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

When the contents of ExcelTable are referenced, Contiguous cell Range assignment formulas cannot be used #1642

Open
minren118 opened this issue Oct 21, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@minren118
Copy link

minren118 commented Oct 21, 2024

EPPlus usage

Noncommercial use

Environment

Windows

Epplus version

7.4

Spreadsheet application

Excel365

Description

When a user references ExcelTable's formulas in cells other than ExcelTable, using structured reference (#This Row), an error occurs when multiple cell formulas are assigned to Contiguous cell range at once

If you don't use the continuous range assignment formula, the relative and absolute references to the formula will be very difficult to handle, and I think this should be a bug to deal with.

image

                var worksheet = package.Workbook.Worksheets["Sheet1"];
                var excelTable = worksheet.Tables[0];
[testExcelTable.xlsx](https://github.com/user-attachments/files/17452770/testExcelTable.xlsx)

                var col = excelTable.Range.Offset(0,10).TakeSingleColumn(0).SkipRows(1);
                var formulaStr = col.TakeSingleCell(0, 0).Formula;
                col.Formula = formulaStr;

testExcelTable.xlsx

@minren118 minren118 added the bug Something isn't working label Oct 21, 2024
@JanKallman
Copy link
Contributor

These are array formulas. Use the CreateArrayFormula(formulaStr, true); for each cell when copying this.
We will look at adding better support for this in a coming version.

@minren118
Copy link
Author

minren118 commented Oct 22, 2024

It is not an array formula, I just need to copy the formula of the connected area according to the formula of the first cell, similar to the effect of VBA interface Fill Down, in EPPLUS, if there is no structured reference to ExcelTable, you can select a continuous area and then assign the formula value to it. The relative and absolute reference of formulas are processed automatically.

As shown in the image below, what I ultimately need is that after the formula is assigned to the selected continuous region, the content of the formula is different, if it is an array formula the content of the formula is the same.

image

image

If the formula is the following way, it is normal
image

@JanKallman
Copy link
Contributor

Excel will create this formula as an array formula...

<c r="K2" cm="1">
<f t="array" ref="K2">表1[[#This Row],[列5]]+M2</f>
<v>2</v>
</c>

If it's not an array formula, you can set it as usual with the Formula property

@minren118
Copy link
Author

Finally, I can only use this copy method to go through all the cells to achieve this, but I don't know how the performance is?

image

                    var sht = package.Workbook.Worksheets["Sheet1"];
                    var srcCell= sht.Cells["K2"];
                    var fillRange = sht.Cells["K3:K5"];
                    for (int i = 0; i < 3; i++)
                    {
                        var dstCell = srcCell.Offset(i + 1, 0);
                        srcCell.Copy(dstCell);  
                    }

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

3 participants
@JanKallman @minren118 and others