简体   繁体   中英

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

Can someone help to convert this vba code to C# getting lastrow and lastcolumn in a worksheet.

refer this link 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

or Try this to get last row and last column of excel sheet,

   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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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