We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Exporting filter on sfdatagrid filtered columns into Excel

Thread ID:

Created:

Updated:

Platform:

Replies:

121955 Feb 11,2016 12:32 PM UTC Feb 12,2016 11:47 AM UTC WPF 5
loading
Tags: SfDataGrid
Anas El Hallabi
Asked On February 11, 2016 12:32 PM UTC

Hello,
Is there a way to export the filter of a filtered sfdatagrid columns into excel ? what we would like to have is from the following sfdatagrid:


the following exported excel sheet with the filters on the header column cells:

is it possible ?
Thank you for your support.
Anas


Sivakumar R [Syncfusion]
Replied On February 11, 2016 03:35 PM UTC

Hi Anas,

This can be achieved by enabling filter for the exported range in sheet. Refer the below code highlighted code,

var exportingOptions = new ExcelExportingOptions();

var excelEngine = dataGrid.ExportToExcel(dataGrid.View, exportingOptions);

var workBook = excelEngine.Excel.Workbooks[0];

workBook.Worksheets[0].AutoFilters.FilterRange = workBook.Worksheets[0].UsedRange;
workBook.SaveAs("sample.xlsx");


Thanks,
Sivakumar

Anas El Hallabi
Replied On February 11, 2016 03:58 PM UTC

Hi Sivakumar,

Thank you for your rapid answer.
If we use the UsedRange, we indeed have the filter for each excel column.
Now, if we have stacked header rows, is there a way to display the filters on the underneath columns not on the stacked Header itself ?

Regards,
Anas


Sivakumar R [Syncfusion]
Replied On February 11, 2016 04:24 PM UTC

Hi Anas,

Find the code snippet to enable filter based on stacked header rows.

var exportingOptions = new ExcelExportingOptions();

var excelEngine = dataGrid.ExportToExcel(dataGrid.View, options);

var workBook = excelEngine.Excel.Workbooks[0];

var worksheet = excelEngine.Excel.Workbooks[0].Worksheets[0];

var range = "A" + (dataGrid.StackedHeaderRows.Count + 1).ToString() + ":" + worksheet.UsedRange.End.AddressLocal;

excelEngine.Excel.Workbooks[0].Worksheets[0].AutoFilters.FilterRange = worksheet.Range[range];
workBook.SaveAs("sample.xlsx");


Documentation:
http://help.syncfusion.com/file-formats/xlsio/worksheet-cells-manipulation#data-filtering

Thanks,
Sivakumar

Anas El Hallabi
Replied On February 11, 2016 04:33 PM UTC

Hi Sivakumar,

Thank you for your response. I was able to place the filters at the right position.

Regards,
Anas

Ashwini Paranthaman [Syncfusion]
Replied On February 12, 2016 11:47 AM UTC

Hi Anas,
Thank you for the update.
We are glad that your issue has been fixed.
Please let us know if you need any other assistance.
Regards,
Ashwini P.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;