Export Excel Biff and column widths

5 posts, 0 answers
  1. Aaron Gibbs
    Aaron Gibbs avatar
    23 posts
    Member since:
    Dec 2007

    Posted 17 Dec 2012 Link to this post

    I'm having a hard time getting column widths looking nice in a RadGrid Excel export to Biff format.  The grid is fairly simple, binding to a dataset with a few DataBound columns.

    With no widths set on any of the GridBoundColumns, the grid looks wonderful in HTML (widths set automatically), but the Excel export appears with very small columns (all have width set to zero).

    If I manually set widths on each of my GridBoundColumns, again it looks great in HTML but the resulting Excel export has very, very wide columns that run way off the right side of the page.  It appears this has to do with Excel measuring column widths in characters and the RadGrid of course handling column widths with pixels.  For example, if I set my GridBoundColumn.HeaderStyle.Width = 240, in the resulting Excel file I can see the column width set to 180.  Some conversion must be happening here to convert pixels to characters but it's not working right.

    Is there any way I can set the Excel columns width equal to the pixel width settings in my RadGrid?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Dec 2012 Link to this post


    Try setting the width as shown below.
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
           if (e.CommandName == RadGrid.ExportToExcelCommandName)
               foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
                   if (col.UniqueName == "Uniiquename")
                       col.HeaderStyle.Width = Unit.Pixel(240);

  3. DevCraft R3 2016 release webinar banner
  4. Bob
    Bob avatar
    123 posts
    Member since:
    Sep 2012

    Posted 15 Feb 2013 Link to this post

    An auto-resize property on radgrid for exporting would be nice...
  5. Alanna
    Alanna avatar
    1 posts
    Member since:
    Nov 2011

    Posted 25 Mar 2013 Link to this post

    I agree that an auto-resize property for the export would be amazing.

    Shinu - I have tried your suggestion and it still doesn't seem to work.  The markup for the column in particular sets a width of 300px - the actual grid itself when rendered in the browser looks perfect.  However, when exporting to excel, the column ends up about twice as wide as it needs to be.  Excel is reporting a width of 94.57.  The export seems to ignore anything I try setting it to and ALWAYS ends up giving it the same width in the final export.

    When using your suggestion, I set that column (which just contains a string, as well as all the "ExpandColumn"s) to a width of 10 and that has still made no difference at all.

    Am I missing something?  Aside from the code snippet that you posted, is there anything else that needs to be done? 

    FYI - I followed this example to export my hierarchical grid and then just added in the code you posted to deal with the column width:  Export Hierarchical Grid
  6. Kostadin
    Kostadin avatar
    1686 posts

    Posted 28 Mar 2013 Link to this post

    Hello Alanna,

    I am assuming you are using HTML format and not Biff format in your project. In this case the width you set is in your mark up is the same as the one in the exported file. The problem is that the grid column widths is different than the excel column widths. More information could be found at the following article.

    Kind regards,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
DevCraft R3 2016 release webinar banner