Resolve #392, compatible with strict relations name space inspection

This commit is contained in:
xuri 2019-04-27 23:40:57 +08:00
parent 29b2854e53
commit 01a418bda8
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
1 changed files with 11 additions and 2 deletions

View File

@ -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