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

Option for CellSetterArrayValueSpecial to fill down formulas alongside it #40

Open
chris114782 opened this issue Apr 12, 2023 · 2 comments

Comments

@chris114782
Copy link

If I have a table like so:
image

And it is filled using the CellSetterArrayValueSpecial setter, I would like it to carry the formula down with the rows too.

Currently you end up with:

image

Which is not great as the formula is then not used.

I was wondering if it was possible to do this using callbacks on say Threshold but it would need to know how many rows to fill it down and I can't see how to get that in the params.

Any suggestions

@chris114782
Copy link
Author

chris114782 commented Apr 12, 2023

I am aware I could just set the formula in code, but these templates are to be edited by non developers and I'd like to leave as much excel functionality intact as possible, without having to update the code every time a new template is built.

@alhimik1986
Copy link
Owner

alhimik1986 commented Apr 12, 2023

Well, you are passing an array to the CellSetter. To find out how many rows to fill, you simply pass the size of this array to the callback function. This will be the number of rows to fill (or maybe number of rows minus one).

If the formula will be edited you can try some solution:
insert a template variable with name like {cell_E2_formula} in D2 cell so the cell could be cloneable. And then add some formula to E2 cell. After that copy the formula from cell E2 using event PhpExcelTemplator::BEFORE_INSERT_PARAMS. And then you need to somehow copy the formula so that there is a relative shift of the cells along the rows (using CellSetter callback). I hope the PHPSpreadsheet could make this.

I'm not sure this will work. It has not been tested. But that's all I can help without modifying the code to solve the problem quickly.

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