summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2019-04-27 23:40:57 +0800
committerxuri <xuri.me@gmail.com>2019-04-27 23:40:57 +0800
commit01a418bda8502890e89ab20a2b41220372877bae (patch)
tree7975eca61fc0181da285334a63a2eaea5a2d703e
parent29b2854e53560beb3c238786929097421fa9a942 (diff)
Resolve #392, compatible with strict relations name space inspection
-rw-r--r--sheet.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/sheet.go b/sheet.go
index 32d12d1..5e9fcae 100644
--- a/sheet.go
+++ b/sheet.go
@@ -92,7 +92,7 @@ func (f *File) workbookReader() *xlsxWorkbook {
func (f *File) workBookWriter() {
if f.WorkBook != nil {
output, _ := xml.Marshal(f.WorkBook)
- f.saveFileList("xl/workbook.xml", replaceRelationshipsNameSpaceBytes(output))
+ f.saveFileList("xl/workbook.xml", replaceRelationshipsBytes(replaceRelationshipsNameSpaceBytes(output)))
}
}
@@ -105,7 +105,7 @@ func (f *File) workSheetWriter() {
f.Sheet[p].SheetData.Row[k].C = trimCell(v.C)
}
output, _ := xml.Marshal(sheet)
- f.saveFileList(p, replaceWorkSheetsRelationshipsNameSpaceBytes(output))
+ f.saveFileList(p, replaceRelationshipsBytes(replaceWorkSheetsRelationshipsNameSpaceBytes(output)))
ok := f.checked[p]
if ok {
f.checked[p] = false
@@ -211,6 +211,15 @@ func (f *File) setAppXML() {
f.saveFileList("docProps/app.xml", []byte(templateDocpropsApp))
}
+// replaceRelationshipsBytes; Some tools that read XLSX files have very strict
+// requirements about the structure of the input XML. This function is a
+// horrible hack to fix that after the XML marshalling is completed.
+func replaceRelationshipsBytes(content []byte) []byte {
+ oldXmlns := []byte(`xmlns:relationships="http://schemas.openxmlformats.org/officeDocument/2006/relationships" relationships`)
+ newXmlns := []byte("r")
+ return bytes.Replace(content, oldXmlns, newXmlns, -1)
+}
+
// replaceRelationshipsNameSpaceBytes; Some tools that read XLSX files have
// very strict requirements about the structure of the input XML. In
// particular both Numbers on the Mac and SAS dislike inline XML namespace