I have a few columns with balances showing on the grid that I export to excel.
I only show the $ sign in the footer totals and the rows are displayed without the $. So my column looks like below:
<telerik:GridBoundColumn Aggregate="Sum" DataField="PlanExpense" HeaderText="Annual Plan Expense" UniqueName="PlanExpense"
DataFormatString="{0:#,##0.00;(#,##0.00)}" HeaderStyle-Width="9%" FooterAggregateFormatString="{0:c2}" />
protected void grid_ExportCellFormatting(object source, ExportCellFormattingEventArgs e)
{
if (e.FormattedColumn.ColumnType == "GridTemplateColumn")
{
GridTemplateColumn templateCol = (GridTemplateColumn)e.FormattedColumn;
if (templateCol.DataTypeName == "System.Decimal" || templateCol.DataTypeName == "System.Double")
{
e.Cell.Style["mso-number-format"] = "$#,##0.00;($#,##0.00)";
}
}
if (e.FormattedColumn.ColumnType == "GridBoundColumn")
{
GridBoundColumn boundCol = (GridBoundColumn)e.FormattedColumn;
if (boundCol.DataFormatString.ToLower().Contains("0:c") || boundCol.DataFormatString.ToLower().Contains("$"))
{
//e.Cell.Style["mso-number-format"] = "$#,##0.00;($#,##0.00)";
e.Cell.Style["mso-number-format"] = "-$* #,##0.00_-;$* (#,##0.00-);_-$* \" - \"??_-;_-@_-";
}
else if (boundCol.DataFormatString.ToLower().Contains("%"))
{
e.Cell.Style["mso-number-format"] = "0.##%;(0.##%)";
}
else if (boundCol.DataFormatString.ToLower().Contains("0:#,##0.00"))
{
e.Cell.Style["mso-number-format"] = "0:#,##0.00;(#,##0.00)";
}
else if (boundCol.DataFormatString.Contains("{0:P}"))
{
e.Cell.Style["mso-number-format"] = @"Percent";
}
else if (boundCol.DataFormatString.Contains("{0:#,##0;(#,##0)}"))
{
e.Cell.Style["mso-number-format"] = "$#,##0;($#,##0)";
}
}
}
I specify formatting in the exportcellformatting event as shown above, but it seems that is only applicable to the data rows and not the footer. Currently excel displays a negative currency in red parenthesis and I do not want to show the negative in red, only in parentheses.
Is there a way I can format the footer to do that?