Skip to content

Commit

Permalink
Resolve #392, compatible with strict relations name space inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
xuri committed Apr 27, 2019
1 parent 29b2854 commit 01a418b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 01a418b

Please sign in to comment.