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:
copy filter results to sheet2,
what i want results in sheet2:
what i get in sheet2:
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();
}
}
------