-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
The SetCellValue method has a bug #1528
Comments
Thanks for your feedback. Could you follow the issue template, and show us a complete, standalone example program or reproducible demo? |
Of course.You can see the sample: github.com/heliangrui/excel; Run the test-main method to execute the test case. You can execute the test case without modifying it. Modify the exportData method in excel/ Excel. go and add the go flag to 179,183 |
I have tested with the repository you mention, and it works well. I don't understand what means you said: "Modify the exportData method in excel/ Excel. go and add the go flag to 179,183". Could you follow the issue template, provide a reproducible demo with simplified codes, and provide what's the results you expected? |
Thanks for your feedback. The statements already exist same with you want to change them. Could you follow the issue template, provide a reproducible demo with simplified codes, and provide what're the results you expected? That will be helpful in quickly understanding and resolving this problem. |
errorMessage: goroutine 81895 [running]: |
Thank you for your issue. I have fixed race condition issues, please upgrade to the master branch code, and this patch will be released in the next version. In addition, you need to wait for all the goroutines launched here to finish in your code diff --git a/excel.go b/excel.go
index f1371b5..15ebb92 100644
--- a/excel.go
+++ b/excel.go
@@ -165,7 +166,6 @@ func (e *Export[T]) setHeadStyle(style *excelize.Style) *Export[T] {
func (e *Export[T]) exportData(object []T, start int) *Export[T] {
obLen := len(object)
- e.wg.Add(1)
e.setRowHeight(start, obLen)
for i := 0; i < obLen; i++ {
mod := object[i]
@@ -175,16 +175,20 @@ func (e *Export[T]) exportData(object []T, start int) *Export[T] {
nowValue := value.FieldByName(fieldName)
name, _ := excelize.ColumnNumberToName(r + 1)
s := name + strconv.Itoa(i+start+e.headRowHeight)
- if m.toExcelFormat == "" {
- go e.f.SetCellValue(e.sheetName, s, nowValue)
- } else {
- toExcelFun := value.MethodByName(m.toExcelFormat)
- call := toExcelFun.Call(nil)
- go e.f.SetCellValue(e.sheetName, s, call[0])
- }
+ e.wg.Add(1)
+ go func() {
+ defer e.wg.Done()
+ if m.toExcelFormat == "" {
+ e.f.SetCellValue(e.sheetName, s, nowValue)
+ } else {
+ toExcelFun := value.MethodByName(m.toExcelFormat)
+ call := toExcelFun.Call(nil)
+ e.f.SetCellValue(e.sheetName, s, call[0])
+ }
+ }()
}
}
- e.wg.Done()
+ e.wg.Wait()
return e
} |
Thanks♪(・ω・)ノ |
- Avoid format text cell value as a numeric - Fix race conditions for concurrency safety functions
- Avoid format text cell value as a numeric - Fix race conditions for concurrency safety functions
The official documentation says that the secondary method is thread-safe, but multithreading starts with an error:
go f.SetCellValue(e.sheetName, s, nowValue)
errors: panic: runtime error: index out of range [4] with length 1
The text was updated successfully, but these errors were encountered: