Pandoc不能很好地将HTML表转换成docx文档。我得到一个请求的内容,我使用一个模板文件呈现它。然后我就这样用pypandoc:
response = render(
request,
'template.html',
{
"field1": f1,
"field1": f2,
}
)
import pypandoc
pypandoc.convert(source=response.content, format='html', to='docx', outputfile='output.docx')
在模板.html包含一个表。在docx文件中,我得到一个表,其内容在下面分开。有没有额外的参数要考虑来解决这个问题?或者pandoc转换还不支持well表?有什么功能性的例子吗?也许有更简单的方法吗?在
编辑1
我提供了更简洁的例子。下面是一个测试python代码片段:
^{pr2}$我打开html文件:
$ firefox test-table.html
并获取以下html页面:
这很好。我还得到了以下docx文档:
$ libreoffice test-table.docx
这不好。在
我将docx文件导出为pdf文件,并得到以下输出:
$ evince test-table.pdf
请注意,我们在图片中看到的是整个页面,没有滚动的可能。第二列的日期根本不存在。有什么想法吗?在
编辑2
Pandoc已安装在conda环境中:
$ type pandoc
pandoc is hashed (/home/kaligne/local/miniconda3/bin/pandoc)
Pandoc版本是:
$ pandoc -v
pandoc 2.2.1
Compiled with pandoc-types 1.17.4.2, texmath 0.11, skylighting 0.7.0.2
Default user data directory: /home/kaligne/.pandoc
Copyright (C) 2006-2018 John MacFarlane
Web: http://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.
编辑3 我将docx文件转换为txt:
$ docx2txt test-table.docx
$ cat test-table.txt
Table with colgroup and col
Lime
Lemon
Green
Yellow
Fruit
Fruit
我们可以看到所有的数据都在。所以我想这和信息的显示方式有关。在
目前没有回答
相关问题 更多 >
编程相关推荐