我正在尝试查找包含特定行的Excel的最后一列的数据。我想仅在行number2
中找到它。
使用以下代码
Excel.Range last = sheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
int lastUsedRow = last.Row;
int lastUsedColumn = last.Column;
答案 0 :(得分:0)
You can do something like this--
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\test.xlsx");
Excel.Worksheet xlWorksheet = (Excel.Worksheet) xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
var cellvalue = (xlRange.Cells[2,colCount-1] as Excel.Range).Value2.ToString();