This is a migrated thread and some comments may be shown as answers.

Replace text in excel footer when exporting

1 Answer 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leon
Top achievements
Rank 1
Leon asked on 17 Jan 2014, 11:43 AM
Hi.

I am trying to replace specific characters when exporting to excel as it doesn't recognise the contents as numeric data when I do not.  I have managed to get it working for the normal cells but it I cannot seem to get it working for the footers.

Please find my code snippet below, and advise on any possible ways to do this.

Protected Sub grdSingleCurrency_ExportCellFormatting(sender As Object, e As ExportCellFormattingEventArgs) Handles grdSingleCurrency.ExportCellFormatting, grdHoldingsSummary.ExportCellFormatting,
grdMultiCash.ExportCellFormatting, grdMultiCurrency.ExportCellFormatting, grdSingleCash.ExportCellFormatting
    
    If (Not String.IsNullOrWhiteSpace(e.Cell.Text)) Then
        e.Cell.Text = e.Cell.Text.Replace(",", String.Empty).Replace(" ", String.Empty)
    End If
 
    If (Not String.IsNullOrWhiteSpace(e.FormattedColumn.FooterText)) Then
        e.FormattedColumn.FooterText.Replace(",", String.Empty)
    End If
 
End Sub

On to the second issue, how/where can I do the same as the above, but for csv export?  As there isn't a csvExportFormatting event.

Any and all help will be greatly appreciated.

Kind regards.
Leon Havenga

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 18 Jan 2014, 04:55 AM
Hi Leon,

You can use the PreRender event to format the cells, please try the following code snippet:

VB:
Private isExport As Boolean = False
Private isCSVExport As Boolean = False
 
Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs)
    If e.CommandName = RadGrid.ExportToExcelCommandName Then
        isExport = True
    ElseIf e.CommandName = RadGrid.ExportToCsvCommandName Then
        isCSVExport = True
    End If
End Sub
 
Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
    If isExport OrElse isCSVExport Then
 
        Dim footer As GridFooterItem = TryCast(RadGrid1.MasterTableView.GetItems(GridItemType.Footer)(0), GridFooterItem)
        For Each col As GridColumn In RadGrid1.Columns
            footer(col.UniqueName).Text = footer(col.UniqueName).Text.Replace(":", String.Empty)
            For Each item As GridDataItem In RadGrid1.MasterTableView.Items
                item(col.UniqueName).Text = item(col.UniqueName).Text.Replace(",", String.Empty).Replace(" ", String.Empty)
            Next
        Next
    End If
End Sub

Thanks,
Princy
Tags
Grid
Asked by
Leon
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or