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

Is there support relative formula update in duplicate row function #1306

Closed
bailantaotao opened this issue Aug 5, 2022 · 5 comments
Closed
Labels
enhancement New feature or request
Projects

Comments

@bailantaotao
Copy link
Contributor

Hi,

I wonder to know the feature is supported currently?

In my imagine like below

  1. C1 = A1+B1
  2. call duplicate row 1
  3. C2 = A2+B2

but in library actually

  1. C1 = A1+B1
  2. call duplicate row 1
  3. C2 = A1+B1

I have try to find any documents but no answer in library.

@bailantaotao bailantaotao changed the title Is there support relative formula in duplicate row function Is there support relative formula update in duplicate row function Aug 5, 2022
@xuri
Copy link
Member

xuri commented Aug 5, 2022

Thanks for your issue. This library doesn't support this feature currently. I'll consider adding support for it later.

@xuri xuri added the enhancement New feature or request label Aug 5, 2022
@bailantaotao
Copy link
Contributor Author

thank you sir~

@ljyf5593
Copy link

ljyf5593 commented Apr 4, 2023

same feature need, thank you !

@ljyf5593
Copy link

ljyf5593 commented Apr 10, 2023

I write this utils funtion can support this feature

func parseFormula(formula string, sourceRowID, targetRowID int) (newFormula string) {
	reg := regexp.MustCompile(fmt.Sprintf("([A-Z]{1,2}%d)", sourceRowID))
	cellSlice := reg.FindAllString(formula, -1)
	newFormula = formula
	for _, cell := range cellSlice {
		col, _, err := excelize.SplitCellName(cell)
		if err != nil {
			log.Fatalln(err)
		}
		targetCell, err := excelize.JoinCellName(col, targetRowID)
		if err != nil {
			log.Fatalln(err)
		}
		newFormula = strings.ReplaceAll(newFormula, cell, targetCell)
	}
	return
}

call like this parseFormula("A1 + B1", 1, 2)

@xuri xuri added the in progress Working in progress label Oct 23, 2023
@xuri xuri added this to Features in v2.8.1 Oct 23, 2023
xuri added a commit to TeeRenJing/excelize that referenced this issue Oct 23, 2023
- Support adjust formula on inserting/deleting columns/rows
xuri added a commit to TeeRenJing/excelize that referenced this issue Oct 23, 2023
- Support adjust formula on inserting/deleting columns/rows
@xuri xuri closed this as completed in a8cbcfa Oct 23, 2023
@xuri xuri removed the in progress Working in progress label Oct 23, 2023
@xuri
Copy link
Member

xuri commented Oct 24, 2023

Hi @bailantaotao, @ljyf5593, this library now support this feature, please upgrade to the master branch code, and this feature 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
enhancement New feature or request
Projects
No open projects
v2.8.1
Features
Development

No branches or pull requests

3 participants