xlwings 函数用于查找包含数据的最后一行 [英] xlwings function to find the last row with data

查看:1006
本文介绍了xlwings 函数用于查找包含数据的最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找包含数据的列中的最后一行.替换vba函数:LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row

I am trying to find the last row in a column with data. to replace the vba function: LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row

我正在尝试这个,但这会拉入 Excel 中的所有行.我怎样才能得到最后一行.

I am trying this, but this pulls in all rows in Excel. How can I just get the last row.

from xlwings import Workbook, Range
wb = Workbook()
print len(Range('A:A'))

推荐答案

综合以上答案,一行即可搞定:

Consolidating the answers above, you can do it in one line:

wb.sheet.range(column + last cell value).Get End of section going up[non blank assuming the last cell is blank].row

示例代码:

import xlwings as xw
from xlwings import Range, constants

wb = xw.Book(r'path.xlsx')
wb.sheets[0].range('A' + str(wb.sheets[0].cells.last_cell.row)).end('up').row

这篇关于xlwings 函数用于查找包含数据的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆