Method
Last row
#xlwings
sht.range(‘A1’).end(‘down’).select()
sht.range(‘A1’).end(‘down’).row
#sht.cells(1,1).end(‘down’).row
#sht.range(‘A’+str(sht.api.Rows.Count)).end(‘up’).row
#sht.cells(sht.api.Rows.Count,1).end(‘up’).row
#xlwings API
#sht.api.Range(‘A1’).End(xw.constants.Direction.xlDown).Row
#sht.api.Cells(1,1).End(xw.constants.Direction.xlDown).Row
#sht.api.Range(‘A’+str(sht.api.Rows.Count)).End(xw.constants.Direction.xlUp).Row
#sht.api.Cells(sht.api.Rows.Count,1).End(xw.constants.Direction.xlUp).Row
Last column
#xlwings
#sht.range(‘A1’).end(‘right’).column
#sht.cells(1,1).end(‘right’).column
#sht.cells(1,sht.api.Columns.Count).end(‘left’).column
#xlwings API
#sht.api.Range(‘A1’).End(xw.constants.Direction.xlToRight).Column
#sht.api.Cells(1,1).End(xw.constants.Direction.xlToRight).Column
#sht.api.Cells(1,sht.api.Columns.Count).End(xw.constants.Direction.xlToLeft).Column
Sample Code
#Referencing the Last Row or Column
import xlwings as xw #Import the xlwings package
app=xw.App()
bk=app.books.open('last.xlsx') #Get the active workbook
sht=bk.sheets.active #Get the active worksheet
#Last row
#xlwings
sht.range('A1').end('down').select()
print(sht.range('A1').end('down').row)
#sht.cells(1,1).end('down').row
#sht.range('A'+str(sht.api.Rows.Count)).end('up').row
#sht.cells(sht.api.Rows.Count,1).end('up').row
#xlwings API
#sht.api.Range('A1').End(xw.constants.Direction.xlDown).Row
#sht.api.Cells(1,1).End(xw.constants.Direction.xlDown).Row
#sht.api.Range('A'+str(sht.api.Rows.Count)).End(xw.constants.Direction.xlUp).Row
#sht.api.Cells(sht.api.Rows.Count,1).End(xw.constants.Direction.xlUp).Row
#Last column
#xlwings
#sht.range('A1').end('right').column
#sht.cells(1,1).end('right').column
#sht.cells(1,sht.api.Columns.Count).end('left').column
#xlwings API
#sht.api.Range('A1').End(xw.constants.Direction.xlToRight).Column
#sht.api.Cells(1,1).End(xw.constants.Direction.xlToRight).Column
#sht.api.Cells(1,sht.api.Columns.Count).End(xw.constants.Direction.xlToLeft).Column
#bk.close()
#app.kill()


Leave a Reply