Skip to content
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

Excel's celll format does not support numeric types #1411

Closed
kkkilo opened this issue Dec 2, 2022 · 11 comments
Closed

Excel's celll format does not support numeric types #1411

kkkilo opened this issue Dec 2, 2022 · 11 comments

Comments

@kkkilo
Copy link

kkkilo commented Dec 2, 2022

Background

We need to use excel to display a large amount of data, including percentages, decimals, currency, time, and text.

Problem

The “decimal” cannot control the number of digits and the format is not a decimal
(the below picture shows what I want)
image
but most of them(I mean all the numFmt ID I test) shows "custom"
I know use "customNumFmt" can control the number of digits but the format is "custom"!

Thanks!

@xuri
Copy link
Member

xuri commented Dec 2, 2022

Thanks for your feedback. But sorry, I don't understand what you exactly mean. This problem may be similar to issue #705, and you can use build-in number format ID 2 for the numeric data type values. You can find more built-in number format mapping details in the documentation.

@kkkilo
Copy link
Author

kkkilo commented Dec 2, 2022

I am so sorry that my English is poor, the more detail is below:
I used to use number format ID 2:
image

At the same time, all the built-in numFmts can not control the digits's decimal places, it always 2 places!

Thanks for answer!

@xuri
Copy link
Member

xuri commented Dec 3, 2022

Please use the custom number format for the Kingsoft WPS, but which will incompatible with Microsoft Excel for Mac:

customNumFmt := "0.00_ "
styleID, err := f.NewStyle(&excelize.Style{CustomNumFmt: &customNumFmt})
if err != nil {
    fmt.Println(err)
    return
}

@kkkilo
Copy link
Author

kkkilo commented Dec 4, 2022

the code you pin seems don't work, it shows the format is "General".
image
( the format "0.00_" seems invalid?)
image

btw my wps is kingsoft.

@xuri
Copy link
Member

xuri commented Dec 4, 2022

Which version of Excelize library and Kingsoft WPS are you using?

@kkkilo
Copy link
Author

kkkilo commented Dec 4, 2022

exelize: 2.6.0
wps 4.4.2

@xuri
Copy link
Member

xuri commented Dec 4, 2022

It seems your provided Kingsoft WPS version is incorrect, version 4.4.2 was released in 2001, which does not support the spreadsheet in xlsx format, I have tested with version 11.1.0.12763, and it works well.

@xuri xuri added the needs more info This issue can't reproduce, need more info label Dec 4, 2022
@kkkilo
Copy link
Author

kkkilo commented Dec 4, 2022

but I can't find any other version info in wps
image
(when I click the update button, it shows the wps is the newest version🥺)

@xuri
Copy link
Member

xuri commented Dec 5, 2022

Thanks for your feedback. Here is an example for you reference, and it works on WPS Office for Mac:

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)
        }
    }()
    if err := f.SetCellValue("Sheet1", "A1", 23.455667); err != nil {
        fmt.Println(err)
        return
    }
    customNumFmt := "0.00_ "
    styleID, err := f.NewStyle(&excelize.Style{CustomNumFmt: &customNumFmt})
    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)
    }
}

@xuri
Copy link
Member

xuri commented Dec 22, 2022

It seems still not have enough info or feedback for this issue, so I'll close this issue, if you have any questions, please let me know to reopen this anytime.

@xuri xuri closed this as completed Dec 22, 2022
@kkkilo
Copy link
Author

kkkilo commented Dec 22, 2022

The question has been resolved. and the code did work! Thanks a lot!!! ❤️

@xuri xuri removed the needs more info This issue can't reproduce, need more info label Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants