2024-06-26 17:45:24 发布
网友
我想在PythonXLWings中查找excel的第一行和第一列数据。以下是一些例子:
或
我认为最安全的方法是使用API属性,而只使用VBA{a1}方法。我们现在可以使用*通配符搜索任何内容,以确保找到公式(可以显示"")和值。一个简化的例子:
API
VBA
*
""
import xlwings as xw app = xw.App(visible=False, add_book=False) wb = app.books.add() ws = wb.sheets.active ws['C2'].value = 'check' row_cell = ws.api.Cells.Find(What="*", After=ws.api.Cells(ws.api.Rows.Count, ws.api.Columns.Count), LookAt=xw.constants.LookAt.xlPart, LookIn=xw.constants.FindLookIn.xlFormulas, SearchOrder=xw.constants.SearchOrder.xlByRows, SearchDirection=xw.constants.SearchDirection.xlNext, MatchCase=False) column_cell = ws.api.Cells.Find(What="*", After=ws.api.Cells(ws.api.Rows.Count, ws.api.Columns.Count), LookAt=xw.constants.LookAt.xlPart, LookIn=xw.constants.FindLookIn.xlFormulas, SearchOrder=xw.constants.SearchOrder.xlByColumns, SearchDirection=xw.constants.SearchDirection.xlNext, MatchCase=False) print((row_cell.Row, column_cell.Column))
我们可以使用SearchDirection.xlNext并从最后一个Excel单元格开始。这是VBA中的一种recommended方法,可以可靠地找到最后使用的行/列,但也可以可靠地找到第一行/列
SearchDirection.xlNext
Excel
我认为最安全的方法是使用
API
属性,而只使用VBA
{a1}方法。我们现在可以使用*
通配符搜索任何内容,以确保找到公式(可以显示""
)和值。一个简化的例子:我们可以使用
SearchDirection.xlNext
并从最后一个Excel
单元格开始。这是VBA
中的一种recommended方法,可以可靠地找到最后使用的行/列,但也可以可靠地找到第一行/列相关问题 更多 >
编程相关推荐