summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2022-06-21 20:08:47 +0800
committerxuri <xuri.me@gmail.com>2022-06-21 20:08:47 +0800
commit852f211970b47c79cceedd9de934f9aa7520f131 (patch)
tree8a2ac5103cc32dfb3d78b2dbcbb6aa4f913e162f
parent7819cd7fec50513786a5d47c6f11a59cceba541a (diff)
This closes #1257, fix incorrect worksheet header footer fields order
-rw-r--r--excelize.go8
-rw-r--r--sheet.go2
-rw-r--r--xmlContentTypes.go2
-rw-r--r--xmlWorksheet.go31
4 files changed, 22 insertions, 21 deletions
diff --git a/excelize.go b/excelize.go
index aaa4953..580bc29 100644
--- a/excelize.go
+++ b/excelize.go
@@ -234,9 +234,11 @@ func (f *File) workSheetReader(sheet string) (ws *xlsxWorksheet, err error) {
ws = worksheet.(*xlsxWorksheet)
return
}
- if strings.HasPrefix(name, "xl/chartsheets") || strings.HasPrefix(name, "xl/macrosheet") {
- err = fmt.Errorf("sheet %s is not a worksheet", sheet)
- return
+ for _, sheetType := range []string{"xl/chartsheets", "xl/dialogsheet", "xl/macrosheet"} {
+ if strings.HasPrefix(name, sheetType) {
+ err = fmt.Errorf("sheet %s is not a worksheet", sheet)
+ return
+ }
}
ws = new(xlsxWorksheet)
if _, ok := f.xmlAttr[name]; !ok {
diff --git a/sheet.go b/sheet.go
index 7b6e5dc..45b724f 100644
--- a/sheet.go
+++ b/sheet.go
@@ -280,7 +280,7 @@ func (f *File) SetActiveSheet(index int) {
for idx, name := range f.GetSheetList() {
ws, err := f.workSheetReader(name)
if err != nil {
- // Chartsheet or dialogsheet
+ // Chartsheet, macrosheet or dialogsheet
return
}
if ws.SheetViews == nil {
diff --git a/xmlContentTypes.go b/xmlContentTypes.go
index 4b3cd64..52dd744 100644
--- a/xmlContentTypes.go
+++ b/xmlContentTypes.go
@@ -22,8 +22,8 @@ import (
type xlsxTypes struct {
sync.Mutex
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/package/2006/content-types Types"`
- Overrides []xlsxOverride `xml:"Override"`
Defaults []xlsxDefault `xml:"Default"`
+ Overrides []xlsxOverride `xml:"Override"`
}
// xlsxOverride directly maps the override element in the namespace
diff --git a/xmlWorksheet.go b/xmlWorksheet.go
index eb855c5..0c0fe92 100644
--- a/xmlWorksheet.go
+++ b/xmlWorksheet.go
@@ -78,18 +78,17 @@ type xlsxDrawing struct {
// footers on the first page can differ from those on odd- and even-numbered
// pages. In the latter case, the first page is not considered an odd page.
type xlsxHeaderFooter struct {
- XMLName xml.Name `xml:"headerFooter"`
- AlignWithMargins bool `xml:"alignWithMargins,attr,omitempty"`
- DifferentFirst bool `xml:"differentFirst,attr,omitempty"`
- DifferentOddEven bool `xml:"differentOddEven,attr,omitempty"`
- ScaleWithDoc bool `xml:"scaleWithDoc,attr,omitempty"`
- OddHeader string `xml:"oddHeader,omitempty"`
- OddFooter string `xml:"oddFooter,omitempty"`
- EvenHeader string `xml:"evenHeader,omitempty"`
- EvenFooter string `xml:"evenFooter,omitempty"`
- FirstFooter string `xml:"firstFooter,omitempty"`
- FirstHeader string `xml:"firstHeader,omitempty"`
- DrawingHF *xlsxDrawingHF `xml:"drawingHF"`
+ XMLName xml.Name `xml:"headerFooter"`
+ DifferentOddEven bool `xml:"differentOddEven,attr,omitempty"`
+ DifferentFirst bool `xml:"differentFirst,attr,omitempty"`
+ ScaleWithDoc bool `xml:"scaleWithDoc,attr,omitempty"`
+ AlignWithMargins bool `xml:"alignWithMargins,attr,omitempty"`
+ OddHeader string `xml:"oddHeader,omitempty"`
+ OddFooter string `xml:"oddFooter,omitempty"`
+ EvenHeader string `xml:"evenHeader,omitempty"`
+ EvenFooter string `xml:"evenFooter,omitempty"`
+ FirstHeader string `xml:"firstHeader,omitempty"`
+ FirstFooter string `xml:"firstFooter,omitempty"`
}
// xlsxDrawingHF (Drawing Reference in Header Footer) specifies the usage of
@@ -147,12 +146,12 @@ type xlsxPrintOptions struct {
// a sheet or a custom sheet view.
type xlsxPageMargins struct {
XMLName xml.Name `xml:"pageMargins"`
- Bottom float64 `xml:"bottom,attr"`
- Footer float64 `xml:"footer,attr"`
- Header float64 `xml:"header,attr"`
Left float64 `xml:"left,attr"`
Right float64 `xml:"right,attr"`
Top float64 `xml:"top,attr"`
+ Bottom float64 `xml:"bottom,attr"`
+ Header float64 `xml:"header,attr"`
+ Footer float64 `xml:"footer,attr"`
}
// xlsxSheetFormatPr directly maps the sheetFormatPr element in the namespace
@@ -880,8 +879,8 @@ type FormatHeaderFooter struct {
OddFooter string
EvenHeader string
EvenFooter string
- FirstFooter string
FirstHeader string
+ FirstFooter string
}
// FormatPageMargins directly maps the settings of page margins