From ee2ef152d939c6a5bdd703167a58ba22a866f06b Mon Sep 17 00:00:00 2001 From: Vivek Kairi Date: Thu, 15 Feb 2024 11:00:07 +0530 Subject: [PATCH] This closes #1815, cell value reading functions inherit the Options settings of the OpenReader (#1816) Co-authored-by: Vivek Kairi --- calc.go | 5 +++-- cell.go | 2 +- col.go | 2 +- excelize.go | 6 +++--- file.go | 2 +- rows.go | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/calc.go b/calc.go index 59c8885..f03c573 100644 --- a/calc.go +++ b/calc.go @@ -805,14 +805,15 @@ type formulaFuncs struct { // Z.TEST // ZTEST func (f *File) CalcCellValue(sheet, cell string, opts ...Options) (result string, err error) { + options := f.getOptions(opts...) var ( - rawCellValue = getOptions(opts...).RawCellValue + rawCellValue = options.RawCellValue styleIdx int token formulaArg ) if token, err = f.calcCellValue(&calcContext{ entry: fmt.Sprintf("%s!%s", sheet, cell), - maxCalcIterations: getOptions(opts...).MaxCalcIterations, + maxCalcIterations: options.MaxCalcIterations, iterations: make(map[string]uint), iterationsCache: make(map[string]formulaArg), }, sheet, cell); err != nil { diff --git a/cell.go b/cell.go index 721ba7b..5d547e8 100644 --- a/cell.go +++ b/cell.go @@ -72,7 +72,7 @@ func (f *File) GetCellValue(sheet, cell string, opts ...Options) (string, error) if err != nil { return "", true, err } - val, err := c.getValueFrom(f, sst, getOptions(opts...).RawCellValue) + val, err := c.getValueFrom(f, sst, f.getOptions(opts...).RawCellValue) return val, true, err }) } diff --git a/col.go b/col.go index b51a283..c51fdad 100644 --- a/col.go +++ b/col.go @@ -92,7 +92,7 @@ func (cols *Cols) Rows(opts ...Options) ([]string, error) { if cols.stashCol >= cols.curCol { return rowIterator.cells, rowIterator.err } - cols.rawCellValue = getOptions(opts...).RawCellValue + cols.rawCellValue = cols.f.getOptions(opts...).RawCellValue if cols.sst, rowIterator.err = cols.f.sharedStringsReader(); rowIterator.err != nil { return rowIterator.cells, rowIterator.err } diff --git a/excelize.go b/excelize.go index b869572..152e212 100644 --- a/excelize.go +++ b/excelize.go @@ -180,7 +180,7 @@ func OpenReader(r io.Reader, opts ...Options) (*File, error) { return nil, err } f := newFile() - f.options = getOptions(opts...) + f.options = f.getOptions(opts...) if err = f.checkOpenReaderOptions(); err != nil { return nil, err } @@ -219,8 +219,8 @@ func OpenReader(r io.Reader, opts ...Options) (*File, error) { // getOptions provides a function to parse the optional settings for open // and reading spreadsheet. -func getOptions(opts ...Options) *Options { - options := &Options{} +func (f *File) getOptions(opts ...Options) *Options { + options := f.options for _, opt := range opts { options = &opt } diff --git a/file.go b/file.go index 894dd0a..067f999 100644 --- a/file.go +++ b/file.go @@ -50,7 +50,7 @@ func NewFile(opts ...Options) *File { ws, _ := f.workSheetReader("Sheet1") f.Sheet.Store("xl/worksheets/sheet1.xml", ws) f.Theme, _ = f.themeReader() - f.options = getOptions(opts...) + f.options = f.getOptions(opts...) return f } diff --git a/rows.go b/rows.go index b87d45d..7541a0b 100644 --- a/rows.go +++ b/rows.go @@ -151,7 +151,7 @@ func (rows *Rows) Columns(opts ...Options) ([]string, error) { } var rowIterator rowXMLIterator var token xml.Token - rows.rawCellValue = getOptions(opts...).RawCellValue + rows.rawCellValue = rows.f.getOptions(opts...).RawCellValue if rows.sst, rowIterator.err = rows.f.sharedStringsReader(); rowIterator.err != nil { return rowIterator.cells, rowIterator.err } -- GitLab