diff options
author | Ri Xu <xuri.me@gmail.com> | 2016-12-26 18:06:12 +0800 |
---|---|---|
committer | Ri Xu <xuri.me@gmail.com> | 2016-12-26 18:06:12 +0800 |
commit | c5cc500b886366a99641eaa7bc24613f6066fd79 (patch) | |
tree | 3242a5af60d607a6cd8e915b546381aa14f096bb | |
parent | 30d0a2f40afadf7fef9e008bf2fa557b07560c54 (diff) |
- Fix issue: pivot cache and extending spreadsheetML missing;
- Compatibility improved: relationship namespace in `workbook.xml` has been changed (`xmlns:mc`, `xmlns:x15` and `mc:Ignorable` added)
-rw-r--r-- | sheet.go | 13 | ||||
-rw-r--r-- | xmlWorkbook.go | 42 | ||||
-rw-r--r-- | xmlWorksheet.go | 1 |
3 files changed, 53 insertions, 3 deletions
@@ -70,7 +70,7 @@ func (f *File) setWorkbook(name string, rid int) { if err != nil { fmt.Println(err) } - f.saveFileList(`xl/workbook.xml`, replaceRelationshipsNameSpace(string(output))) + f.saveFileList(`xl/workbook.xml`, workBookCompatibility(replaceRelationshipsNameSpace(string(output)))) } // Read and unmarshal workbook relationships of XLSX. @@ -118,7 +118,7 @@ func (f *File) setAppXML() { // horrible hack to fix that after the XML marshalling is completed. func replaceRelationshipsNameSpace(workbookMarshal string) string { oldXmlns := `<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">` - newXmlns := `<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">` + newXmlns := `<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x15" xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main">` return strings.Replace(workbookMarshal, oldXmlns, newXmlns, -1) } @@ -200,5 +200,14 @@ func workBookCompatibility(workbookMarshal string) string { workbookMarshal = strings.Replace(workbookMarshal, `></tabColor>`, ` />`, -1) workbookMarshal = strings.Replace(workbookMarshal, `></pageSetUpPr>`, ` />`, -1) workbookMarshal = strings.Replace(workbookMarshal, `></pane>`, ` />`, -1) + workbookMarshal = strings.Replace(workbookMarshal, `<extLst></extLst>`, ``, -1) + workbookMarshal = strings.Replace(workbookMarshal, `<fileRecoveryPr />`, ``, -1) + workbookMarshal = strings.Replace(workbookMarshal, `<workbookProtection />`, ``, -1) + workbookMarshal = strings.Replace(workbookMarshal, `<pivotCaches></pivotCaches>`, ``, -1) + workbookMarshal = strings.Replace(workbookMarshal, `<externalReferences></externalReferences>`, ``, -1) + workbookMarshal = strings.Replace(workbookMarshal, `<workbookProtection></workbookProtection>`, ``, -1) + workbookMarshal = strings.Replace(workbookMarshal, `<definedNames></definedNames>`, ``, -1) + workbookMarshal = strings.Replace(workbookMarshal, `<fileRecoveryPr></fileRecoveryPr>`, ``, -1) + workbookMarshal = strings.Replace(workbookMarshal, `<workbookPr />`, ``, -1) return workbookMarshal } diff --git a/xmlWorkbook.go b/xmlWorkbook.go index b5c6879..c196900 100644 --- a/xmlWorkbook.go +++ b/xmlWorkbook.go @@ -37,14 +37,17 @@ type xlsxWorkbook struct { WorkbookProtection xlsxWorkbookProtection `xml:"workbookProtection"` BookViews xlsxBookViews `xml:"bookViews"` Sheets xlsxSheets `xml:"sheets"` + ExternalReferences xlsxExternalReferences `xml:"externalReferences"` DefinedNames xlsxDefinedNames `xml:"definedNames"` CalcPr xlsxCalcPr `xml:"calcPr"` + PivotCaches xlsxPivotCaches `xml:"pivotCaches"` + ExtLst xlsxExtLst `xml:"extLst"` FileRecoveryPr xlsxFileRecoveryPr `xml:"fileRecoveryPr"` } // xlsxFileRecoveryPr maps sheet recovery information. type xlsxFileRecoveryPr struct { - RepairLoad int `xml:"repairLoad,attr"` + RepairLoad int `xml:"repairLoad,attr,omitempty"` } // xlsxWorkbookProtection directly maps the workbookProtection element from the @@ -122,6 +125,43 @@ type xlsxSheet struct { State string `xml:"state,attr,omitempty"` } +// xlsxExternalReferences directly maps the externalReferences element +// of the external workbook references part. +type xlsxExternalReferences struct { + ExternalReference []xlsxExternalReference `xml:"externalReference"` +} + +// xlsxExternalReference directly maps the externalReference element +// of the external workbook references part. +type xlsxExternalReference struct { + RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` +} + +// xlsxPivotCaches element enumerates pivot cache definition parts +// used by pivot tables and formulas in this workbook. +type xlsxPivotCaches struct { + PivotCache []xlsxPivotCache `xml:"pivotCache"` +} + +// xlsxPivotCache directly maps the pivotCache element. +type xlsxPivotCache struct { + CacheID int `xml:"cacheId,attr,omitempty"` + RID string `xml:"http://schemas.openxmlformats.org/officeDocument/2006/relationships id,attr,omitempty"` +} + +// extLst element provides a convention for extending spreadsheetML in +// predefined locations. The locations shall be denoted with the extLst +// element, and are called extension lists. Extension list locations +// within the markup document are specified in the markup specification +// and can be used to store extensions to the markup specification, +// whether those are future version extensions of the markup specification +// or are private extensions implemented independently from the markup +// specification. Markup within an extension might not be understood by a +// consumer. +type xlsxExtLst struct { + Ext string `xml:",innerxml"` +} + // xlsxDefinedNames directly maps the definedNames element from the // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main // - currently I have not checked it for completeness - it does as diff --git a/xmlWorksheet.go b/xmlWorksheet.go index be7dcc2..4752a15 100644 --- a/xmlWorksheet.go +++ b/xmlWorksheet.go @@ -26,6 +26,7 @@ type xlsxWorksheet struct { LegacyDrawing xlsxLegacyDrawing `xml:"legacyDrawing"` Picture xlsxPicture `xml:"picture"` TableParts xlsxTableParts `xml:"tableParts"` + ExtLst xlsxExtLst `xml:"extLst"` } // xlsxDrawing change r:id to rid in the namespace. |