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
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
I cannot say that I agree on that
There is a property in the UltraWInGrid.ExcelExport object called "ExportFormattingOptions", and before one of your colleagues ( Michael DiFilippo) helped me with finding that one, everything in the Excel file was changed (Forecolor, Background color) when the export was made. But when setting that property to None, ForeColors, BackgroundColors, Fonts etc. were not changed. The width of the columns should be included in that scope if you ask me.
Anyway, if you say that this cannot be done in any other way, it is a bit sad, since we loose all kinds of dynamics in terms of Excel files that can be opened and exported to. We can never now which template the user wants to export to.
Any other ideas?