forked from p30928647/excelize
- 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)
This commit is contained in:
parent
30d0a2f40a
commit
c5cc500b88
13
sheet.go
13
sheet.go
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue