我正在开发一个应用程序,能够列出客户与开放收费的pdf格式。代码包括输入电子表格、检查尚未付款的客户并将其保存在字典中,然后将其保存为pdf。现在的情况是,它只列出了一个客户的pdf格式。
代码如下:
# !/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
import openpyxl
import os
pastaApp = os.path.dirname(__file__)
def createPDF():
# Opens the spreadsheet and obtains the status of the last payment.
wb = openpyxl.load_workbook('C:/temp/cobranca.xlsx')
sheet = wb['Sheet1']
lastCol = sheet.max_column
# Checks the payment status of each customer.
unpaidMembers = {}
clients = []
months = []
emails = []
for r in range(2, sheet.max_row + 1):
for c in range(3, lastCol + 1):
payment = sheet.cell(row=r, column=c).value
if payment != 'ok':
client = sheet.cell(row=r, column=1).value
email = sheet.cell(row=r, column=2).value
month = sheet.cell(row=1, column=c).value
clients.append(client)
months.append(month)
emails.append(email)
unpaidMembers[client] = email
#print('Line:', r, 'Column:', c, 'Client:', client, 'Email:', email, 'Month:', month)
print('dictionary created successfully')
cnv = canvas.Canvas(pastaApp+"\\test.pdf", pagesize=A4)
cnv.drawString(10, 800, "Open Fee")
cnv.drawString(130, 800, " - Client/Month/E-mail")
cnv.drawString(10, 780, client)
cnv.drawString(170, 780, month)
cnv.drawString(350, 780, email)
cnv.save()
root = Tk()
root.title("Create PDF")
btn_createPDF = Button(root, text="Check", command=createPDF)
btn_createPDF.pack(side="left", padx=10)
root.mainloop()
这是一个电子表格模型:https://prnt.sc/125jdcq
1条答案
按热度按时间nnt7mjpx1#
您的代码只保存一条记录:
要保存所有记录,请使用:
请注意,我的代码不适合页面大小。