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

Feature-request for batch merging cells #1221

Closed
leafspace opened this issue May 6, 2022 · 6 comments
Closed

Feature-request for batch merging cells #1221

leafspace opened this issue May 6, 2022 · 6 comments

Comments

@leafspace
Copy link

性能说明:https://xuri.me/wp-content/uploads/2016/08/excelize-performance.svg?t=20220502中描述MergeCell的耗时为0.018
我这边在V2.6.0版本上实测两个单元格合并单次调用的确耗时很低,在0.001左右。
但是我们这边有个处理要求合并多个单元格。数量级在 8000行40列0.001S中
实测发现随着调用次数增多,单次调用耗时会有比较大的出入,我观察到最多可能会到0.008S左右。
整体全部跑下来,执行时间大约在1000S左右。

我在merge.go中另外写了一个批量处理MergeCell的func,耗时降到了12S

`
func (f *File) MergeCellUnSetStyle(sheet string, hCells, vCells []string) error {
ws, err := f.workSheetReader(sheet)
if err != nil {
return err
}

if len(hCells) != len(vCells) {
return newerr
}

for i := 0; i < len(hCells); i++ {
hCell := hCells[i]
vCell := vCells[i]

rect, err := areaRefToCoordinates(hCell + ":" + vCell)
if err != nil {
return err
}
// Correct the coordinate area, such correct C1:B3 to B1:C3.
// _ = sortCoordinates(rect)

//hCell, _ = CoordinatesToCellName(rect[0], rect[1])
//vCell, _ = CoordinatesToCellName(rect[2], rect[3])

ref := hCell + ":" + vCell
if ws.MergeCells != nil {
ws.MergeCells.Cells = append(ws.MergeCells.Cells, &xlsxMergeCell{Ref: ref, rect: rect})
} else {
ws.MergeCells = &xlsxMergeCells{Cells: []*xlsxMergeCell{{Ref: ref, rect: rect}}}
}
}
ws.MergeCells.Count = len(ws.MergeCells.Cells)
return nil
}
`

测试文件请查收附件,很抱歉无法提供带有数据的表格,附件为处理完毕的表格。
Hello 2022-05-06 08-40-09.xlsx

@xuri
Copy link
Member

xuri commented May 6, 2022

Thanks for your feedback. The performance data is generated by this benchmark testing script, and I've test it works well. Can you show us a complete, standalone example program or reproducible demo?

@xuri xuri added the needs more info This issue can't reproduce, need more info label May 6, 2022
@leafspace
Copy link
Author

e , please use this test demo

MergeCell Test.zip

@xuri
Copy link
Member

xuri commented May 8, 2022

There is no obvious improvements in the time cost of the two programs in the attachment, and it takes about 1s to merge 400,000 cells not as you above mentation 1000s.

@leafspace
Copy link
Author

400,000 cells on your machine as long as 1S?
But on my side 10000 pieces cost 32S
动画

@xuri
Copy link
Member

xuri commented May 8, 2022

Please upgrade to the master branch code. Commit eed431e improve performance for set sheet row and the merging cells, fix performance impact when resolving #1129.

@leafspace
Copy link
Author

think you, when i use this commit fix this problem

@xuri xuri changed the title 希望提供单个Sheet内批量MergeCell的功能 Feature-request for batch merging cells May 18, 2022
@xuri xuri removed the needs more info This issue can't reproduce, need more info label May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants