我需要确定 Excel 工作表中有多少行填充了数据,即不为空的行。我需要使用 c# 来做到这一点。
目前我正在使用以下代码:
Excel.Application excelApp = new Excel.Application();
            string workbookPath = "C:\\ScriptTest\\bin\\Debug\\SDownloadScripts\\ExcelResult.xlsx";
            Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,
        0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
        true, false, 0, true, false, false);
            Excel.Sheets excelSheets = excelWorkbook.Worksheets;
            string currentSheet = "Sheet1";
            Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
            //long i = excelWorksheet.UsedRange.Rows.Count;
            int lastUsedRow = excelWorksheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell,
Type.Missing).Row;
            return lastUsedRow;
        }
我的工作表只填充了四行,但我得到了 65536。结果我需要 4 行,即没有填充一些数据的行。请建议。