-
-
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
GetStyle does not return DecimalPlaces #1777
Labels
bug
Something isn't working
Comments
Thanks for your issue. I have fixed it. Please upgrade to the master branch code. This patch will be released in the next version. In addition, there are some special cases for using the package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
defer func() {
if err := f.Close(); err != nil {
fmt.Println(err)
}
}()
// Example 1: DecimalPlaces doesn't work if we have specified NumFmt with
// built-in all languages formats or built-in language
decimalPlaces := 4
styleID, err := f.NewStyle(&excelize.Style{
NumFmt: 2, // 0.00
DecimalPlaces: &decimalPlaces,
})
if err != nil {
fmt.Println(err)
return
}
style, err := f.GetStyle(styleID)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("DecimalPlaces: %d\r\n", *style.DecimalPlaces)
// DecimalPlaces: 2
// Example 2: DecimalPlaces doesn't work if we have specified CustomNumFmt
customNumFmt := "0.0"
styleID, err = f.NewStyle(&excelize.Style{
CustomNumFmt: &customNumFmt,
DecimalPlaces: &decimalPlaces,
})
if err != nil {
fmt.Println(err)
return
}
style, err = f.GetStyle(styleID)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("DecimalPlaces: %d\r\n", *style.DecimalPlaces)
// DecimalPlaces: 1
// Example 3: get style definition by the GetStyle or GetConditionalStyle
// function, the DecimalPlaces is nil if a number format code has the
// different decimal places in the positive part and negative part
customNumFmt = "0.0;0.00"
styleID, err = f.NewStyle(&excelize.Style{
CustomNumFmt: &customNumFmt,
})
if err != nil {
fmt.Println(err)
return
}
style, err = f.GetStyle(styleID)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("DecimalPlaces: %v\r\n", style.DecimalPlaces)
// DecimalPlaces: <nil>
// Example 4: get style definition by the GetStyle or GetConditionalStyle
// function, the DecimalPlaces is nil if a number format code only have the
// negative part
customNumFmt = ";0.00"
styleID, err = f.NewStyle(&excelize.Style{
CustomNumFmt: &customNumFmt,
})
if err != nil {
fmt.Println(err)
return
}
style, err = f.GetStyle(styleID)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("DecimalPlaces: %v\r\n", style.DecimalPlaces)
// DecimalPlaces: <nil>
// Example 5: get style definition by the GetStyle or GetConditionalStyle
// function, the NumFmt is not equal with the value when create the style
decimalPlaces = 4
styleID, err = f.NewStyle(&excelize.Style{
NumFmt: 165, // [$$-409]#,##0.00
DecimalPlaces: &decimalPlaces, // change [$$-409]#,##0.00 to [$$-409]#,##0.0000
})
if err != nil {
fmt.Println(err)
return
}
style, err = f.GetStyle(styleID)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("NumFmt: %d\r\n", style.NumFmt)
// NumFmt: 0
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Currently getting a style using
GetStyle
does not return the previously setDecimalPlaces
property. If this setting is retained in the Excel file this should also be read in theGetStyle
method.Steps to reproduce the issue:
1.
Describe the results you received:
DecimalPlaces
isnil
in both outputs. It makes sense in the first style, since no decimal places were set there.Describe the results you expected:
In the second output one would expect
DecimalPlaces
to be set to2
(pointer to variable set to2
to be specific).Output of
go version
:Excelize version or commit ID:
Environment details (OS, Microsoft Excel™ version, physical, etc.):
The text was updated successfully, but these errors were encountered: