[英]Last cell (column and row) of a Excel range object in 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。
或尝试使用此方法获取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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.