Skip to content

Commit

Permalink
This fixes #1645 and fixes #1655
Browse files Browse the repository at this point in the history
- Breaking changes, change the data type for the `HeaderFooterOptions` structure fields `AlignWithMargins` and `ScaleWithDoc` as a pointer
- Fixed panic on `AutoFilter` by adding nil pointer guard for local sheet ID
- Allow dot character in the defined name, table name, or pivot table name
- Update the unit tests
  • Loading branch information
xuri committed Sep 9, 2023
1 parent a0a7d5c commit 49706c9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sheet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func TestSetHeaderFooter(t *testing.T) {
func TestDefinedName(t *testing.T) {
f := NewFile()
assert.NoError(t, f.SetDefinedName(&DefinedName{
Name: "Amount",
Name: "Amount.",
RefersTo: "Sheet1!$A$2:$D$5",
Comment: "defined name comment",
Scope: "Sheet1",
Expand Down
7 changes: 5 additions & 2 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,11 @@ func (f *File) AutoFilter(sheet, rangeRef string, opts []AutoFilterOptions) erro
} else {
var definedNameExists bool
for idx := range wb.DefinedNames.DefinedName {
definedName := wb.DefinedNames.DefinedName[idx]
if definedName.Name == builtInDefinedNames[2] && *definedName.LocalSheetID == sheetID && definedName.Hidden {
definedName, localSheetID := wb.DefinedNames.DefinedName[idx], 0
if definedName.LocalSheetID != nil {
localSheetID = *definedName.LocalSheetID
}
if definedName.Name == builtInDefinedNames[2] && localSheetID == sheetID && definedName.Hidden {
wb.DefinedNames.DefinedName[idx].Data = filterRange
definedNameExists = true
}
Expand Down
4 changes: 4 additions & 0 deletions table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ func TestAutoFilter(t *testing.T) {
f.WorkBook = nil
f.Pkg.Store(defaultXMLPathWorkbook, MacintoshCyrillicCharset)
assert.EqualError(t, f.AutoFilter("Sheet1", "D4:B1", nil), "XML syntax error on line 1: invalid UTF-8")
// Test add auto filter with empty local sheet ID
f = NewFile()
f.WorkBook = &xlsxWorkbook{DefinedNames: &xlsxDefinedNames{DefinedName: []xlsxDefinedName{{Name: builtInDefinedNames[2], Hidden: true}}}}
assert.NoError(t, f.AutoFilter("Sheet1", "A1:B1", nil))
}

func TestAutoFilterError(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions xmlWorksheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ type xlsxHeaderFooter struct {
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"`
ScaleWithDoc *bool `xml:"scaleWithDoc,attr"`
AlignWithMargins *bool `xml:"alignWithMargins,attr"`
OddHeader string `xml:"oddHeader,omitempty"`
OddFooter string `xml:"oddFooter,omitempty"`
EvenHeader string `xml:"evenHeader,omitempty"`
Expand Down Expand Up @@ -963,10 +963,10 @@ type SheetProtectionOptions struct {

// HeaderFooterOptions directly maps the settings of header and footer.
type HeaderFooterOptions struct {
AlignWithMargins bool
AlignWithMargins *bool
DifferentFirst bool
DifferentOddEven bool
ScaleWithDoc bool
ScaleWithDoc *bool
OddHeader string
OddFooter string
EvenHeader string
Expand Down

0 comments on commit 49706c9

Please sign in to comment.