Skip to content

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

@gvassili

Description

@gvassili

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions