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

StreamWriter corrupt Workbook created by Excel if the Sheet already exist #576

Closed
gvassili opened this issue Feb 12, 2020 · 1 comment
Closed

Comments

@gvassili
Copy link

Description
When using StreamWriter on an existing sheet created by an excel software the saved workbook is corrupted.
Writing rows or not in the StreamWriter doesn't matter, only StreamWriter.Flush corrupt the workbook.

If the the Workbook was created by Excelize the Sheet will have all it's anterior content overwritten but the Workbook won't be corrupted.

Steps to reproduce the issue:

  1. Create a workbook with an empty sheet on excel (tried google sheet as well), create "Sheet1" if not already there, save it.
package main

import "github.com/360EntSecGroup-Skylar/excelize/v2"

func main() {
	f, err := excelize.OpenFile("Workbook.xlsx")
	if err != nil {
		panic(err)
	}
	sw, err := f.NewStreamWriter("Sheet1")
	if err != nil {
		panic(err)
	}
	if err := sw.Flush(); err != nil {
		panic(err)
	}
	if err := f.SaveAs("Workbook2.xlsx"); err != nil {
		panic(err)
	}
}
  1. Open the Workbook2.xlsx in excel

Describe the results you received:
The opened workbook in empty and corrupted

Describe the results you expected:
A functional Workbook that kept his content. Or an error.

Output of go version:

go version go1.13.3 linux/amd64

Excelize version or commit ID:

2.1.0
@xuri xuri closed this as completed in 023dba7 Feb 12, 2020
@xuri
Copy link
Member

xuri commented Feb 12, 2020

Thanks for your issue. I have fixed it. Please try to upgrade the library with the master branch code.

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

2 participants