繁体   English   中英

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

[英]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。

请参阅此链接https://social.msdn.microsoft.com/Forums/office/en-US/5fa24ca9-2949-4442-b0f1-742e941cfe5a/how-to-get-the-last-cell-on-a-sheet在C像Endxlup在Excel VBA?论坛= 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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM