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

Merged cols and rows #1018

Closed
geoirb opened this issue Sep 12, 2021 · 3 comments
Closed

Merged cols and rows #1018

geoirb opened this issue Sep 12, 2021 · 3 comments

Comments

@geoirb
Copy link

geoirb commented Sep 12, 2021

Description

In my task i needed know how many rows and cols merge with cell and i wrote function for get this information

I propose to add this function to the main repository

// GetMergeCells provides a function to get the number of merged rows and columns by axis cell
// from a worksheet currently.
func (f *File) GetNumMergeCell(sheet string, axis string) (colNum int, rowNum int, err error) {
	ws, err := f.workSheetReader(sheet)
	if err != nil {
		return
	}

	if ws.MergeCells != nil {
		for i := range ws.MergeCells.Cells {
			ref := ws.MergeCells.Cells[i].Ref
			cells := strings.Split(ref, ":")
			if cells[0] == axis {
				col1, row1, _ := CellNameToCoordinates(cells[0])
				col2, row2, _ := CellNameToCoordinates(cells[1])
				colNum, rowNum = col2-col1+1, row2-row1+1
				return
			}
		}
	}
	colNum = 1
	rowNum = 1
	return
}

I wrote test for this function

@xuri
Copy link
Member

xuri commented Sep 13, 2021

Thanks for your issue, following the minimum usable design principle, I don't suggest adding a new API into the base library if developers could be easy to implement any feature by the wrapper or composite the existing APIs. You can get the merged cells to range by GetMergeCells and parse the column and rows base on it.

@geoirb
Copy link
Author

geoirb commented Sep 13, 2021

@xuri algorithm complexity my function is O(n), algorithm proposed method is O(n^2), and in the lib code i saw a violation the minimum usable

@xuri
Copy link
Member

xuri commented Jul 3, 2023

The issues #1382 and #1448 was similar with this, the performance of the GetMergeCells function has been improvement by #1500, and this optimization has been released in the version 2.7.1. Please upgrade to the latest version. I've closed this issue, if you have any question, please let me know, and you can reopen this anytime.

@xuri xuri closed this as completed Jul 3, 2023
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