【问题标题】:Export Postgres table data to Excel and append the data to MS Excel将 Postgres 表数据导出到 Excel 并将数据附加到 MS Excel
【发布时间】:2021-09-30 18:50:37
【问题描述】:
我知道我们可以使用 Python 将 Postgres 表数据导出到 MS Excel。
但是,通过使用 Python 是否可以通过将数据附加到现有 Excel 工作表数据来将 Postgres 表数据导出到 MS Excel?
注意:我不想每天手动执行此操作,而是想使用 Python 自动化该过程,通过基于日期附加数据将 Postgres 表数据导出到 MS Excel。
【问题讨论】:
标签:
python
excel
postgresql
psycopg2
【解决方案1】:
您可以通过 psycopg2 从 postgres 获取数据并使用 xlsxwriter 创建 excel 文件。
剩下的就是用数据库数据设置变量并将变量放入excel文件中
查看xlsxwriter 和psycopg2 的文档
【讨论】:
-
xlswriter 是只写的,它不能将数据附加到现有的电子表格中。为此,您需要openpyxl