how to write a percent value #1424
-
i want to draw a chart with percent value,
i can not find a way to directly set percent value, so anyone knows? thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
xuri
Dec 20, 2022
Replies: 1 comment
-
Thanks for your feedback. Please reference issue #705 and #1411. First, create a style with percentage number format and get a style ID, then set the cell style by style ID. For example, set the Sheet1!A1 with percentage style with 2 decimal places: package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
if err := f.SetCellValue("Sheet1", "A1", 0.123456); err != nil {
fmt.Println(err)
return
}
defer func() {
if err := f.Close(); err != nil {
fmt.Println(err)
}
}()
styleID, err := f.NewStyle(&excelize.Style{NumFmt: 10})
if err != nil {
fmt.Println(err)
return
}
if err := f.SetCellStyle("Sheet1", "A1", "A1", styleID); err != nil {
fmt.Println(err)
return
}
if err := f.SaveAs("Book1.xlsx"); err != nil {
fmt.Println(err)
}
} The value of Sheet1!A1 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
RiverFerry
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your feedback. Please reference issue #705 and #1411. First, create a style with percentage number format and get a style ID, then set the cell style by style ID. For example, set the Sheet1!A1 with percentage style with 2 decimal places: