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
2005
Fixed columns and rows to be exported into Excel freeze panes
posted

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

Parents
No Data
Reply
  • 2005
    Verified Answer
    Offline posted

    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);
    }

    Best Regards,
    Shaolin

Children