当前位置:网站首页>On the use of pyscript (realizing office preview)
On the use of pyscript (realizing office preview)
2022-07-29 04:23:00 【beginner2021】
One , Yes pyscript The expectations of the ( Realization office preview )
as everyone knows python There are many pairs of office The library of operations , and js Relatively weak in this regard ,pyscript Just in html Run in python Code , The original idea was to use pyscript function python Code will word To html Just for pyscript Namespace js And python The characteristics of interworking are js Write the conversion result to iframe Realize file preview in the tag
Two , Try it
One , Try Library mammoth
because pyscript It uses pyoided To achieve python The running effect of can only run python3.1.0
Try the following code
import mammoth
def wordToHtml(filename):
with open(filename+".docx", "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)
with open(filename+".html", "w") as html_file:
html_file.write(result.value)
# Support word There are pictures in
wordToHtml('1')I'm in advance python3.1.0 Tested in the environment, it can run , Pictured

The conversion result is as follows
Then I'll start with pypi Download a mammoth tar.gz Format package Then decompress and try to package it with the following code whl Format file import pyscript
python setup.py check
python setup.py sdist bdist_wheel || true
Then use the following code to introduce whl package
<py-env>- './mammoth-1.4.19-none-any.whl'</py-env>The resulting run reported an error
ValueError: Couldn't find a pure Python 3 wheel for 'cobble<0.2,>=0.1.3'.
You can use `micropip.install(..., keep_going=True)` to get a list of all packages
with missing wheels.Then it could be whl So I went to pypi Download from the official website whl package

Introduce the package with the following code
<py-env>- './mammoth-1.4.19-py2.py3-none-any.whl'</py-env>The result is the same error

It really broke down , The reason for the error is not correct wheel wheel ,pyscript Of github There is also a post on this issue whl Let me try it python3.1.0 It can be used after installation
Two , Try pydocx
Try to run python Code
from pydocx import PyDocX
html = PyDocX.to_html("test.docx")
f = open("test.html", 'w', encoding="utf-8")
f.write(html)
f.close()pack pydocx.tar.gz by pydocx.whl( Download from the official website tar.gz Unzip and enter )
python setup.py check
python setup.py sdist bdist_wheel || trueThen the following code is introduced
<py-env>- 'PyDocX-0.9.10-py3-none-any.whl'</py-env>Then the introduction succeeded , But the operation reports an error
3、 ... and , summary
pyscript It's a new module. There are still many problems. It's not recommended for novices to try , He passed pyodied Realization python Running effect
But it can only support python3.1.0 Many modules do not support , Interested friends can try it on their own
Links to related resources : Packed pydocx.whl file
边栏推荐
猜你喜欢
随机推荐
String, array, generalized table (detailed)
No, just stick to it for 59 days
On quotation
全屋WiFi方案:Mesh路由器组网和AC+AP
How to solve the problem of store ranking?
Two forms of softmax cross entropy + numpy implementation
C语言:联合体知识点总结
6. Pytest generates an allure Report
Why is it necessary to scale the attention before softmax (why divide by the square root of d_k)
Svg -- loading animation
Log configuration logback
Compilation and linking
Pytorch GPU and CPU models load each other
Not for 63 days. The biggest XOR
11.备份交换机
不会就坚持64天吧 查找插入位置
SVG--loading动画
不会就坚持59天吧 替换单词
WebRTC实现简单音视频通话功能
visio画网格









