excelize
excelize copied to clipboard
concurrent use GetCellStyle got panic:index out of range
Description hi,I want to parse an xlsx file with 3000 rows and 50 columns. If the parsing time for each cell is too long, I will concurrently retrieve the properties of each cell by column, such as value content, style, cell type, etc. Then I found that the GetCellStyle method will report the following error in concurrent situations.
goroutine 29 [running]:
github.com/xuri/excelize/v2.(*File).GetCellStyle(0x5a39a0?, {0x50c341?, 0xc00009df90?}, {0xc0003fe436, 0x2})
D:/Users/xxxx/go/pkg/mod/github.com/xuri/excelize/[email protected]/styles.go:2202 +0x295
here is my demo code and demo file
func TestGetStyle(t *testing.T) {file, err := excelize.OpenFile("1.xlsx")
if err != nil {
panic(err)
}
var wg sync.WaitGroup
rows,column:=200,24
for i := 0; i < column; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
for row := 0; row < rows; row++ {
axis := AxisEncode(i, row)
style, err := file.GetCellStyle("Sheet1", axis)
if err != nil {
panic(err)
}
fmt.Println(style)
}
}(i)
}
wg.Wait()
}
func AxisEncode(colIndex, rowIndex int) string {
if rowIndex > excelize.TotalRows {
rowIndex = excelize.TotalRows - 1
}
if colIndex > excelize.MaxColumns {
rowIndex = excelize.MaxColumns - 1
}
cellName, err := excelize.CoordinatesToCellName(colIndex+1, rowIndex+1)
if err == nil {
return cellName
}
return ""
}