问题:我的代码总是返回一行而不是 13。
代码:
Excel.Application xlApp = null;
Excel.Workbook xlWorkBook = null;
Excel.Worksheet xlWorkSheet = null;
Excel.Range xlrange = null;
string sCurrentDir = Directory.GetCurrentDirectory();
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(sCurrentDir + @"\Res\res.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlrange = xlWorkSheet.UsedRange;
xlrange.AutoFilter(5, "4", Excel.XlAutoFilterOperator.xlFilterValues, Type.Missing, true);
Excel.Range filteredRange = xlrange.SpecialCells(Excel.XlCellType.xlCellTypeVisible, Excel.XlSpecialCellsValue.xlTextValues);
MessageBox.Show(filteredRange.Rows.Count.ToString());
Run Code Online (Sandbox Code Playgroud)
如您所见,我想用值“4”过滤第 5 列。它应该返回 13 行,但它总是返回 1 行。
任何帮助将不胜感激