Problem with 'Sum' operation after setting the cell format



I am using this custom pattern "$#,##0.00" to display negative currency in the following format, -$670.90. I am able to get it in the exported excel. But after exporting when I try to do a sumation, avarage, min etc on the cells of the column, the result is displayed in the pattern ($670.90), but it must be displayed in the former pattern. How can I get this? The pattern of the summation result must be similar to the pattern of the values in each cell of the column.




It seems that the sum cell's number format is different with data cells. Please set it same as other cells.


cells["A1"].Style.Custom = "$#,##0.00";


cells["A2"].Style.Custom = "$#,##0.00";

cells["A3"].Formula = "=SUM(A1:A2)";

cells["A3"].Style.Custom = "$#,##0.00";


I am not doing the SUM operation by code. The user does it maually by selecting the columns in the excel and choosing the function from the menu, How do I set the same custom pattern in this case?


You cannot control manual action in MS Excel. That sum cell must have different number format. You can tell the user to change the format in MS Excel.