-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Description
Executing calculations with formulas containing nested VLOOKUPs is very slow, and the more rows in the table, the slower the speed.
Steps to reproduce the issue
package test
import (
"github.com/xuri/excelize/v2"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestVlookup(t *testing.T) {
Convey("test VLOOKUP", t, func() {
file := excelize.NewFile()
// sheet1
sheet1Name := "Sheet1"
var err error
err = file.SetCellStr(sheet1Name, "A1", "a")
So(err, ShouldBeNil)
err = file.SetCellFormula(sheet1Name, "A2", `VLOOKUP($A1,'Sheet2'!$A:$D,2,FALSE)`)
So(err, ShouldBeNil)
// sheet2
sheet2Name := "Sheet2"
_, err = file.NewSheet(sheet2Name)
So(err, ShouldBeNil)
var cellsValue = map[string]string{
"A1": "a",
"A2": "b",
"A3": "c",
"A4": "d",
"A5": "e",
"A6": "f",
"A7": "g",
"B1": "hero_level_name_1",
"B2": "hero_level_name_2",
"B3": "hero_level_name_3",
"B4": "hero_level_name_4",
"B5": "hero_level_name_5",
"B6": "hero_level_name_6",
"B7": "hero_level_name_7",
"E1": "w",
"E2": "w",
"E3": "w",
"E4": "w",
"E5": "w",
"E6": "w",
"E7": "w",
"I1": "w",
"I2": "g",
"I3": "b",
"I4": "p",
"I5": "o",
"J1": "#FFFFFF",
"J2": "#FFFFFF",
"J3": "#FFFFFF",
"J4": "#FFFFFF",
"J5": "#FFFFFF",
}
for k, v := range cellsValue {
err = file.SetCellStr(sheet2Name, k, v)
So(err, ShouldBeNil)
}
var cellsFormula = map[string]string{
"D1": `VLOOKUP($E1,$I:$J,2,FALSE)`,
"D2": `VLOOKUP($E2,$I:$J,2,FALSE)`,
"D3": `VLOOKUP($E3,$I:$J,2,FALSE)`,
"D4": `VLOOKUP($E4,$I:$J,2,FALSE)`,
"D5": `VLOOKUP($E5,$I:$J,2,FALSE)`,
"D6": `VLOOKUP($E6,$I:$J,2,FALSE)`,
"D7": `VLOOKUP($E7,$I:$J,2,FALSE)`,
}
for k, v := range cellsFormula {
err = file.SetCellFormula(sheet2Name, k, v)
So(err, ShouldBeNil)
}
// CalcCellValue VLOOKUP
result, err := file.CalcCellValue(sheet1Name, "A2")
So(err, ShouldBeNil)
So(result, ShouldEqual, "hero_level_name_1")
})
}
### Describe the results you received
cost time > 1s
### Describe the results you expected
When there is a lot of data, calculating a single cell can take up to 20 seconds.
### Go version
go1.24.2
### Excelize version or commit ID
2.9.1
### Environment
```shell
Apple M3 Pro
macos 14.3
Validations
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request