如何在XLWings中引用Excel table列名?

How to reference Excel table column names in XLWings?

XLWings 是否允许我通过 table 和列名称与 Excel tables(在 Excel 2007 及以后通过菜单或 ctrl+t 可用)交互?这确实存在于年轻的开源项目 Pyvot (https://pypi.python.org/pypi/Pyvot) 中。我希望现在在 XLWings 中是可能的,或者 XLWings 将添加功能,特别是因为这个开源项目可以作为模型使用。

这是来自 https://pythonhosted.org/Pyvot/tutorial.html 的示例。 "Pyvot specifically recognizes column names from tables and auto-filters. Pyvot will search all tables in the workbook for a given column name." 下面的示例会将 return 城市列中 可见 个单元格的值添加到列表中。

import xl
wb = xl.Workbook(r"c:\temp\cities.xlsx")
wb.get("City").get() #get the column named City

方括号访问有效,参见例如here:

例如获取特定列的数据:

import xlwings as xw
wb = xw.Workbook.active()
xw.Range('TableName[ColumnName]').value

或者要获取包含 header 和总计行的列,您可以这样做:

xw.Range('TableName[[#All], [ColumnName]]').value