Skip to content

Commit 01a418b

Browse files
committed
Resolve #392, compatible with strict relations name space inspection
1 parent 29b2854 commit 01a418b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

sheet.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (f *File) workbookReader() *xlsxWorkbook {
9292
func (f *File) workBookWriter() {
9393
if f.WorkBook != nil {
9494
output, _ := xml.Marshal(f.WorkBook)
95-
f.saveFileList("xl/workbook.xml", replaceRelationshipsNameSpaceBytes(output))
95+
f.saveFileList("xl/workbook.xml", replaceRelationshipsBytes(replaceRelationshipsNameSpaceBytes(output)))
9696
}
9797
}
9898

@@ -105,7 +105,7 @@ func (f *File) workSheetWriter() {
105105
f.Sheet[p].SheetData.Row[k].C = trimCell(v.C)
106106
}
107107
output, _ := xml.Marshal(sheet)
108-
f.saveFileList(p, replaceWorkSheetsRelationshipsNameSpaceBytes(output))
108+
f.saveFileList(p, replaceRelationshipsBytes(replaceWorkSheetsRelationshipsNameSpaceBytes(output)))
109109
ok := f.checked[p]
110110
if ok {
111111
f.checked[p] = false
@@ -211,6 +211,15 @@ func (f *File) setAppXML() {
211211
f.saveFileList("docProps/app.xml", []byte(templateDocpropsApp))
212212
}
213213

214+
// replaceRelationshipsBytes; Some tools that read XLSX files have very strict
215+
// requirements about the structure of the input XML. This function is a
216+
// horrible hack to fix that after the XML marshalling is completed.
217+
func replaceRelationshipsBytes(content []byte) []byte {
218+
oldXmlns := []byte(`xmlns:relationships="http://schemas.openxmlformats.org/officeDocument/2006/relationships" relationships`)
219+
newXmlns := []byte("r")
220+
return bytes.Replace(content, oldXmlns, newXmlns, -1)
221+
}
222+
214223
// replaceRelationshipsNameSpaceBytes; Some tools that read XLSX files have
215224
// very strict requirements about the structure of the input XML. In
216225
// particular both Numbers on the Mac and SAS dislike inline XML namespace

0 commit comments

Comments
 (0)