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

Remove column caused workbook corrupted #1879

Closed
jianxinhou opened this issue Apr 17, 2024 · 1 comment · Fixed by #1880
Closed

Remove column caused workbook corrupted #1879

jianxinhou opened this issue Apr 17, 2024 · 1 comment · Fixed by #1880
Labels
confirmed This issue can be reproduced
Projects

Comments

@jianxinhou
Copy link
Contributor

jianxinhou commented Apr 17, 2024

Description

开发者你好,我在使用该库的过程中,发现具有以下特点的文件:

  1. 经过WPS Office打开并保存;
  2. 带有序列类型的数据验证;

在调用(f *File) RemoveCol方法后无法使用MS Office正常打开,如Steps to reproduce the issue所示。

我尝试定位了问题产生的原因,发现对于数据验证的下拉列表
MS Office会将其保存为:
image
而WPS Office则会保存为:
image

因此,对于WPS Office生成的文件,在调用(f *File) adjustDataValidations时,对formula的转义会不正确,进而导致该问题。

我提了一个PR以修复该问题,经过测试修复后的代码能够使xlsx文件被正确打开。但不确定会不会有别的坑是我没注意到的,烦请帮忙review一下。

Steps to reproduce the issue:

  1. 使用WPS Office打开带有下拉列表的xlsx文件并保存(MS Office生成的文件:test.xlsx;经过WPS Office打开后保存的文件:test111.xlsx
  2. 执行以下代码生成一个新的xlsx文件:
func TestXxx(t *testing.T) {
	bs, err := os.ReadFile("./test111.xlsx")
	assert.Nil(t, err)
	file, err := OpenReader(bytes.NewReader(bs))
	assert.Nil(t, err)

	err = file.RemoveCol("Sheet2", "A")
	assert.Nil(t, err)

	buf, err := file.WriteToBuffer()
	assert.Nil(t, err)

	err = os.WriteFile("tttt.xlsx", buf.Bytes(), 0644)
	assert.Nil(t, err)
}
  1. 使用MS office无法正确打开生成的xlsx:
    image

  2. 使用 WPS office 能够打开,但下拉框无法正确下拉
    image

Output of go version:

go version go1.21.6 darwin/arm64

Excelize version or commit ID:

3e636ae7b20285d4efb3d21bba0e1c165318f9f8

Environment details (OS, Microsoft Excel™ version, physical, etc.):
image
image

GOARCH='arm64'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/30/cmv9c_5j3mq_kthx63sb1t5c0000gn/T/go-build1186998755=/tmp/go-build -gno-record-gcc-switches -fno-common'
xuri added a commit to jianxinhou/excelize that referenced this issue Apr 18, 2024
…none formula data validation rules

- Update dependencies module to fix vulnerabilities
- Update unit tests
@xuri xuri linked a pull request Apr 18, 2024 that will close this issue
10 tasks
@xuri xuri added the confirmed This issue can be reproduced label Apr 18, 2024
@xuri xuri added this to Improve the Compatibility in v2.9.0 Apr 18, 2024
xuri pushed a commit that referenced this issue Apr 18, 2024
…ormula data validation rules (#1880)

- Update dependencies module to fix vulnerabilities
- Update unit tests

Co-authored-by: houjianxin.rupert <houjianxin.rupert@bytedance.com>
@xuri xuri changed the title 调用RemoveCol并保存为xlsx后,文件无法正确打开 Remove column caused workbook corrupted Apr 18, 2024
@xuri
Copy link
Member

xuri commented Apr 18, 2024

Thanks for your issue and pull request. The pull request has been merged, and this patch will be released in the next version.

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
v2.9.0
Improve the Compatibility
Development

Successfully merging a pull request may close this issue.

2 participants