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,
I'm glad that you found my suggestion helpful.
Thank you for choosing Infragistics!
Regards,Ivan Kitanov
Thank you, it works fine.
If you only want to export the grid data from specific rowIndex and colIndex, then I believe that the Excel Engine would be a better option than the UltraGridExcelExporter. With it you would be able to load the specific template file and preserve its format as well as entering the data from the grid in the cells of the template file.
I am attaching a small sample that demonstrates what I have explained above, for template I am using an excel file with specified widths of the columns as well as a background color for the headers. When the user presses the “Load Excel File and Export Specific Data” button the template file is loaded by the Excel Engine, the required data is written and then the file is saved under a different name in order to compare if the formatting of the file is preserved successfully. Along with the sample I am attaching the “template” that I have used as well as the resulting excel file.
Please test the sample on your side and let me know if you have any questions or converns.
Regards, Ivan Kitanov
ExportGridWithMultipleRows.zip
Hello Ivan! It is true what you say and I understand it completely.
The problem is that we don't want the excel file to be specified in terms of columns widths from the very beginning, meaning that when we click the export button, we dont know the layout of the file. We just know which rowIndex and colIndex that the export function should start at.
But in terms of functionality, it seems that the export function will change the excel column swidth meaning that we will have to do some sort of mapping in-between. I hope we can manage to fix something here.
Thanks
By design the UltraGridExcelExporter exports the data based how the grid looks and tries to replicate its layout in the excel file, having this in mind it doesn’t matter how the file has been formatted previously, since the UltraGridExcelExporter would override it.
Could you please provide some more information on the template excel files you are using?
For example, the way I understand it is as follows: If you have a grid with 4 columns – A, B, C and D and all of them have width of 100, and you want a template with columns such as A (width 75), B (width 150) and D (width 200). This template could be achieved by setting the widths of the columns the way I suggested in my previous reply and then hiding the column C.
Additionally if you would like to load an excel file and keep its formatting and only modifying the cells of the WorkSheet with the data that comes from the grid I suggest you reviewing our Excel Engine.