How can I print my data from my database (sqlite) into a notepad /word document from my table in my GUI (using the same formatting). Here is my code for the table which is represented on my gui.
class Table(QtGui.QDialog):
def __init__(self):
super(Table, self).__init__()
with sqlite3.connect('database.db') as db:
cursor=db.cursor()
cursor.execute('select* from Receipt Order BY ReceiptID ASC')
title = [cn[0] for cn in cursor.description]
rows = [cn[0] for cn in cursor.description]
cur=cursor.fetchall()
layout = QtGui.QGridLayout()
self.table = QtGui.QTableWidget()
self.setGeometry(500,500,500,400)
qr = self.frameGeometry()
cp = QtGui.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
self.label2=QtGui.QLabel(self)
self.label2.setPixmap(QtGui.QPixmap('receipt_pic.jpg'))
self.label2.setGeometry(0,0,500,400)
self.table.setColumnCount(2)
self.table.setHorizontalHeaderLabels(title)
for i,row in enumerate(cur):
self.table.insertRow(self.table.rowCount())
for j,val in enumerate(row):
self.table.setItem(i, j, QtGui.QTableWidgetItem(str(val)))
layout.addWidget(self.table, 0, 0)
self.setLayout(layout)
self.setWindowTitle('Receipt Table')
I want to be able to click a button which copies this information (which would appear as a table with filled columns and rows) into a seperate notepad file / or any text document (where I can send the table to the printer to be printed).