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

SetCellStr creates cells that are interpreted by excel with format "General" #1915

Closed
nicolasfranck opened this issue Jun 3, 2024 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@nicolasfranck
Copy link

Description

When I use the method SetCellStr I get cells
that are formatted by Microsoft Excel with format "General" instead of the
expected format "Text"

Output of go version:

go version go1.21.4 darwin/arm64

Excelize version or commit ID:

2.8.0

Environment details (OS, Microsoft Excel™ version, physical, etc.):

MAC OS X

@xuri
Copy link
Member

xuri commented Jun 3, 2024

Thanks for your issue. This was duplicated with issue #705, you can set cell A1 as text by number format like this:

var style int
if style, err = f.NewStyle(&excelize.Style{NumFmt: 49}); err != nil {
    fmt.Println(err)
    return
}
if err = f.SetCellStyle("Sheet1", "A1", "A1", style); err != nil {
    fmt.Println(err)
    return
}

This library also support set multiple cell's style by SetColStyle and SetRowStyle functions.

@xuri xuri added the duplicate This issue or pull request already exists label Jun 3, 2024
@nicolasfranck
Copy link
Author

I am not sure what this means: should the method SetCellStr do this actually, or should cell styling do this?

What does NumFmt 49 do btw?

@xuri
Copy link
Member

xuri commented Jun 4, 2024

The SetCellStr function used for accept Go language's string data type value, this function won't affect the format of the cell, so if you need set cell style with specified number format, may need to create the style with number format by the NewStyle function at first, and you will get a style index, and then set cells style with that. The excelize library supports create style with number format by built-in number format index or custom number format code, the number 49 represents the "Text" format. As the comments in issue #705 say, you can find more built-in number format mapping details on the documentation website.

@nicolasfranck
Copy link
Author

Ok, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants