Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add OpenReader options to GetRows #1816

Merged
merged 6 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,13 +806,13 @@ type formulaFuncs struct {
// ZTEST
func (f *File) CalcCellValue(sheet, cell string, opts ...Options) (result string, err error) {
var (
rawCellValue = getOptions(opts...).RawCellValue
rawCellValue = f.getOptions(opts...).RawCellValue
styleIdx int
token formulaArg
)
if token, err = f.calcCellValue(&calcContext{
entry: fmt.Sprintf("%s!%s", sheet, cell),
maxCalcIterations: getOptions(opts...).MaxCalcIterations,
maxCalcIterations: f.getOptions(opts...).MaxCalcIterations,
iterations: make(map[string]uint),
iterationsCache: make(map[string]formulaArg),
}, sheet, cell); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down
3 changes: 2 additions & 1 deletion col.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (f *File) GetCols(sheet string, opts ...Options) ([][]string, error) {
}
cols, err := f.Cols(sheet)
results := make([][]string, 0, 64)
opts = append([]Options{*f.options}, opts...)
xuri marked this conversation as resolved.
Show resolved Hide resolved
for cols.Next() {
col, _ := cols.Rows(opts...)
results = append(results, col)
Expand All @@ -92,7 +93,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
}
Expand Down
6 changes: 3 additions & 3 deletions excelize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func (f *File) GetRows(sheet string, opts ...Options) ([][]string, error) {
return nil, err
}
rows, _ := f.Rows(sheet)
// Adding the OpenReader function options
opts = append([]Options{*f.options}, opts...)
xuri marked this conversation as resolved.
Show resolved Hide resolved
results, cur, max := make([][]string, 0, 64), 0, 0
for rows.Next() {
cur++
Expand Down Expand Up @@ -151,7 +153,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
}
Expand Down