如何使用python-docx从sqlite导入数据?

问题描述 投票:1回答:1

需求:

我需要将来自sqlite3 db的文本和图像数据填充到word文档中。

我在做什么:

我正在使用python-docx库,using this documentation to get started

Db结构:

创建表用户(用户ID整数PRIMARY KEY,用户名文本不为NULL,UserImage Blob)

我的代码:

import sqlite3
from docx import Document

document = Document()
document.add_heading("Test Report from Sql",0) # ---> Document heading name
connection = sqlite3.connect("demo.db")  # ---> Connection to Db
cursor = connection.cursor()
rows = cursor.execute("SELECT UserName FROM Users where UserID = 1") # ---> Trying to get text values from db and adding
p = document.add_paragraph(rows)

connection.close()
document.save('Report1.docx')

错误消息:TypeError:“ in”要求将字符串作为左操作数,而不是元组

python-3.x sqlite python-docx
1个回答
0
投票

您是如何克服这个问题的?我现在正面临着同样的问题

© www.soinside.com 2019 - 2024. All rights reserved.