Skip to content

how to write a percent value #1424

Closed Answered by xuri
RiverFerry asked this question in Q&A
Discussion options

You must be logged in to vote

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)
        

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by RiverFerry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants