소스 검색

Resolve #392, compatible with strict relations name space inspection

xuri 6 년 전
부모
커밋
01a418bda8
1개의 변경된 파일11개의 추가작업 그리고 2개의 파일을 삭제
  1. 11 2
      sheet.go

+ 11 - 2
sheet.go

@@ -92,7 +92,7 @@ func (f *File) workbookReader() *xlsxWorkbook {
 func (f *File) workBookWriter() {
 func (f *File) workBookWriter() {
 	if f.WorkBook != nil {
 	if f.WorkBook != nil {
 		output, _ := xml.Marshal(f.WorkBook)
 		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)
 				f.Sheet[p].SheetData.Row[k].C = trimCell(v.C)
 			}
 			}
 			output, _ := xml.Marshal(sheet)
 			output, _ := xml.Marshal(sheet)
-			f.saveFileList(p, replaceWorkSheetsRelationshipsNameSpaceBytes(output))
+			f.saveFileList(p, replaceRelationshipsBytes(replaceWorkSheetsRelationshipsNameSpaceBytes(output)))
 			ok := f.checked[p]
 			ok := f.checked[p]
 			if ok {
 			if ok {
 				f.checked[p] = false
 				f.checked[p] = false
@@ -211,6 +211,15 @@ func (f *File) setAppXML() {
 	f.saveFileList("docProps/app.xml", []byte(templateDocpropsApp))
 	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
 // replaceRelationshipsNameSpaceBytes; Some tools that read XLSX files have
 // very strict requirements about the structure of the input XML. In
 // very strict requirements about the structure of the input XML. In
 // particular both Numbers on the Mac and SAS dislike inline XML namespace
 // particular both Numbers on the Mac and SAS dislike inline XML namespace