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

v2.3.2 generates empty worksheets, but works in v2.3.1 #813

Closed
SVilgelm opened this issue Apr 2, 2021 · 4 comments
Closed

v2.3.2 generates empty worksheets, but works in v2.3.1 #813

SVilgelm opened this issue Apr 2, 2021 · 4 comments
Labels
confirmed This issue can be reproduced
Projects

Comments

@SVilgelm
Copy link

SVilgelm commented Apr 2, 2021

Description

In case of writing data to a new worksheet and then deleted "Sheet1" (default one), the final file has no data at all

Steps to reproduce the issue:

  1. Create new file
  2. Create new sheet
  3. Write data to the newly created sheet
  4. Delete default "Sheet 1"
  5. Save file

Describe the results you received:

empty file

Describe the results you expected:

file with my data

Output of go version:

go version go1.16.2 darwin/amd64

Excelize version or commit ID:

v2.3.2

Environment details (OS, Microsoft Excel™ version, physical, etc.):
System: MacOS
Use Numbers to open the files

Snippet

package main

import (
	"fmt"
	"math/rand"

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

func main() {
	file := excelize.NewFile()
	file.NewSheet("No Default Sheet")
	streamWriter, err := file.NewStreamWriter("No Default Sheet")
	if err != nil {
		fmt.Println(err)
	}
	styleID, err := file.NewStyle(`{"font":{"color":"#777777"}}`)
	if err != nil {
		fmt.Println(err)
	}
	if err := streamWriter.SetRow("A1", []interface{}{
		excelize.Cell{StyleID: styleID, Value: "Data"},
	}); err != nil {
		fmt.Println(err)
	}
	for rowID := 2; rowID <= 30; rowID++ {
		row := make([]interface{}, 50)
		for colID := 0; colID < 50; colID++ {
			row[colID] = rand.Intn(640000)
		}
		cell, _ := excelize.CoordinatesToCellName(1, rowID)
		if err := streamWriter.SetRow(cell, row); err != nil {
			fmt.Println(err)
		}
	}
	if err := streamWriter.Flush(); err != nil {
		fmt.Println(err)
	}

	file.DeleteSheet("Sheet1")

	if err := file.SaveAs("Book1.xlsx"); err != nil {
		fmt.Println(err)
	}
}

This code works well with v2.3.1, but does not work in v2.3.2
If I remove the line file.DeleteSheet("Sheet1"), then the "No Default Sheet" contains the data, otherwise it's empty

@SVilgelm
Copy link
Author

SVilgelm commented Apr 2, 2021

I checked the master branch, result is same, no data

@SVilgelm
Copy link
Author

SVilgelm commented Apr 2, 2021

same happens if replace DeleteSheet with UpdateLinkedValue:

	if err := file.UpdateLinkedValue(); err != nil {
		fmt.Println(err)
	}

no errors, but the sheet is empty, even if the default name is used

@xuri xuri added the confirmed This issue can be reproduced label Apr 3, 2021
@xuri xuri closed this as completed in 89c262f Apr 3, 2021
@xuri
Copy link
Member

xuri commented Apr 3, 2021

Thanks for your feedback, I confirmed this issue caused by PR #659, and I have fixed it, please try to use the master branch code, and this patch will be released in the next version.

@SVilgelm
Copy link
Author

SVilgelm commented Apr 3, 2021

Confirm, the issue is fixed!

@xuri xuri added this to Bugfix in v2.4.0 Apr 5, 2021
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
No open projects
v2.4.0
Bugfix
Development

No branches or pull requests

2 participants