You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently facing an issue with excelize. When using file.SetCellValue(), I input the value "$1231". However, when I download the xlsx file, it shows a warning that the number is in text format, which could lead to calculation errors. I want to input a string like "$1231" because it clearly should not be directly converted to a number based on the requirements, but I would like to convert it to a number in the final step before downloading.
I'm not sure if there is a suitable function or approach to solve this problem.
The text was updated successfully, but these errors were encountered:
Thanks for your issue. As the documentation of the SetCellValue function says, it supports multiple data types. Please set the cell value by Go's numeric data type, then set the currency number formats for the cells. For example:
package main
import (
"fmt""github.com/xuri/excelize/v2"
)
funcmain() {
f:=excelize.NewFile()
deferfunc() {
iferr:=f.Close(); err!=nil {
fmt.Println(err)
}
}()
// Set cell valueiferr:=f.SetCellValue("Sheet1", "A1", 1231); err!=nil {
fmt.Println(err)
return
}
// Create new style with built-in currency formatsstyleID, err:=f.NewStyle(&excelize.Style{
NumFmt: 165,
})
iferr!=nil {
fmt.Println(err)
return
}
// Set number format for the cellsiferr:=f.SetCellStyle("Sheet1", "A1", "A1", styleID); err!=nil {
fmt.Println(err)
return
}
iferr:=f.SaveAs("Book1.xlsx"); err!=nil {
fmt.Println(err)
return
}
}
I'm currently facing an issue with excelize. When using file.SetCellValue(), I input the value "$1231". However, when I download the xlsx file, it shows a warning that the number is in text format, which could lead to calculation errors. I want to input a string like "$1231" because it clearly should not be directly converted to a number based on the requirements, but I would like to convert it to a number in the final step before downloading.
I'm not sure if there is a suitable function or approach to solve this problem.
The text was updated successfully, but these errors were encountered: