Closed tony-clariondoor closed 2 months ago
Thanks for your feedback. Could you provide the workbook as file attachment without confidential info?
That workbook is fairly long and complex, so I tried to recreate it using a fresh .xlsx
file and I got the same results.
Using this code:
package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f, err := excelize.OpenFile("test.xlsx")
if err != nil {
fmt.Println(err)
return
}
sheetName := f.GetSheetName(f.GetActiveSheetIndex())
rows, err := f.GetRows(sheetName)
if err != nil {
fmt.Println(err)
return
}
for rowNumber, row := range rows {
for columnPosition := range row {
cellID, _ := excelize.CoordinatesToCellName(columnPosition+1, rowNumber+1)
cellStyle, _ := f.GetCellStyle(sheetName, cellID)
colCell, _ := f.GetCellValue(sheetName, cellID)
rawCell, _ := f.GetCellValue(sheetName, cellID, excelize.Options{RawCellValue: true})
fmt.Printf("Cell ID: %s -- Cell Styling: %v -- Cell Value: %s -- Raw Cell Value: %s\n", cellID, cellStyle, colCell, rawCell)
}
}
if err := f.Close(); err != nil {
fmt.Println(err)
}
}
on the attached workbook
I got the following results:
Cell ID: A1 -- Cell Styling: 4 -- Cell Value: 0 -- Raw Cell Value: 0
Cell ID: A2 -- Cell Styling: 3 -- Cell Value: 0 -- Raw Cell Value: 0
Cell ID: A3 -- Cell Styling: 1 -- Cell Value: 0 -- Raw Cell Value: 0
Cell ID: A4 -- Cell Styling: 2 -- Cell Value: 0 -- Raw Cell Value: 0
Cell ID: A5 -- Cell Styling: 4 -- Cell Value: 0% -- Raw Cell Value: 0.00001
Cell ID: A6 -- Cell Styling: 1 -- Cell Value: 1.23% -- Raw Cell Value: 0.01234
Cell ID: A7 -- Cell Styling: 1 -- Cell Value: 12.34% -- Raw Cell Value: 0.1234
Cell ID: A8 -- Cell Styling: 1 -- Cell Value: 123.40% -- Raw Cell Value: 1.234
Cell ID: A9 -- Cell Styling: 1 -- Cell Value: 1234.00% -- Raw Cell Value: 12.34
which leads me to believe that either I am getting the cell value wrong or there is something in there that is not liking the idea of dividing by zero so it is just returning a raw zero.
Additionally, I did check the loop for an error condition on any of the cell actions, and none of them produced errors, so I removed that check in the code for the sake of brevity.
Thanks for your issue. This issue has been fixed, please upgrade to the master branch code by go get -u github.com/xuri/excelize/v2@master
, and this patch will be released in the next version.
Thank you very much! I'll pull this down and test it out.
Description When reading a spreadsheet I am having problems getting the percent sign to show up for a cell that is formatted as
Percentage
when the value is zero. I had this failure with 0, 0.0, 0.00, etc. I am hoping that I am just doing something wrong in my code.Steps to reproduce the issue: See Below
Describe the results you received: In this snippet of code here I am checking two cells that are formatted in Excel as Percentage:
and I get these results:
When I set
RawCellValue
totrue
, I get these results:Describe the results you expected: I expected the percent to be displayed when I get the cell value without the
RawCellValue
option set to true.Output of
go version
:Excelize version or commit ID:
Environment details (OS, Microsoft Excel™ version, physical, etc.): MacOS is where I performed this test, but it also fails in different docker containers (Alpine Linux, Debian). Excel document was created in version 16.86, but other versions failed as well.