自己设计一个文字水印文件,并且将水印添加到MySQLPDF所有页
from PyPDF2 import PdfReader,PdfWriter
reader1 = PdfReader("files/MySQL必知必会.pdf")
water = PdfReader("files/data4.pdf").pages[0]
all = PdfWriter()
for x in reader1.pages:
x.merge_page(water)
all.add_page(x)
all.write("files/作业mysql水印.pdf")
2. 统计订单数据中不同店铺的销售额,并且将统计结果保存到’店铺‘表中
import openpyxl
wb = openpyxl.load_workbook("files/订单数据.xlsx")
sheet1 = wb["订单数据"]
#第一步,添加新表标题
sheet2= wb.create_sheet("销售数据")
sheet2.cell(1,1,"店铺名")
sheet2.cell(1,2,"销售额")
#第二步,添加销售额统计
mr = sheet1.max_row
for row in range(2,mr+1):
xiaoshoue = int(sheet1.cell(row,6).value) * int(sheet1.cell(row,7).value)
sheet1.cell(row,11,xiaoshoue)
#第三步,添加进新表
cidt1={}
for row in range(2,mr+1):
if sheet1.cell(row,10).value != "作废":
if sheet1.cell(row,8).value not in cidt1:
cidt1[sheet1.cell(row,8).value]=sheet1.cell(row,7).value
else:
cidt1[sheet1.cell(row, 8).value] += sheet1.cell(row,11).value
dianming = list(cidt1.keys())
zonge = list(cidt1.values())
for x in range(len(dianming)):
sheet2.cell(x+2,1,dianming[x])
sheet2.cell(x+2,2,zonge[x])
wb.save("files/订单数据.xlsx")