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 conflicts with some func #777

Closed
00LT00 opened this issue Feb 1, 2021 · 5 comments
Closed

streamWriter conflicts with some func #777

00LT00 opened this issue Feb 1, 2021 · 5 comments
Labels
kind/documentation Improvements or additions to documentation

Comments

@00LT00
Copy link

00LT00 commented Feb 1, 2021

this is my demo.

func main() {
	xlsx := excelize.NewFile()
	err := xlsx.SetSheetRow("Sheet1", "A1", &[]interface{}{"学号", "姓名", "是否缴费"})
	if err != nil {
		fmt.Println(err.Error())
	}
	data, err := xlsx.GetRows("Sheet1")
	fmt.Println(data)
	streamWriter, err := xlsx.NewStreamWriter("Sheet1")
	cell, _ := excelize.CoordinatesToCellName(1, 2)
	if err := streamWriter.SetRow(cell, []interface{}{"1", "2", "3"}); err != nil {
		fmt.Println(err.Error())
	}
	if err := streamWriter.Flush(); err != nil {
		fmt.Println(err.Error())
	}
	if err := xlsx.SaveAs("Book1.xlsx"); err != nil {
		fmt.Println(err)
	}

	data, err = xlsx.GetRows("Sheet1")
	fmt.Println(data)
}

the result is:
image

the file is :
image

Why can't I get data by GetRows after I use the streamWriter, and the data will losed? But when I get empty data by GetRows, there is streamWriter's data in the file. And if I use SetSheetRow to add row after the file that has been saved with streamWriter, the excel file will be broken.

I want know if maybe the "bug" is a feature in fact because it looks like very obvious. I can't get any information in the docs.

@xuri
Copy link
Member

xuri commented Feb 2, 2021

Thanks for your issue. You can read cell value by GetRows which value is just written with common API (such as SetSheetRow and SetCellValue). The SetSheetRow is not a streaming API, it will not work in stream mode, in another word, we can not using common API and stream API mixed, also ref: #725

@00LT00
Copy link
Author

00LT00 commented Feb 2, 2021

Thanks for reply @xuri . I also can't understand this result. Because in my understanding, when I call Flush, I have written the data to this file. Why is the data lost?
I set data by SetSheetRow. And then I create a streamWriter. I call the Flush. Then I can't get data by GetRows.
Do you mean is that we can't useing common Api and stream Api mixed for any file?

@xuri
Copy link
Member

xuri commented Feb 2, 2021

Yes, the data generated by streaming API storage way is different with common API, so it seems "missing", but it can be stored in a spreadsheet if you save the file.

@00LT00
Copy link
Author

00LT00 commented Feb 2, 2021

All right. But I suggest you should write some tips at here. And I think it's a bit counterintuitive. Maybe you can consider merging these two APIs.

@00LT00 00LT00 closed this as completed Feb 2, 2021
@xuri xuri added the kind/documentation Improvements or additions to documentation label Feb 2, 2021
xuri added a commit to xuri/excelize-doc that referenced this issue Feb 6, 2021
@xuri
Copy link
Member

xuri commented Feb 6, 2021

Hi @00LT00, thanks for your suggestion. I have clarified for streaming API doesn't work with common API in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants