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

Export to Excel (BIFF) from RadGrid

1 Answer 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 06 Aug 2014, 09:40 PM
My data is exporting to Excel but the problem is the appearance of the Excel column widths.  Currently, the result is the columns are very narrow and concealing some of the data.  I have looked at the RadGrid documentation and demo and tried to follow it but I haven't seen, or comprehended, what would format the Excel column widths to fit the header column titles.  I have tried scrolling through all the properties for MasterTableView, RowIndicatorColumn, and a few others but didn't seem to see anything that offered help with this issue.  Is there a setting that would 'autosize' the width of the exported columns based on the content of the data in the HeaderText so that the user doesn't have to manually expand the columns before being able to view the contents?  Thanks for any suggestions.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Aug 2014, 06:38 AM
Hi Alex,

You can set the column width on Export to Excel or you can have the columns ResizeToFit.

ASPX:
<ClientSettings>
    <Resizing AllowColumnResize="true" ResizeGridOnColumnResize="true" AllowResizeToFit="true" />
</ClientSettings>

JS:
<script type="text/javascript">
    function pageLoad() {
        var grid = $find("<%= rgrdSample.ClientID %>");
        var columns = grid.get_masterTableView().get_columns();
        for (var i = 0; i < columns.length; i++) {
            columns[i].resizeToFit();
        }
    }
</script>

OR

C#:
bool isExport = false;
void rgrdSample_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToExcelCommandName)
    {
        isExport = true;
    }
}
 
void rgrdSample_PreRender(object sender, EventArgs e)
{
    if (isExport)
    {
        foreach (GridColumn col in rgrdSample.MasterTableView.RenderColumns)
        {
            col.HeaderStyle.Width = Unit.Pixel(200);
        }
    }
}

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