问题
Requirement:
I need text and image data from sqlite3 db to be populated into a word doc.
What I'm doing:
I'm using python-docx library, using this documentation to get started.
Db structure:
CREATE TABLE Users(UserID integer PRIMARY KEY, UserName text NOT NULL, UserImage Blob)
My code:
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')
Error Message: TypeError: 'in ' requires string as left operand, not tuple
来源:https://stackoverflow.com/questions/53254894/how-to-import-data-from-sqlite-using-python-docx