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

Using the WriteTo() method with go 1.21 got problems #1734

Closed
ShowerBandV opened this issue Nov 30, 2023 · 4 comments
Closed

Using the WriteTo() method with go 1.21 got problems #1734

ShowerBandV opened this issue Nov 30, 2023 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@ShowerBandV
Copy link
Contributor

Description
We used excelize in the project, and in our business scenario, I need to call the WriteTo() method to create an Excel file. When I use go 1.18.10.0, this is completely feasible. Recently, we switched to go 1.21.0.0 and found that the generated Excel file is damaged. After converting to an XML file, it was found that each tag contains the xmlns="" attribute. After careful investigation, we found that the cause should be the 1.21 version of go.

Code And Result
here is the code

func main() {
	file := excelize.NewFile()
	buf := bytes.NewBuffer(nil)
	_, err := file.WriteTo(buf)
	if err != nil {
		log.Fatalf("write err:%s", err.Error())
	}
	openFile, err := os.OpenFile("empty.xlsx", os.O_CREATE|os.O_WRONLY, 0666)
	if err != nil {
		log.Fatalf("openfile err:%s", err.Error())
	}
	defer openFile.Close()
	n, err := buf.WriteTo(openFile)
	if err != nil {
		log.Fatalf("write file err:%s", err.Error())
	}
	fmt.Println("write bytes ", n)
}

This is the XML generated for Excel conversion in version 1.21

<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
    <dimension xmlns="" ref="A1"/>
    <sheetViews xmlns="">
      <sheetView tabSelected="true" workbookViewId="0"/>
    </sheetViews>
    <sheetFormatPr xmlns="" defaultRowHeight="15"/>
    <sheetData xmlns=""/>
</worksheet>

This is the XML generated for Excel conversion in version 1.18

<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
    <dimension ref="A1"/>
    <sheetViews>
      <sheetView tabSelected="true" workbookViewId="0"/>
    </sheetViews>
    <sheetFormatPr defaultRowHeight="15"/>
    <sheetData/>
</worksheet>

The file generated by Go 21 version cannot be opened in Excel, and Excel will report an error that needs to be fixed

Conclusion

the diffrent is the xmlns="" attr and the go 1.21 version seems to be the reason,can you fix this bug? After all, it's due to the upgrade of the Go version

@xuri xuri added the duplicate This issue or pull request already exists label Nov 30, 2023
@xuri
Copy link
Member

xuri commented Nov 30, 2023

Thanks for your issue. If you are reporting a new issue, make sure that we do not have any duplicates already exist. If it does not work with Go 1.21.0, please reference the issues #1465, #1595, #1603, #1608, #1614, #1619, #1620, #1621, #1623, #1633, #1637, #1641, #1642, #1648, #1651, #1652, #1656, #1657, #1660, #1663, #1670 and #1686. There are some incompatible changes in the Go 1.21.0 encoding/xml library. I have given feedback to the Go team and created a patch for it (golang/go#61881), and it has been fixed on Go 1.21.1. Please using the Go 1.20.11 and previous Go released version or upgrade to Go 1.21.1 and later. I have added notice on the README and documentation website for this, and I've closed this. If you have any questions, please let me know, and reopen this anytime.

@xuri xuri closed this as completed Nov 30, 2023
@ShowerBandV
Copy link
Contributor Author

Thank you for reply. Hope it will be fixed soon

@xuri
Copy link
Member

xuri commented Nov 30, 2023

This issue already has been fixed in https://go.dev/cl/466295. As my reply in above, it has been fixed on Go 1.21.1. So please using the Go 1.20.11 and previous Go released version or upgrade to Go 1.21.1 and later.

@ShowerBandV
Copy link
Contributor Author

ok,thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants