Hi,
I have an UltraGrid with fixed rows on the top and fixed columns on the left. When data are exported to Excel, I would like to freeze the header row and fixed rows on top of Excel and the fixed columns on the left. I also need to set the bottom border of last frozen row and the right border of the last frozen column to be thick.
Your help is greatly appreciated!
Best Regards,Shaolin
Exporting data from UltraGrid to Excel does support freezing columns and rows. Here is the code snippet:
using (var excelExporter = new UltraGridExcelExporter()) { excelExporter.ExportStarted += (sender, eventArgs) => { ... }; excelExporter.RowExporting += (sender, eventArgs) => { ... }; excelExporter.InitializeColumn += (sender, eventArgs) => { ... }; Workbook workbook = excelExporter.Export(GridControl, filePath, WorkbookFormat.Excel2007); Worksheet worksheet = workbook.Worksheets[0]; worksheet.DisplayOptions.PanesAreFrozen = true; int frozenRows = 3; // your logic to count fixed rows plus header int frozenColumns = 3; // your logic to count fixed columns worksheet.DisplayOptions.FrozenPaneSettings.FrozenRows = frozenRows; worksheet.DisplayOptions.FrozenPaneSettings.FrozenColumns = frozenColumns; workbook.Save(filePath); }
Shaolin,
You are right, and I misspoke. Freezing panes is possible to do through the Infragistics ExcelEngine, and the UltraGridExcelExporter will honor that in the Excel file that it saves. However, the UltraGrid does not automatically send the exporter which columns/rows are fixed, and consequently where the ExcelEngine will freeze the pane. This last step is what I meant would have to be handled through code.
I've been working on a sample which demonstrates how one would handle this through code, and have attached it below. Please take a look if you need more info about how to freeze the correct columns/rows in the ExcelEngine.
Please let me know if I can assist you further.