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

The first execution of Flush() data will be written to Excel, and SetRow() after Flush() will not take effect #1869

Closed
chaimengfei opened this issue Apr 2, 2024 · 1 comment

Comments

@chaimengfei
Copy link

When flush() is executed multiple times, it will only be written to the Excel file on the first execution,and the generated Excel table only has one record :Amy 10

The example:

// 创建一个新的 Excel 文件
	f := excelize.NewFile()

	// 使用 NewStreamWriter 方法创建一个流式写入器
	sw, err := f.NewStreamWriter("Sheet1")
	if err != nil {
		panic(err)
	}

	// 向工作表写入数据并多次调用 Flush() 方法
	if err = sw.SetRow("A1", []interface{}{"name", "age"}); err != nil {
		panic(err)
	}
	if err = sw.Flush(); err != nil {
		panic(err)
	}
	if err = sw.SetRow("A2", []interface{}{"Amy", "10"}); err != nil {
		panic(err)
	}
	if err = sw.Flush(); err != nil {
		panic(err)
	}
	if err = sw.SetRow("A3", []interface{}{"Danel", "12"}); err != nil {
		panic(err)
	}
	if err = sw.Flush(); err != nil {
		panic(err)
	}

	// 保存 Excel 文件
	if err = f.SaveAs("example.xlsx"); err != nil {
		panic(err)
	}
@chaimengfei chaimengfei changed the title Flush() on the first execution The first execution of Flush() data will be written to Excel, and SetRow() after Flush() will not take effect Apr 2, 2024
@xuri
Copy link
Member

xuri commented Apr 2, 2024

Thanks for your issue. In streaming writing mode, just call Flush function one time after data write finished for each worksheet. I'll close this issue, if you have any questions, please let me know, and you can reopen this anytime.

@xuri xuri closed this as completed Apr 2, 2024
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