From 38ad20efc11c1872c4e62a12617f0300c138b867 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 7 May 2018 16:12:51 +0800 Subject: save bytes on memory instead of string --- sheet.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'sheet.go') diff --git a/sheet.go b/sheet.go index f42226b..cb50d61 100644 --- a/sheet.go +++ b/sheet.go @@ -50,7 +50,7 @@ func (f *File) contentTypesReader() *xlsxTypes { func (f *File) contentTypesWriter() { if f.ContentTypes != nil { output, _ := xml.Marshal(f.ContentTypes) - f.saveFileList("[Content_Types].xml", string(output)) + f.saveFileList("[Content_Types].xml", output) } } @@ -70,7 +70,7 @@ func (f *File) workbookReader() *xlsxWorkbook { func (f *File) workbookWriter() { if f.WorkBook != nil { output, _ := xml.Marshal(f.WorkBook) - f.saveFileList("xl/workbook.xml", replaceRelationshipsNameSpace(string(output))) + f.saveFileList("xl/workbook.xml", replaceRelationshipsNameSpaceBytes(output)) } } @@ -83,7 +83,7 @@ func (f *File) worksheetWriter() { f.Sheet[path].SheetData.Row[k].C = trimCell(v.C) } output, _ := xml.Marshal(sheet) - f.saveFileList(path, replaceWorkSheetsRelationshipsNameSpace(string(output))) + f.saveFileList(path, replaceWorkSheetsRelationshipsNameSpaceBytes(output)) ok := f.checked[path] if ok { f.checked[path] = false @@ -151,7 +151,7 @@ func (f *File) workbookRelsReader() *xlsxWorkbookRels { func (f *File) workbookRelsWriter() { if f.WorkBookRels != nil { output, _ := xml.Marshal(f.WorkBookRels) - f.saveFileList("xl/_rels/workbook.xml.rels", string(output)) + f.saveFileList("xl/_rels/workbook.xml.rels", output) } } @@ -183,7 +183,7 @@ func (f *File) addXlsxWorkbookRels(sheet int) int { // setAppXML update docProps/app.xml file of XML. func (f *File) setAppXML() { - f.saveFileList("docProps/app.xml", templateDocpropsApp) + f.saveFileList("docProps/app.xml", []byte(templateDocpropsApp)) } // Some tools that read XLSX files have very strict requirements about the @@ -199,6 +199,12 @@ func replaceRelationshipsNameSpace(workbookMarshal string) string { return strings.Replace(workbookMarshal, oldXmlns, newXmlns, -1) } +func replaceRelationshipsNameSpaceBytes(workbookMarshal []byte) []byte { + oldXmlns := []byte(``) + newXmlns := []byte(``) + return bytes.Replace(workbookMarshal, oldXmlns, newXmlns, -1) +} + // SetActiveSheet provides function to set default active worksheet of XLSX by // given index. Note that active index is different with the index that got by // function GetSheetMap, and it should be greater than 0 and less than total -- cgit v1.2.1