Dim Lrow,LColumn as Long
Sheet1.Activate
If WorksheetFunction.CountA(Cells) > 0 Then
LRow = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
LColumn = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
End If
有人可以帮助将此vba代码转换为C#,在工作表中获取lastrow和lastcolumn。
答案 0 :(得分:0)
或 试试这个以获取Excel工作表的最后一行和最后一列,
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
// get the reference of first sheet. By default its name is Sheet1.
// store its reference to worksheet
worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item(1);
int rowcount = worksheet.Rows.Count;
int colcount = worksheet.Columns.Count;