NewFile provides a function to create new file by default template. For example: f := NewFile()
(opts ...Options)
| 29 | // |
| 30 | // f := NewFile() |
| 31 | func NewFile(opts ...Options) *File { |
| 32 | f := newFile() |
| 33 | f.Pkg.Store(defaultXMLPathRels, []byte(xml.Header+templateRels)) |
| 34 | f.Pkg.Store(defaultXMLPathDocPropsApp, []byte(xml.Header+templateDocpropsApp)) |
| 35 | f.Pkg.Store(defaultXMLPathDocPropsCore, []byte(xml.Header+templateDocpropsCore)) |
| 36 | f.Pkg.Store(defaultXMLPathWorkbookRels, []byte(xml.Header+templateWorkbookRels)) |
| 37 | f.Pkg.Store(defaultXMLPathTheme, []byte(xml.Header+templateTheme)) |
| 38 | f.Pkg.Store(defaultXMLPathSheet, []byte(xml.Header+templateSheet)) |
| 39 | f.Pkg.Store(defaultXMLPathStyles, []byte(xml.Header+templateStyles)) |
| 40 | f.Pkg.Store(defaultXMLPathWorkbook, []byte(xml.Header+templateWorkbook)) |
| 41 | f.Pkg.Store(defaultXMLPathContentTypes, []byte(xml.Header+templateContentTypes)) |
| 42 | f.SheetCount = 1 |
| 43 | f.CalcChain, _ = f.calcChainReader() |
| 44 | f.ContentTypes, _ = f.contentTypesReader() |
| 45 | f.Styles, _ = f.stylesReader() |
| 46 | f.WorkBook, _ = f.workbookReader() |
| 47 | f.Relationships = sync.Map{} |
| 48 | rels, _ := f.relsReader(defaultXMLPathWorkbookRels) |
| 49 | f.Relationships.Store(defaultXMLPathWorkbookRels, rels) |
| 50 | f.sheetMap["Sheet1"] = defaultXMLPathSheet |
| 51 | ws, _ := f.workSheetReader("Sheet1") |
| 52 | f.Sheet.Store(defaultXMLPathSheet, ws) |
| 53 | f.Theme, _ = f.themeReader() |
| 54 | f.options = f.getOptions(opts...) |
| 55 | return f |
| 56 | } |
| 57 | |
| 58 | // Save provides a function to override the spreadsheet with origin path. |
| 59 | func (f *File) Save(opts ...Options) error { |