|
@@ -0,0 +1,42 @@
|
|
|
+#-*-coding:utf-8 -*-
|
|
|
+import os
|
|
|
+from PIL import Image
|
|
|
+from PIL import Image,ImageDraw,ImageFont
|
|
|
+from exceltool import ExcelTool
|
|
|
+
|
|
|
+def addText(img,orgpath,string,path,point=(100,100),size=32):
|
|
|
+ draw = ImageDraw.Draw(img)
|
|
|
+ fontpath = "/root/font/simsun.ttc"
|
|
|
+ #fontpath = os.path.join(settings.BASE_DIR,"templates/font/consola.ttf")
|
|
|
+ font = ImageFont.truetype(fontpath, size,encoding="unic")
|
|
|
+ draw.text(point,string,fill='black',font=font)
|
|
|
+ img.save(path)
|
|
|
+
|
|
|
+class_hour_tpl = "classhour.png"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+exceltool = ExcelTool("test.xls")
|
|
|
+data = exceltool.get_data()
|
|
|
+
|
|
|
+print(len(data))
|
|
|
+for item in data[2:]:
|
|
|
+ name = item[2].encode("utf-8")
|
|
|
+ subject_item0 = item[7].encode("utf-8")
|
|
|
+ subject_item1 = item[7].encode("utf-8")
|
|
|
+ subject_item2 = item[8].encode("utf-8")
|
|
|
+ train_type = item[6].encode("utf-8")
|
|
|
+ total_classhour = 100
|
|
|
+ print(name)
|
|
|
+
|
|
|
+ class_hour_file = os.path.join("/root/classhour","classhour{}.png".format(name))
|
|
|
+
|
|
|
+ img = Image.open(class_hour_tpl)
|
|
|
+ addText(img,class_hour_tpl,unicode("巴中逸沣安全培训学时证明","utf-8"),class_hour_file,(160,65),24)
|
|
|
+ addText(img,class_hour_tpl,unicode("姓名:{}".format(name),"utf-8"),class_hour_file,(80,100),20)
|
|
|
+ addText(img,class_hour_tpl,unicode("工种:{}".format(subject_item0),"utf-8"),class_hour_file,(80,130),20)
|
|
|
+ addText(img,class_hour_tpl,unicode("操作类型:{}".format(subject_item1),"utf-8"),class_hour_file,(80,160),20)
|
|
|
+ addText(img,class_hour_tpl,unicode("准操项目:{}".format(subject_item2),"utf-8"),class_hour_file,(80,190),20)
|
|
|
+ addText(img,class_hour_tpl,unicode("培训类型:{}".format(train_type),"utf-8"),class_hour_file,(80,220),20)
|
|
|
+ addText(img,class_hour_tpl,unicode("总学时:{}".format(total_classhour),"utf-8"),class_hour_file,(80,250),20)
|
|
|
+ addText(img,class_hour_tpl,unicode("已完成学时:{}".format(total_classhour),"utf-8"),class_hour_file,(80,280),20)
|