【问题标题】:Appending data to existing tables in openpyxl将数据附加到openpyxl中的现有表
【发布时间】:2021-03-07 03:47:22
【问题描述】:

我正在尝试使用 openpyxl 将一些数据附加到 Excel 电子表格中的现有表中

我在文档中只能找到如何创建新表,而不是如何向它们添加数据

对此的任何帮助或解决方法将不胜感激 谢谢

【问题讨论】:

标签: python openpyxl


【解决方案1】:

您可以遍历工作表_tables。假设您的表格名为 SalesTable,并且您想将表格范围编辑为 A1:C10。将table.ref 设置为“A1:C10”

for table in worksheet._tables:
    if table.displayName == "SalesTable":
        table.ref = "A1:C10"

随着 OpenPyXL 的更新版本,_tables 已更改为 .tables

for table in worksheet.tables:
    if table.displayName == "SalesTable":
        table.ref = "A1:C10"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    相关资源
    最近更新 更多