How to remove extra string when Exporting to Excel

2 posts, 0 answers
  1. Raymond
    Raymond avatar
    1 posts
    Member since:
    Aug 2013

    Posted 07 Aug 2013 Link to this post

    I have a very basic code that Export data from a GridView using Visual Basic. The problem I am encountering is the Excel file contains many extra space strings
    For example instead '123', it is '123          '

    Is there anyway to get rid of these extra strings?

  2. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 12 Aug 2013 Link to this post

    Hi Raymond,

    Thank you for writing.

    A suitable event for customizing the value of the exported cells is the ExcelCellFormatting event. Here is an example:
    void exporter_ExcelCellFormatting(object sender, Telerik.WinControls.UI.Export.ExcelML.ExcelCellFormattingEventArgs e)
    {
        if (e.ExcelCellElement.Data.DataItem is string)
        {
            e.ExcelCellElement.Data.DataItem = e.ExcelCellElement.Data.DataItem.ToString().TrimEnd(' ');
        }
    }

    I hope this helps.
     
    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top