首页 > 解决方案 > 将数据附加到openpyxl中的现有表

问题描述

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

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

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

标签: pythonopenpyxl

解决方案


您可以遍历工作表_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"

推荐阅读