-
-
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
Clear formats in file #1508
Comments
Thanks for your feedback. What's means that parsing incorrectly, and what's your expected result? Could you follow the issue templates to provide more details about that? |
I have made some test with file, and i think that the problem is in the first line, where the names are written in Cyrillic, if i rename them, then the file is perfectly parsed. Maybe there are some special characters? Can you analyze my file? (test.xlsx) UPD... |
Sorry, I didn't understand what's means "parse incorrectly" as your say. Which version of this library were your using? Did you get any errors? Please follow the issue templates to provide more details about this. |
It seems you set the numeric cell value as a text string. Please convert it to numeric data types before setting the cell value. Could you follow the issue template, and show us a complete, standalone example program or reproducible demo? |
This excel file i am get from mail, I don’t install anything in it, I have the task of parsing it and then inserting rows into the database. But the problem is that some kind of bugs occurs during parsing, I have attached screenshots where you can see that the first line is the same as in the original file, but line 100000 no longer matches the source file. |
This issue is caused by the shared string table index which contains blank characters, we need to trim these blank characters before converting them into integers, for example, made some changes based on the commit diff --git a/cell.go b/cell.go
index 5ebcefe..5fcadce 100644
--- a/cell.go
+++ b/cell.go
@@ -564,7 +564,7 @@ func (c *xlsxC) getValueFrom(f *File, d *xlsxSST, raw bool) (string, error) {
case "s":
if c.V != "" {
xlsxSI := 0
- xlsxSI, _ = strconv.Atoi(c.V)
+ xlsxSI, _ = strconv.Atoi(strings.TrimSpace(c.V))
if _, ok := f.tempFiles.Load(defaultXMLPathSharedStrings); ok {
return f.formattedValue(c.S, f.getFromStringItem(xlsxSI), raw)
}
diff --git a/cell_test.go b/cell_test.go
index 58a4bee..565c1c9 100644
--- a/cell_test.go
+++ b/cell_test.go
@@ -432,6 +432,11 @@ func TestGetValueFrom(t *testing.T) {
value, err := c.getValueFrom(f, sst, false)
assert.NoError(t, err)
assert.Equal(t, "", value)
+
+ c = xlsxC{T: "s", V: " 1 "}
+ value, err = c.getValueFrom(f, &xlsxSST{Count: 1, SI: []xlsxSI{{}, {T: &xlsxT{Val: "s"}}}}, false)
+ assert.NoError(t, err)
+ assert.Equal(t, "s", value)
}
func TestGetCellFormula(t *testing.T) { |
Thx. I am wait for your fix. |
Thanks for your issue. I have fixed this issue. Please upgrade to the master branch code, and this patch will be released in the next version. |
I have a problem with the file, it parse incorrectly, but if I open the file manual in excel and press the CLEAR FORMATS button and save the file, the problem disappears. Is there a way to clear formats programmatically? Thx for all !
test.xlsx
The text was updated successfully, but these errors were encountered: