我正在尝试使用 pandas 和 reportlab 导出 pdf 中的 sqlite 表列表。当我打印一切看起来都很好,但是当我尝试生成 pdf 时,我只得到标题行,但作为列格式。因为是较大应用程序的一部分,所以我有一个小 GUI 来生成 pdf。任何帮助将不胜感激。谢谢
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Pdf_test")
self.grid()
self.label = Label(self.parent, text = 'Pdf test')
self.label.grid(row=0, column=0)
self.buton = Button(self.parent, width= 15, text=" PDF ", command=self.pdf_test)
self.buton.grid(row=1, column=0)
def pdf_test(self):
self.conn = sqlite3.connect("Baza_Date.db")
self.cursor = self.conn.cursor()
with self.conn:
self.cursor.execute("SELECT * FROM test1")
rows = (pd.read_sql_query("SELECT * FROM test1", self.conn))
print (rows)
report = canvas.Canvas("Multi.pdf") # save pdf in working folder)
report.setFont("Times-Roman", 20)
report.setFillColor(black)
size = 9
y = 650
for row in rows:
report.setFont("Helvetica", size)
report.drawString(70, y, row)
y = y - 10
report.save()