python - 如何在 XLWings 中引用 Excel 表格列名称?

标签 python excel excel-2010 xlwings

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

这是来自 https://pythonhosted.org/Pyvot/tutorial.html 的示例。 “Pyvot 专门识别表和自动过滤器中的列名称。Pyvot 将在工作簿中的所有表中搜索给定的列名称。”下面的示例会将“城市”列中可见单元格的值返回到列表。

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

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

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

关于python - 如何在 XLWings 中引用 Excel 表格列名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36392633/

相关文章:

string - 将字符插入字符串的不同位置

excel - 在 excel 2010 图表的动态命名范围中使用 OFFSET 会导致崩溃

python - Unix `at` 使用 python 脚本 : Permission denied 进行调度

python - 在 PyCharm IDE 中添加 pygame 模块

python - Pandas 创建只有列名的空 DataFrame

Excel for Mac 2016 - 另存为 CSV - 行尾错误

c# - C# 中 Excel 2016 的 oledb 连接字符串

excel - 危机:对帐宏-每次都挂起Excel 2010

excel - 条件格式规则拆分和重复

python - POST 请求使用 pydev Eclipse 获取 400 错误代码,但在 Postman 上工作