From a5fce8aa7d155b39742a79ea811315ab0a17913d Mon Sep 17 00:00:00 2001 From: Pismak Ivan Date: Thu, 12 Sep 2024 19:51:59 +0300 Subject: [PATCH 1/2] issue 817 autoFilterBounds could have one element only, in this case use it as second param of AutoFilter --- lib.go | 8 +++++++- sheet.go | 11 +++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib.go b/lib.go index dec567ee..e7dd738c 100644 --- a/lib.go +++ b/lib.go @@ -735,7 +735,13 @@ func readSheetFromFile(rsheet xlsxSheet, fi *File, sheetXMLMap map[string]string sheet.SheetViews = readSheetViews(worksheet.SheetViews) if worksheet.AutoFilter != nil { autoFilterBounds := strings.Split(worksheet.AutoFilter.Ref, ":") - sheet.AutoFilter = &AutoFilter{autoFilterBounds[0], autoFilterBounds[1]} + + bottomRightCell := autoFilterBounds[0] + if len(autoFilterBounds) > 1 { + bottomRightCell = autoFilterBounds[1] + } + + sheet.AutoFilter = &AutoFilter{autoFilterBounds[0], bottomRightCell} } sheet.SheetFormat.DefaultColWidth = worksheet.SheetFormatPr.DefaultColWidth diff --git a/sheet.go b/sheet.go index de0ffe22..1c335eb6 100644 --- a/sheet.go +++ b/sheet.go @@ -30,8 +30,8 @@ type Sheet struct { cellStore CellStore currentRow *Row cellStoreName string // The first part of the key used in - // the cellStore. This name is stable, - // unlike the Name, which can change + // the cellStore. This name is stable, + // unlike the Name, which can change } // NewSheet constructs a Sheet with the default CellStore and returns @@ -47,8 +47,8 @@ func NewSheetWithCellStore(name string, constructor CellStoreConstructor) (*Shee return nil, fmt.Errorf("sheet name is invalid: %w", err) } sheet := &Sheet{ - Name: name, - Cols: &ColStore{}, + Name: name, + Cols: &ColStore{}, cellStoreName: name, } var err error @@ -949,10 +949,9 @@ func handleNumFmtIdForXLSX(NumFmtId int, styles *xlsxStyleSheet) (XfId int) { return } - func IsSaneSheetName(sheetName string) error { runeLength := utf8.RuneCountInString(sheetName) - if runeLength > 31 || runeLength == 0 { + if runeLength > 43 || runeLength == 0 { return fmt.Errorf("sheet name must be 31 or fewer characters long. It is currently '%d' characters long", runeLength) } // Iterate over the runes From 3138af4f6266030ac65423b24047c150dad6cc07 Mon Sep 17 00:00:00 2001 From: Pismak Ivan Date: Mon, 16 Sep 2024 11:04:47 +0300 Subject: [PATCH 2/2] issue 817 autoFilterBounds could have one element only, in this case use it as second param of AutoFilter --- sheet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sheet.go b/sheet.go index 1c335eb6..a9367891 100644 --- a/sheet.go +++ b/sheet.go @@ -951,7 +951,7 @@ func handleNumFmtIdForXLSX(NumFmtId int, styles *xlsxStyleSheet) (XfId int) { func IsSaneSheetName(sheetName string) error { runeLength := utf8.RuneCountInString(sheetName) - if runeLength > 43 || runeLength == 0 { + if runeLength > 31 || runeLength == 0 { return fmt.Errorf("sheet name must be 31 or fewer characters long. It is currently '%d' characters long", runeLength) } // Iterate over the runes