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

Corrupted xlsx after write operation #152

Closed
valasek opened this issue Nov 12, 2017 · 18 comments
Closed

Corrupted xlsx after write operation #152

valasek opened this issue Nov 12, 2017 · 18 comments

Comments

@valasek
Copy link

valasek commented Nov 12, 2017

Thank you for your great work on excelize. Reading works like a charm.
But I have an issue with writing.

I update one cell, save and XLSX file is corrupted.

Input file: source_file.xlsx
Output corrupted file: Workbook.xlsx

How I am writing to the file

xlsx, err := excelize.OpenFile(path)
xlsx.SetCellInt("Sheet1", "I15", 100)
err := xlsx.SaveAs("./Workbook.xlsx")

Erro message during opening Workbook.xlsx
image

And error if I try to recover the workbook:
Replaced Part: /xl/worksheets/sheet1.xml part with XML error. Load error. Line 2, column 213397.
Removed Records: Formula from /xl/calcChain.xml part (Calculation properties)

go env

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\stanislav.valasek\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
@cescoferraro
Copy link

Have you tried using SetCellValue?

@valasek
Copy link
Author

valasek commented Nov 13, 2017

Yes xlsx.SetCellValue("Sheet1", "I15", 100)
But if I understand SetCellValue correctly it only switches based on data type and in this case it should call SetCellInt or am I missing something?

Result it the same. Output file - Workbook.xlsx

Output file is smaller by 680Kb and corrupted.

xuri added a commit that referenced this issue Nov 16, 2017
Signed-off-by: Ri Xu <xuri.me@gmail.com>
@xuri
Copy link
Member

xuri commented Nov 16, 2017

@valasek Thanks for your issue. I have fixed it by add missing XML attribute and namespaces.

@valasek
Copy link
Author

valasek commented Nov 16, 2017

@xuri thank you. I have updated the package and tested. Works better than before.
I am still getting "Removed Feature: View from /xl/worksheets/sheet2.xml part" but after I hit Repair my excel I can see a content.
Output file size is similar from 61,4Kb to 51,9 Kb.
I will do some more testing and let you know.

@valasek
Copy link
Author

valasek commented Nov 16, 2017

@xuri I made a diff of extracted xlsx files input and output before any changes/repairs.
Found a difference in files: styles.xml, workbook.xml, workbook.xml.rels, sheet1.xml.
Attached is a diff of relevant files - diff.txt

@xuri
Copy link
Member

xuri commented Nov 16, 2017

Please attach broken and input file if you can.

@valasek
Copy link
Author

valasek commented Nov 16, 2017

Which contact can I use to share it directly? I have used your gmail.

xuri added a commit that referenced this issue Nov 16, 2017
…iew` in the workbook, relate issue #152.

Signed-off-by: Ri Xu <xuri.me@gmail.com>
@valasek
Copy link
Author

valasek commented Nov 17, 2017

@xuri thank you. I have updated the package and tested. Now I can open a sheet where one cell was updated using excelize without a warning.
Based on the above I consider this issue as solved. I do not want to close the issue directly without your confirmation.
If I find any other issues I will report.
Side note: output files are still smaller and I have sent you the input and output files via email.

@valasek
Copy link
Author

valasek commented Nov 28, 2017

Based on my testing updated excel files are readable and give any further warnings. Closing the issue. Thank you for fixing.

@ntttrang
Copy link

ntttrang commented Mar 11, 2020

Hi dev team, @xuri,
I want to create new excel file from template excel but I encountered the same issue with version 2.1.0 (Stream Writer).
Could you please help me check this issue?

input_output_file.zip

Input file: Template.xlsx
Output corrupted file: Template_20200311_104439.xlsx

Here is my code
sheetName1 := "Sheet1" streamWriter, err := f.NewStreamWriter(sheetName1) if err != nil { fmt.Println(err) }
if err := streamWriter.Flush(); err != nil { fmt.Println(err) }

@xuri
Copy link
Member

xuri commented Mar 11, 2020

Hi @ntttrang, please try to upgrade the library with the master branch code. Ref: #576

@ntttrang
Copy link

Hi @ntttrang, please try to upgrade the library with the master branch code. Ref: #576

@xuri : I am a beginner in Golang, so I don't know how to upgrade the library. Is this latest version?

module export_excel_file2

go 1.12

require (
github.com/360EntSecGroup-Skylar/excelize v1.4.1 // indirect
github.com/360EntSecGroup-Skylar/excelize/v2 v2.1.0 // indirect
)

I used this command to upgrade library, but this issue is still existed.
go get -u github.com/360EntSecGroup-Skylar/excelize

@xuri
Copy link
Member

xuri commented Mar 11, 2020

@ntttrang please reference issue #488.

@ntttrang
Copy link

@ntttrang please reference issue #488.

Thank you for your help

@jograjrathore
Copy link

Uploading Vehicle Activity Reports-119 -2023-2024.xlsx…

hello PLease help me the same issues. file attached for referance.

@xuri
Copy link
Member

xuri commented Oct 6, 2023

Hi @jograjrathore, thanks for your feedback. Which version of the Go language and Excelize library are you using? Could you show us a complete, standalone example program or reproducible demo? The file attachment can not download.

@hibare
Copy link

hibare commented Feb 2, 2024

@xuri I'm facing same problem. I tried example from readme. File is generated but when I try to open, it throws above error.
I'm on version 16.81 on mac

@xuri
Copy link
Member

xuri commented Feb 2, 2024

Hi @hibare, thanks for your feedback. Which version of the Go language and Excelize library are you using? Could you show us a complete, standalone example program or reproducible demo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants