C#中Excel范围对象的最后一个单元格(列和行)

时间:2016-07-05 11:13:23

标签: c#

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。

1 个答案:

答案 0 :(得分:0)

请参阅此链接https://social.msdn.microsoft.com/Forums/office/en-US/5fa24ca9-2949-4442-b0f1-742e941cfe5a/how-to-get-the-last-cell-on-a-sheet-in-c-like-endxlup-in-excel-vba?forum=exceldev

或 试试这个以获取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;
相关问题