如何在XLWings中引用Excel表格列名? [英] How to reference Excel table column names in XLWings?

查看:1691
本文介绍了如何在XLWings中引用Excel表格列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Does XLWings allow my to interact with Excel tables (available in Excel 2007 and later via menu or ctrl+t) by table and column names? This does exist in the young, open sourceproject, Pyvot (https://pypi.python.org/pypi/Pyvot). I am hopeful that it is possible in XLWings now or that XLWings will add the functionality, Especially since this open source project is available as a model.

这里是一个例子 https://pythonhosted.org/Pyvot/tutorial.html 。 Pyvot专门从表格和自动过滤器中识别列名称,Pyvot将搜索工作簿中的所有表格,以获取给定的列名称。以下示例将从City列中的可见单元格中的值返回到列表。

Here is an example from 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." The example below will return values from visible cells from the City column to a list.

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


推荐答案

方括号访问工作,请参见eg here

Square bracket access works, see e.g. here:

For例如获取特定列的数据:

For example to get the data of a specific column:

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

或者获取该列包括标题和总行,您可以执行以下操作:

Or to get the column including header and Total row, you could do:

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

这篇关于如何在XLWings中引用Excel表格列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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