原表格中签名为路径信息,无法查看!
转换后将图片路径解析成图片显示出来
通过ie打开后用虚拟打印机可以将页面打印成pdf文档
源码:
#! python3
# -*- coding: utf-8 -*-
import openpyxl,pprint,os
import PySimpleGUI as sg
def data_processing():
wb = openpyxl.load_workbook(values['-xz1-'])
sheet = wb[str(wb.sheetnames[0])]
f_5 = open(values['-xz2-']+'/项目数据表.html','a')
f_5.write('<!DOCTYPE html>'+"\n"+'<html>' +"\n" + '<body>' +"\n"+ '<table border="1">' +"\n")
for i in range(1,sheet.max_row+1):
f_5.write('<tr>'+"\n")
for c in range(1,sheet.max_column+1):
name = sheet.cell(i,c).value
if ".png" in str(name):
f_5.write('<th><img src="https://ylwxsb.19wms.com' + str(name) + '" height="31" width="90"></th>' + "\n")
else:
f_5.write('<th>' + str(name) + '</th>' +"\n")
f_5.write('</tr>'+"\n")
f_5.write('</table>' +"\n" + '</body>' +"\n"+ '</html>' +"\n")
f_5.close()
layout = [
[sg.T('表格路径:',size=(8,1),key='-xm-'),sg.T(' ',size=(40,1),key='-bglj-'),sg.FileBrowse('选择',key='-xz1-')],#sg.FileBrowse选择文件路径,和sg.T同一行会自动传递路径信息到sg.T
[sg.T('保存路径:',size=(8,1),key='-xb-'),sg.T(' ',size=(40,1),key='-bclj-'),sg.FolderBrowse('选择',key='-xz2-')],#sg.FolderBrowse选择文件夹路径,和sg.T同一行会自动传递路径信息到sg.T
[sg.T(' ',size=(20,2)),sg.B('转换',size=(8,2),key='-zh-')]
]
window=sg.Window('Excel转换HTML表格',layout)
while True:
event,values=window.read()
if event==None:
break
if event=='-zh-':
if values['-xz1-']=="" or values['-xz2-']=="":
sg.Popup('请选择表格和转换后的保存路径!')
elif ".xlsx" not in values['-xz1-']:
sg.Popup('只支持转换xlsx为后缀的表格文件!')
else:
print("转换开始")
data_processing()
sg.Popup('处理完成')
window.close()