juavenel juavenel -4 years ago 139
C# Question

How to set the formula to the sum of a column in c# interop

How to set the formula to the sum of a column in c# interop ?

I tried

sheet.Range["O4"].Formula = string.Format("=SUM({0})", table.ListColumns["MONTANT"].DataBodyRange.Address);


But when i add a row to the table the sum is not correct, It does not take the new line.

Answer Source

When you sum a column in Excel, say, AX, you write SUM(AX:AX). Therefore, the format should be SUM({0}:{0}):

sheet.Range["O4"].Formula = string.Format("=SUM({0}:{0})", table.ListColumns["MONTANT"].DataBodyRange.Address);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download