Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2745
Export to excel changes column width
posted

Hello!

I am using the latest version of the components (2021.2) and when I am exporting to Excel from an UltraGrid (WinForms) via the UltraGridExcelExporter, the column widths in the Excel file are changed.

My exportformattingoptions are set to none, and I am exporting to an existing excel file with already set column widths that we don't want to change.

Can you advice?

/Henrik

Parents
No Data
Reply
  • 1700
    Offline posted

    Hello Henrik,

     

    The reason why the styling of the exported excel file is different is because, when exporting the UltraGridExcelExporter uses a copy of the layout of the grid, meaning that any changes done to this layout would be applied on the exported file, but not on the grid in the application. The copy of the layout is then used for the exporting and overrides the file that you are exporting it to. The easiest solution that I can think of is using the BeginExport event and setting the desired width of the columns there. The code below demonstrates the use of the event and changes the width of the first column in the exported excel file.

     

    private void UltraGridExcelExporter1_BeginExport(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.BeginExportEventArgs e)
            {
                e.Layout.Bands[0].Columns[0].Width = 200;
            }
     

    Please let me know if you have any questions.

     

    Regards,
    Ivan Kitanov

Children