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

使用官网excelize.NewFile()的示例代码创建的xlsx文件报错 #1768

Closed
user1026 opened this issue Dec 27, 2023 · 1 comment
Closed
Labels
duplicate This issue or pull request already exists

Comments

@user1026
Copy link

环境

  1. win11家庭版 22H2
  2. go 1.21版本
  3. 微软office家庭和学生版2021
  4. WPS 12.1.0.16120

问题描述
使用官网文档中excelize.NewFile()的示例代码创建的xlsx文件用微软office打开报灾难性错误,wps打开为空白文件

package main
import (
    "fmt"
    "github.com/xuri/excelize/v2"
)

func main() {
    f := excelize.NewFile()
    defer func() {
        if err := f.Close(); err != nil {
            fmt.Println(err)
        }
    }()
    // 创建一个工作表
    index, err := f.NewSheet("Sheet2")
    if err != nil {
        fmt.Println(err)
        return
    }
    // 设置单元格的值
    f.SetCellValue("Sheet2", "A2", "Hello world.")
    f.SetCellValue("Sheet1", "B2", 100)
    // 设置工作簿的默认工作表
    f.SetActiveSheet(index)
    // 根据指定路径保存文件
    if err := f.SaveAs("Book1.xlsx"); err != nil {
        fmt.Println(err)
    }
}

微软office报错描述
已修复的部件: 有 XML 错误的 /xl/worksheets/sheet1.xml。 灾难性故障 行 2,列 419。
已修复的部件: 有 XML 错误的 /xl/worksheets/sheet2.xml。 灾难性故障 行 2,列 302。

报错文件
这是生成的xlsx文件解压后的报错的那个xml文件(sheet1表)

<?xml version="1.0" encoding="UTF-8"?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1" xmlns=""></dimension><sheetViews xmlns=""><sheetView workbookViewId="0"></sheetView></sheetViews><sheetFormatPr defaultRowHeight="15" xmlns=""></sheetFormatPr><sheetData xmlns=""><row r="2"><c r="B2"><v>100</v></c></row></sheetData></worksheet>

这是桌面右键新建的能直接打开的xlsx文件(sheet1表)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac xr xr2 xr3" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" xmlns:xr2="http://schemas.microsoft.com/office/spreadsheetml/2015/revision2" xmlns:xr3="http://schemas.microsoft.com/office/spreadsheetml/2016/revision3" xr:uid="{00000000-0001-0000-0000-000000000000}"><dimension ref="A1"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="E12" sqref="E12"/></sheetView></sheetViews><sheetFormatPr defaultColWidth="9" defaultRowHeight="14" x14ac:dyDescent="0.25"/><sheetData><row r="1" spans="1:1" x14ac:dyDescent="0.25"><c r="A1"><v>100</v></c></row></sheetData><phoneticPr fontId="1" type="noConversion"/><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/><pageSetup paperSize="9" orientation="portrait"/></worksheet>
@xuri xuri added the duplicate This issue or pull request already exists label Dec 27, 2023
@xuri
Copy link
Member

xuri commented Dec 27, 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, #1686, #1734, #1752 and #1764. 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.12 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.

谢谢您的议题,在您创建新的议题之前,请确保不存在任何重复的议题。这与已有议题重复,请参考 #1465, #1595, #1603, #1608, #1614, #1619, #1620, #1621, #1623, #1633, #1637, #1641, #1642, #1648, #1651, #1652, #1656, #1657, #1660, #1663, #1670, #1686#1734#1752#1764。Go 1.21.0 对 encoding/xml 标准库做了不兼容的更改,我已将该问题反馈至 Go 团队,并提交了修复补丁 golang/go#61881,已在 Go 1.21.1 中修复。请使用 Go 1.20.12 以及更早版本,或升级 1.21.1 及以上版本。我已经为此在自述文档和文档网站上添加了通知,因此我将关闭此议题。如果您有任何问题,请告诉我,并可随时重新打开。

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