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

Clear formats in file #1508

Closed
Krevedos opened this issue Mar 24, 2023 · 9 comments
Closed

Clear formats in file #1508

Krevedos opened this issue Mar 24, 2023 · 9 comments
Labels
confirmed This issue can be reproduced

Comments

@Krevedos
Copy link

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

@xuri
Copy link
Member

xuri commented Mar 24, 2023

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?

@Krevedos
Copy link
Author

Krevedos commented Mar 24, 2023

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...
If I open the file in excel and save it without making any changes, everything works fine after that. I don't understand what's going on with this file...

@xuri
Copy link
Member

xuri commented Mar 25, 2023

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.

@xuri xuri added the needs more info This issue can't reproduce, need more info label Mar 25, 2023
@Krevedos
Copy link
Author

Krevedos commented Mar 25, 2023

I use the last version lib. Ok, for example, the first line is displayed perfectly, as in the excel file, but line 100000 already looks different from the file, I am attaching screenshots...

1

2

3

@xuri
Copy link
Member

xuri commented Mar 27, 2023

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?

@Krevedos
Copy link
Author

Krevedos commented Mar 27, 2023

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.
I can attach my test code, so you can see the problem, if its need.

@xuri xuri added confirmed This issue can be reproduced in progress Working in progress and removed needs more info This issue can't reproduce, need more info labels Mar 27, 2023
@xuri
Copy link
Member

xuri commented Mar 27, 2023

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 60b9d02. Would you like to create a pull request to fix it? Or I'll fix it later.

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) {

@Krevedos
Copy link
Author

Thx. I am wait for your fix.

@xuri xuri closed this as completed in 9dbba9f Mar 27, 2023
@xuri
Copy link
Member

xuri commented Mar 27, 2023

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.

@xuri xuri removed the in progress Working in progress label Mar 27, 2023
fudali113 pushed a commit to fudali113/excelize that referenced this issue Apr 17, 2023
xuri added a commit to JDavidVR/excelize that referenced this issue Jul 11, 2023
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed This issue can be reproduced
Projects
None yet
Development

No branches or pull requests

2 participants