- word转HTML功能
- Pyqt5图像化UI
- 打包app
- 1.安装py2app
- 2.创建setup.py文件
- 3.解决报错py2applet:command not found
- 4.打包
#转化HTML
def createHTML(self):
html = PyDocX.to_html(str(self.docx_path))
# 过滤掉不支持的标签(安卓暂不支持style、script等) #
html_remove = re.sub('','',html)
# 样式兼容 #
html_style = BeautifulSoup(html_remove,'html.parser')
# body边距及对齐方式
html_style.find('body')['style'] = 'padding: 50px 30px;text-align: justify;'
# 居中
text_center = html_style.select('.pydocx-center')
for item in text_center:
item['style'] = 'display:block;text-align:center;padding:20px 0px'
# 局右
text_right = html_style.select('.pydocx-right')
for item in text_right:
item['style'] = 'display:block;text-align:right;'
# 下划线
text_underline = html_style.select('.pydocx-underline')
for item in text_underline:
item['style'] = 'text-decoration:underline;'
# 创建HTML #
html_path = 'index.html'
f = open(html_path,'w',encoding='utf-8')
f.write(str(html_style))
f.close()
# 转化完成路径
html_path1 = os.path.abspath('index.html')
self.lb2.adjustSize()
self.lb2.setGeometry(QtCore.QRect(20, 140, 360, 100))
self.lb2.setWordWrap(True)
self.lb2.setAlignment(QtCore.Qt.AlignTop)
self.lb2.setText('转化完成路径:'+html_path1)
Pyqt5图像化UI
#初始化UI
def initUI(self):
self.setGeometry(200,200,400,200)
self.setWindowTitle('word转html')
self.bt1 = QPushButton('选择文件',self)
self.bt1.move(10,20)
self.lb1 = QLabel('上传文件路径:',self)
self.lb1.move(20,60)
self.lb1.setObjectName("lb1")
self.bt2 = QPushButton('立即转换',self)
self.bt2.move(10,100)
self.lb2 = QLabel('转化完成路径:',self)
self.lb2.move(20,140)
self.lb2.setObjectName("lb2")
self.show()
self.bt1.clicked.connect(self.showFile)
self.bt2.clicked.connect(self.createHTML)
#选择文件
def showFile(self):
file = QFileDialog.getOpenFileName(None, "选取文件","./", "All Files (*);;Text Files (*.txt)")[0]
self.lb1.adjustSize()
self.lb1.setGeometry(QtCore.QRect(20, 60, 360, 100))
self.lb1.setWordWrap(True)
self.lb1.setAlignment(QtCore.Qt.AlignTop)
self.lb1.setText('上传文件路径:'+file)
self.docx_path = file
打包app
1.安装py2app开发其实没什么难度,因为本身python支持的库很多,这里用的打包工具是py2app
pip install py2app2.创建setup.py文件
首先进入工程目录:cd 项目路径
py2applet --macke-setup demo.py#自己的打包文件
注:报错:py2applet:command not found
3.解决报错py2applet:command not found#首先查找py2applet路径 sudo find / -name "py2applet" -type f
#本机路径为 /System/Volumes/Data/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/bin/py2applet
#继续生成setup.py /System/Volumes/Data/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/bin/py2applet --macke-setup demo.py4.打包
python3 setup.py py2app --site-packages
提示这一坨的时候,恭喜你打包完成!!!
下边是对应的包及演示:



