Export to Excel - exclude a column when exporting

Answered (Not Verified) This post has 0 verified answers | 9 Replies | 5 Followers Thread's RSS feed.

JoeBlack02
Points 560
Replied On: Wed, Nov 4 2009 2:13 AM Reply

Hi,

I'm using IG 9.2's support for export to Excel. I would like to exclude a couple of columns from being exported to Excel. Can you let me know how that  could be done?

Thanks,

Joe

  • Post Points: 20

All Replies

Replied On: Wed, Nov 4 2009 3:28 AM Reply

Hello Joe,

The easiest way I found is to register for the EndExport event and simply manipulate the Excel Workbook form there. E.g:

e.Workbook.Worksheets[0].Columns[0].Hidden =

true;

Hope this helps.

Sincerely,

Petar Monov,

DS Engineer,

Infragistics Bulgaria

 

Sincerely,
Petar, MCTS
Software Developer 
Infragistics
www.infragistics.com\support

  • Post Points: 20
JoeBlack02
Points 560
Replied On: Wed, Nov 4 2009 4:14 AM Reply

Thanks Petar but this may not work for me as the column still exists in the Excel. My users need the excel to feed into another system or save as csv where this column would still show.

When handling the InitializeRecord event the InitializeRecordEventArgs has a SkipRecord property. Isnt there something similar for columns ?

 

Thanks,

Joe

  • Post Points: 20
Answered (Not Verified) Replied On: Wed, Nov 4 2009 6:04 AM Reply

Hi Joe,

In that case you can register for the HeaderLabelExporting and CellExporting events and use something like this to prevent the exporting:

            if (e.CurrentColumnIndex == 1)

            {

                e.Cancel = true;

            }

Regards Petar.

Sincerely,
Petar, MCTS
Software Developer 
Infragistics
www.infragistics.com\support

  • Post Points: 35
JoeBlack02
Points 560
Replied On: Thu, Nov 5 2009 12:17 AM Reply

Thanks Petar. This way the label and the column data doesn't get exported but I still have the problem that there is an empty column in the exported Excel. Saving the file to csv for eg will add a redundant comma to the csv for the empty column.

For now I've worked around by:

*  removing the concrened columns fromthe layout (setting field.Visibility = Visibility.Collapsed)

* Exporting

* setting visibility back to Visible

Would it be possible for you to raise this as a request for a future release? Similar to how you have SkipRecord

Thanks,

Joe

  • Post Points: 20
nmuthu
Points 955
Replied On: Fri, Jun 18 2010 5:06 PM Reply

Hi,

We are using 2009.2. and would like to know if customizing Excel Export to "exclude" columns is available in this or any future version. Meaning, out of 5 columns displayed in the grid we would like to export only 3 columns.

Or is it possible to put in a feature request to facilitate the same.

Thanks in advance.

Muthu

  • Post Points: 5
nmuthu
Points 955
Replied On: Tue, Jun 22 2010 11:01 AM Reply

Any comments? Thanks.

  • Post Points: 5
Anton Golovanov
Points 490
Replied On: Mon, Feb 9 2015 9:19 AM Reply

Hi,

was this enhanced somehow in last 5 years? I'm using version 2013.2 and it seems like even hiding column in the resulting worksheet doesn't work.

  • Post Points: 20
[Infragistics]Stefan
Points 136,338
Infragistics Employee
Answered (Not Verified) Replied On: Wed, Feb 11 2015 3:19 AM Reply
Suggested by Anton Golovanov

Hello Anton,

 

Thank you for your post. I have been looking into it and I can suggest you handle the DataPresenterExcelExporter’s ExportSatrted event. This event will pass you a clone of the XamDataGrid. Which is used for the exporting. Since it's a clone, you can make changes to this layout and it will not affect the on-screen grid, only the export. So you can hide fields or layouts, change colors, or anything else you like. I also created sample project for you showing this approach. Please let me know if this helps you or you have further questions on this matter.

 

Looking forward for your reply.

Sincerely,
Stefan, MCPD
Developer Support Engineer
Infragistics, Inc.
www.infragistics.com/support

  • Post Points: 20
Anton Golovanov
Points 490
Replied On: Wed, Feb 11 2015 5:40 AM Reply

Thanks, Stefan! That is exactly what I was looking for. I've extended your solution by creating attached property ExcludeFromExport for the Field, so now I'm not dependent on field names and I can mark fields to exclude from export directly in xaml.

  • Post Points: 5
Page 1 of 1 (10 items) | RSS