我正在使用 aspose excel 导出。我正在.net中设置公式。
我想要第三个单元格中两个单元格值的总和。像
excelbook.Worksheets[0].Cells["A2"].R1C1Formula = "=SUM(R1C1,R1C2)";
但我想动态设置该列。与上面的公式一样,C1、C2 列是固定的。
现在我想动态选择列名称,我想构建如下所示的公式
excelbook.Worksheets[0].Cells["A2"].R1C1Formula = "=SUM(R1C(单元格 B1 的值),R1C(单元格的值) B2))”;
因此,如果我在 B1 单元格中输入 1,在 B2 单元格中输入 3,那么它应该对 A1 和 C1 求和。我可以在 B1 和 B2 单元格中输入任何值,Excel 应该根据输入的值计算总和。
请建议如何构建此类公式。
直接在Excel中,我们可以通过这种方式做到:-
=INDIRECT(B1&1)+INDIRECT(B2&1)
所以请建议我可以在r1c1公式中使用INDIRECT或建议其他方式。
I am use aspose excel export. I am setting formulla in .net.
I want sum of two cells value in third cell. like
excelbook.Worksheets[0].Cells["A2"].R1C1Formula = "=SUM(R1C1,R1C2)";
but i want to set the column dynamically. like in above formulla column C1,C2 are fixed.
now i want pick the column name dynamically , i want to build my formulla like below
excelbook.Worksheets[0].Cells["A2"].R1C1Formula = "=SUM(R1C(Value of Cell B1),R1C(Value of Cell B2))";
so if i enter 1 in B1 cell and 3 in B2 cell then it should sum A1 and C1.i can enter any value in B1 and B2 cell and excel should calculate the sum based upon entered values.
Please suggest how to build this type of formulla.
directly in excel we can do by this way:-
=INDIRECT(B1&1)+INDIRECT(B2&1)
so please suggest can i use INDIRECT in r1c1 formulla or suggest some other way.
发布评论
评论(1)
如果您想在 Excel 中添加 D1 和 E1,但您想根据特定单元格的值选择行;例如,在本例中,您可能使用 A1 和 A2 来放置要选择的行的值,然后您将使用如下公式:
=SUM(INDIRECT("D"&$A$1),INDIRECT(" E"&$A$2))
您可以使用 Aspose.Cells for .NET 也是如此。请参阅以下代码:
请在最后使用 最新版本的 Aspose.Cells for .NET。如果您认为这没有帮助或者我无法清楚地理解您的问题,请分享您进一步的想法。
披露:我在 Aspose 担任开发人员传播者。
If you want to add D1 and E1 in Excel but you want to select the row based on the value of the particular cell; for example, in this case, you might use A1 and A2 to place the value of the row to select, then you will use the formula like this:
=SUM(INDIRECT("D"&$A$1),INDIRECT("E"&$A$2))
You can assign the same formula using Aspose.Cells for .NET as well. Please see the following code:
Please try it at your end using the latest version of the Aspose.Cells for .NET. If you think it doesn't help or I'm unable to understand your question clearly then please share your further thoughts.
Disclosure: I work as a developer evangelist at Aspose.