-
-
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
How can I convert cell style to string format ? #512
Comments
Are you reading 'Number' values from an Excel file? Excelize will read 'Number' values like "101,102" as "101102" and you can convert this to your desired format. To convert "12100122" to "12,100,122", you can use 'humanize' package from this page on Stack Overflow. Do you want to insert values using excelize and have Excel display commas? If so you can way you can set these values as strings, so that the comma formatting will carry over to Excel. // will be formatted as 'Text' in Excel, displayed as "101,102"
f.SetCellValue("Sheet1", "A1", "101,102")
// will be formatted as 'General' in Excel, displayed as "101,102,103"
val := 101102103
f.SetCellValue("Sheet1", "A2", humanize.FormatInteger("#,###.", val)) The above values will be read in as "101,102" and "101,102,102", respectively, in excelize,. |
Thanks for your recommended humanize package.@drewhbestbuddy My Excelize vesion is 1.4.1 |
I'm not finding how to retrieve the cell value type, or set a cell type excelize. It looks like the type is stored in You could call If the reason to retrieve the type is to make sure the values are parsed correctly, I think this is still possible without knowing what the type is in Excel. Is the desired behavior to parse the values from the user correctly? What are the types of values expected, and what are the desired values? For instance, if you the only difference is numbers that could be "101102" and "101,102", you could strip out (or add) commas to the number after it is read from excelize. |
Exactly,the only problem is I can not know what its real type in the Excel. |
No problem. Adding a function like this would allow you to retrieve the // GetCellType provides a function to get excel cell type from cell.
//
// type,err := f.GetCellType("Sheet1", "A1")
//
func (f *File) GetCellType(sheet, axis string) (string, error) {
xlsx, err := f.workSheetReader(sheet)
if err != nil {
return "", err
}
cellData, _, _, err := f.prepareCell(xlsx, sheet, axis)
if err != nil {
return "", err
}
return cellData.T, nil
} Though I noticed excelize only assigns this value for |
I have this problem, too.. |
me too... how do you handle it? |
Sorry for the late reply. Excelize library support gets cell data type by the |
As you know, excel will convert "101,102" to "101102" as number format?So how can i get the original value "101,102". Or how can I convert all my cells to string format ? I don't need number_format.
The text was updated successfully, but these errors were encountered: