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.
Unfortunately, activation email could not send to your email. Please try again.

How to copy the filter results?

Thread ID:

Created:

Updated:

Platform:

Replies:

130279 May 3,2017 12:24 PM May 5,2017 12:29 AM Windows Forms 4
loading
Tags: XlsIO
HuangXianwei
Asked On May 3, 2017 12:24 PM

How to copy the filter results? 
My sample xlsx,
in sheet1:
+|A
1|title
2|1
3|2
4|2
5|1
6|2
7|1

filter the 2, get results:
+|A
1|title
3|2
4|2
6|2

copy filter results to sheet2,
what i want results in sheet2:
+|A
1|title
2|2
3|2
4|2

what i get in sheet2:
+|A
1|
2|1
3|2
4|2
5|1
6|2
7|1

This is my code, Please help me to see what is the problem.
Thinks.
------
class Program
{
    static void Main(string[] args)
    {
        string filePath = @"D:\x.xlsx";
        ExcelEngine eg = new ExcelEngine();
        IApplication excelApp = eg.Excel;
        IWorkbook wb =  excelApp.Workbooks.Open(filePath, ExcelOpenType.Automatic);

        IWorksheet sheet = wb.Worksheets[0];
        sheet.AutoFilters.FilterRange = sheet.UsedRange;
        IAutoFilter af = sheet.AutoFilters[0];
        af.FirstCondition.DataType = ExcelFilterDataType.String;
        af.FirstCondition.String = "2";

        IRange usedRange = sheet.UsedRange;
        usedRange.CopyTo(wb.Worksheets[1].Range["A1"], ExcelCopyRangeOptions.None);
        wb.Save();
        wb.Close();
        eg.Dispose();
    }
}
------

Abirami Varadharajan [Syncfusion]
Replied On May 4, 2017 07:46 AM

Hi HuangXianwei, 
 
Thank you for contacting Syncfusion support. 
 
As per MS Excel behavior, filtered range cannot be copied to another range. However, we have prepared a sample as per your requirement, which can be downloaded from following location. 
 
 
Kindly refer and let us know that your requirement is fulfilled. 
 
Regards, 
Abirami 


HuangXianwei
Replied On May 4, 2017 10:32 AM

Hi Abirami,

Thank you for your reply.

Your answers and examples are really helpful to me.

Thanks again for your help,
HuangXianwei

Abirami Varadharajan [Syncfusion]
Replied On May 5, 2017 12:29 AM

Hi HuangXianwei, 
 
We are glad that your requirement is fulfilled.

Please let us know if need any further assistance.
 
 
Regards, 
Abirami. 


Abirami Varadharajan [Syncfusion]
Replied On May 5, 2017 12:29 AM

Hi HuangXianwei, 
 
We are glad that your requirement is fulfilled.

Please let us know if need any further assistance.
 
 
Regards, 
Abirami. 


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.

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.

;