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

Unmerge all cells cause corrupted file #782

Closed
blueicesir opened this issue Feb 9, 2021 · 4 comments
Closed

Unmerge all cells cause corrupted file #782

blueicesir opened this issue Feb 9, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@blueicesir
Copy link

blueicesir commented Feb 9, 2021

使用版本
github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.2

Go 1.15 编译环境 windows 64bit

package main

import (
	"fmt"
	"strings"
	"github.com/360EntSecGroup-Skylar/excelize/v2"
)


func main(){
	f,err:=excelize.OpenFile(`org.xlsx`)
	if err!=nil {
		fmt.Println(err)
		return
	}
	for i,sheet_name:= range f.GetSheetMap() {
		fmt.Println(i,sheet_name)
		merge_cells,err:=f.GetMergeCells(sheet_name)
		if err!=nil {
			fmt.Println(err)
			return
		}

		for i:=range merge_cells {
			axis_x:=strings.Split(merge_cells[i][0],":")[0]
			axis_y:=strings.Split(merge_cells[i][0],":")[1]
			fmt.Printf("index=%d\tref=%s\tval=%s\t\tUnmergeCell(\"%s\",\"%s\",\"%s\")\t",i,merge_cells[i][0],merge_cells[i][1],sheet_name,axis_x,axis_y)
			err=f.UnmergeCell(sheet_name,axis_x,axis_y)
			if err!=nil {
				fmt.Printf("UnmergeCell fail,%v\n",err)
				return
			}else{
				fmt.Printf("OK\n")
			}
		}
	}

	err=f.SaveAs("test.xlsx")
	if err!=nil{
		fmt.Printf("SaveAs fail,%v\n",err)
		return
	}
}

待拆分合并单元格的xlsx文件。
image

org.xlsx

输出的test.xlsx文件用Excel 2013打开提示 “发现test.xlsx中的部分内容有问题”,经过测试如果保留一个合并的单元格不进行拆分,打开的文件正常。

烦请有空核查处理。

@xuri
Copy link
Member

xuri commented Feb 9, 2021

Thanks for your feedback, could you provide more details or a spreadsheet xlsx attachment (org.xlsx) without confidential info?

@blueicesir
Copy link
Author

blueicesir commented Feb 9, 2021

Thanks for your feedback, could you provide more details or a spreadsheet xlsx attachment (org.xlsx) without confidential info?

已经更新到问题单内容中,可以下载 org.xlsx 并使用代码测试。

https://github.com/360EntSecGroup-Skylar/excelize/files/5949576/org.xlsx

@xuri xuri added bug Something isn't working confirmed This issue can be reproduced labels Feb 9, 2021
@xuri xuri changed the title 把一个xlsx文件工作表中的所有合并的单元格UnmergeCell之后生成的文件打开会提示错误。 Unmerge all cells cause corrupted file Feb 9, 2021
@xuri xuri added the in progress Working in progress label Feb 9, 2021
@xuri xuri closed this as completed in 3783d1d Feb 9, 2021
@xuri
Copy link
Member

xuri commented Feb 9, 2021

Thanks for your issue, I have fixed it, please try to use the master branch code, and this patch will be released in the next version.

@xuri xuri removed confirmed This issue can be reproduced in progress Working in progress labels Feb 9, 2021
@blueicesir
Copy link
Author

Test is pass,thank you.happy Chinese New Year in 2021.

jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this issue Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants