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
tnx mate. Did the same on our end.
Example Code:
/// <summary> /// Allows to exclude field from Export /// Credit goes to http://es.infragistics.com/community/forums/p/34093/499958.aspx#499958 /// </summary> public class ExcludeFromExportProperty : DependencyObject { public static readonly DependencyProperty ExcludeProperty = DependencyProperty.RegisterAttached("Exclude", typeof(bool), typeof(ExcludeFromExportProperty), new PropertyMetadata(false));
public static bool GetExclude(DependencyObject d) { return (bool)d.GetValue(ExcludeProperty); } public static void SetExclude(DependencyObject d, bool value) { d.SetValue(ExcludeProperty, value); } }
and then in our InfragisticsFacade class we have this piece of Code to hide it:
for (var i = 0; i < e.DataPresenter.FieldLayouts[0].Fields.Count; i++) { var field = e.DataPresenter.FieldLayouts[0].Fields[i]; var excluded = ExcludeFromExportProperty.GetExclude(field);
if (excluded) { field.Visibility = Visibility.Collapsed; }
}
Anvarbek,
it's just a simple attached property of boolean type. You then set it to true in xaml for Field that you don't want to export. Later in ExportStarted event handler you set Visibility to Collapsed for all fields that have it set to true.
Anton,
Can you pls post your attached Property so that we can reuse on our end as well pls?
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.
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.