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
1320
Exporting an UltraGrid with an UltraGridExcelExporter
posted

Hello Everybody!

In a project I have an UltraGrid with an UltraDataSource and an UltraGridExcelExporter.
The export of the whole grid is working fine with the UltraGridExcelExporter and I can see all UltraGrid rows and columns later in Excel.
I need to hide some columns during the exporting process, so that this columns are not exported to the excel sheet anymore.

I have tried two approaches:

1) With the ExportStarted event of the UltraGridExcelExporter control

ExportStarted( object sender, Infragistics.Win.UltraWinGrid.ExcelExport.ExportStartedEventArgs e )
Workbook hWorkbook = e.Workbook;
if( hWorkbook != null )
   {
   Worksheet hWorksheet = hWorkbook.WindowOptions.SelectedWorksheet;
   if( hWorksheet != null
     {
     hWorksheet.HideColumns( 0, null );
     }
   }

But does not suppress the column with the index 0 in the excel sheet.
It looks like that the Worksheet is only prepared and not filled in with any data at this event.

2) With the InitializeColumn event of the UltraGridExcelExporter control

InitializeColumn( object sender, Infragistics.Win.UltraWinGrid.ExcelExport.InitializeColumnEventArgs e )
UltraGridColumn hCol = e.Column;
if( hCol.Key == "Column0" )
  {
  hCol.Hidden = true;
  }

This does also not hide the column with index 0 in the excel sheet.
Has anybody an idea how a suppressing of one or more columns during the excel export can be achieved?
Thank you for any help!

Best regards
Frank

Parents
  • 23930
    Verified Answer
    Offline posted

    Hi Frank,

    Thank you for posting to our forums.

    You can use the ExportStarted event to hide the column. The event’s arguments have a copy of the grid layout which is used for the exporting. You can use it to hide the column you want and it won’t appear in the exported worksheet:

     private void ultraGridExcelExporter1_ExportStarted(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.ExportStartedEventArgs e)

            {

                e.Layout.Bands[0].Columns["Column0"].Hidden = true;

            }

    I have attached a sample that demonstrates this approach.

    Please let me know if you have any additional questions.

    WG_PreventColumnFromExporting.zip
Reply Children
No Data