<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>word &#8211; 天地一沙鸥</title>
	<atom:link href="https://haoluobo.com/tag/word/feed/" rel="self" type="application/rss+xml" />
	<link>https://haoluobo.com</link>
	<description>to be continue....</description>
	<lastBuildDate>Wed, 20 Aug 2014 14:15:34 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>用程序生成word文档（DOC）</title>
		<link>https://haoluobo.com/2014/08/gen-word-doc/</link>
		
		<dc:creator><![CDATA[vicalloy]]></dc:creator>
		<pubDate>Wed, 20 Aug 2014 14:15:34 +0000</pubDate>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[word]]></category>
		<guid isPermaLink="false">/?p=11106</guid>

					<description><![CDATA[很多程序都支持导出PDF文档，不过如果需要对导出文档进行编辑PDF就显得不那么方便了。就国内环境而言，导出wo [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>很多程序都支持导出PDF文档，不过如果需要对导出文档进行编辑PDF就显得不那么方便了。就国内环境而言，导出word文档对有编辑需求的文档而言更为合适。<br />
由于我使用python，因此这里只讨论python下可用的方案。目前找到的解决方案主要有下面几种</p>
<ul>
<li><a href="https://github.com/mikemaccana/python-docx">python-docx</a><br />
目前能找到支持word格式的库非常的少，就python而言只找到 <a href="https://github.com/mikemaccana/python-docx">python-docx</a> 算是相对可用的解决方案。python-docx 的功能非常的弱，有很多的限制，比如不支持模板等。如果想生成复杂文档那就无能为力了。</li>
<li><a href="http://appyframework.org/pod.html">POD</a><br />
POD是Appy框架的一部分，可使用ODF (Open Document Format)文件做为模板，并输出ODF格式的文件，并可调用LibreOffice将生成的文件转换成DOC等格式。相比python-docx，POD用于生成更为复杂的文档。但如果你需要动态生成一些复杂表格，POD可能会有些问题。</li>
<li><a href="https://github.com/dagwieers/unoconv">unoconv</a><br />
unoconv是个文档转换工具，可调用LibreOffice对文档格式进行转换。unoconv可将HTML转换为DOC格式。因此可先生成HTML，然后再将HTML转换为DOC。生成HTML对广大的WEB开发者而言无疑是轻而易举的，这也是我最终选择的方案。不过要注意的是用unoconv将HTML转换成DOC，遍地是坑-_-!。</p>
<ul>
<li>只支持有限的HTML语法。很多CSS语法根本就不支持，看到的和转换出来的效果完全不一样。解决办法：在LibreOffice中编辑文档，然后保存成HTML，然后对保存的HTML进行编辑。</li>
<li>unoconv的-t参数可传入.ott格式的文档模板。默认情况下LibreOffice转换出的表格的行高远大于文字的高度，更糟糕的是文字还是顶对齐，非常不美观。编辑个空文档，然后保存为.ott，转换的时候指定模板文件可解决该问题。</li>
<li>生成的文档的左右边距不一致。恩&#8230;，这个我还没有找到解决办法。</li>
</ul>
</li>
</ul>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
