diff options
Diffstat (limited to 'sheet.go')
-rw-r--r-- | sheet.go | 81 |
1 files changed, 6 insertions, 75 deletions
@@ -2,12 +2,12 @@ // this source code is governed by a BSD-style license that can be found in // the LICENSE file. // -// Package excelize providing a set of functions that allow you to write to -// and read from XLSX / XLSM / XLTM files. Supports reading and writing -// spreadsheet documents generated by Microsoft Excelâ„¢ 2007 and later. Supports -// complex components by high compatibility, and provided streaming API for -// generating or reading data from a worksheet with huge amounts of data. This -// library needs Go version 1.15 or later. +// Package excelize providing a set of functions that allow you to write to and +// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and +// writing spreadsheet documents generated by Microsoft Excelâ„¢ 2007 and later. +// Supports complex components by high compatibility, and provided streaming +// API for generating or reading data from a worksheet with huge amounts of +// data. This library needs Go version 1.15 or later. package excelize @@ -93,35 +93,6 @@ func (f *File) contentTypesWriter() { } } -// getWorkbookPath provides a function to get the path of the workbook.xml in -// the spreadsheet. -func (f *File) getWorkbookPath() (path string) { - if rels := f.relsReader("_rels/.rels"); rels != nil { - rels.Lock() - defer rels.Unlock() - for _, rel := range rels.Relationships { - if rel.Type == SourceRelationshipOfficeDocument { - path = strings.TrimPrefix(rel.Target, "/") - return - } - } - } - return -} - -// getWorkbookRelsPath provides a function to get the path of the workbook.xml.rels -// in the spreadsheet. -func (f *File) getWorkbookRelsPath() (path string) { - wbPath := f.getWorkbookPath() - wbDir := filepath.Dir(wbPath) - if wbDir == "." { - path = "_rels/" + filepath.Base(wbPath) + ".rels" - return - } - path = strings.TrimPrefix(filepath.Dir(wbPath)+"/_rels/"+filepath.Base(wbPath)+".rels", "/") - return -} - // getWorksheetPath construct a target XML as xl/worksheets/sheet%d by split // path, compatible with different types of relative paths in // workbook.xml.rels, for example: worksheets/sheet%d.xml @@ -135,35 +106,6 @@ func (f *File) getWorksheetPath(relTarget string) (path string) { return path } -// workbookReader provides a function to get the pointer to the workbook.xml -// structure after deserialization. -func (f *File) workbookReader() *xlsxWorkbook { - var err error - if f.WorkBook == nil { - wbPath := f.getWorkbookPath() - f.WorkBook = new(xlsxWorkbook) - if _, ok := f.xmlAttr[wbPath]; !ok { - d := f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readXML(wbPath)))) - f.xmlAttr[wbPath] = append(f.xmlAttr[wbPath], getRootElement(d)...) - f.addNameSpaces(wbPath, SourceRelationship) - } - if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readXML(wbPath)))). - Decode(f.WorkBook); err != nil && err != io.EOF { - log.Printf("xml decode error: %s", err) - } - } - return f.WorkBook -} - -// workBookWriter provides a function to save workbook.xml after serialize -// structure. -func (f *File) workBookWriter() { - if f.WorkBook != nil { - output, _ := xml.Marshal(f.WorkBook) - f.saveFileList(f.getWorkbookPath(), replaceRelationshipsBytes(f.replaceNameSpaceBytes(f.getWorkbookPath(), output))) - } -} - // mergeExpandedCols merge expanded columns. func (f *File) mergeExpandedCols(ws *xlsxWorksheet) { sort.Slice(ws.Cols.Col, func(i, j int) bool { @@ -276,17 +218,6 @@ func (f *File) setSheet(index int, name string) { f.xmlAttr[path] = []xml.Attr{NameSpaceSpreadSheet} } -// setWorkbook update workbook property of the spreadsheet. Maximum 31 -// characters are allowed in sheet title. -func (f *File) setWorkbook(name string, sheetID, rid int) { - content := f.workbookReader() - content.Sheets.Sheet = append(content.Sheets.Sheet, xlsxSheet{ - Name: trimSheetName(name), - SheetID: sheetID, - ID: "rId" + strconv.Itoa(rid), - }) -} - // relsWriter provides a function to save relationships after // serialize structure. func (f *File) relsWriter() { |