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

Auto-Fit column width when exporting to excel using Format="Xlsx"

1 Answer 1773 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jlj30
Top achievements
Rank 2
jlj30 asked on 16 May 2016, 03:45 PM

Hi,

I'm making some progress formatting the header row of my Excel export, but I'd really like to have the columns automatically adjust to fit the width of the content.

Here's my OnInfrastructureExporting event handler:

protected void grdControls_InfrastructureExporting(object sender, GridInfrastructureExportingEventArgs e)
{
    var colCount = e.ExportStructure.Tables[0].Columns.Count;
    // Set the header style for all columns
    ExportStyle headerStyle = new ExportStyle();
    headerStyle.ForeColor = Color.White;
    headerStyle.BackColor = Color.Blue;
    headerStyle.Font.Bold = true;
 
    for (var i = 1; i <= colCount; i++)
    {
        e.ExportStructure.Tables[0].Cells[i, 1].Style = headerStyle;
        e.ExportStructure.Tables[0].Columns[i].Width = 200; // Would like auto-width !!
    }
}

 

I've seen similar threads but they are related to export formats other than Xlsx.

Any idea how I can accomplish auto-fit using the above handler?  Or do I need to do that elsewhere?

Thanks for any advice.

Jim

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 19 May 2016, 10:37 AM
Hello Jim,

Thank you for contacting us.

I am afraid there isn't an auto fit function when using the binary export formats(Biff and Xlsx). This feature is supported if you are using the other export formats. Nevertheless, I would recommend you to create a new feature request in our Ideas&Feedback portal and vote for it. Our developers will make a research and will try to implement in some of our future releases.

I hope this information helps.

Regards,
Kostadin
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
jlj30
Top achievements
Rank 2
Answers by
Kostadin
Telerik team
Share this question
or