Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
虽然 Apache POI 中有 MS Word 支持,但不是很好。加载然后保存除最基本格式之外的任何文件都可能会导致布局混乱。不过你应该尝试一下,也许它对你有用。
还有很多商业图书馆,但我不知道是否有更好的。
最近在处理类似的需求时,我不得不解决的蹩脚“解决方案”是使用 DOCX格式,打开 ZIP 容器,读取文档 XML,然后用正确的文本替换我的标记。这确实适用于替换没有段落等的简单文本。
我并不为此感到自豪,但它确实有效。
While there is MS Word support in Apache POI, it is not very good. Loading and then saving any file with other than the most basic formatting will likely garble the layout. You should try it out though, maybe it works for you.
There are a number of commercial libraries as well, but I don't know if any of them are any better.
The crappy "solution" I had to settle for when working on a similar requirement recently was using the DOCX format, opening the ZIP container, reading the document XML, and then replacing my markers with the right texts. This does work for replacing simple bits of text without paragraphs etc.
I'm not proud of it, but it works.
我建议使用 Apache POI 库:
http://poi.apache.org/
查看更多 - 它看起来就像它没有保持最新一样 - 嘘!不过,它现在可能已经足够完整,可以满足您的需要了。
I would suggest the Apache POI library:
http://poi.apache.org/
Looking more - it looks like it hasn't been kept up to date - Boo! It may be complete enough now to do what you need however.
试试这个:http://www.dancrintea.ro/doc-to-pdf/< /a>
除了替换 ms word 文件中的字符串之外,还可以:
- 使用简化的 API 读取/写入 Excel 文件,例如:getCell(x,y) 和 setCell(x,y,string)
- 隐藏Excel表格(例如二次计算)
- 替换 DOC、ODT 和 SXW 文件中的图像
- 并转换:
doc --> pdf、html、txt、rtf
xls--> pdf、html、csv
PPT--> pdf、swf
Try this one: http://www.dancrintea.ro/doc-to-pdf/
Besides replacing strings in ms word files can also:
- read/write Excel files using simplified API like: getCell(x,y) and setCell(x,y,string)
- hide Excel sheets(secondary calculations for example)
- replace images in DOC, ODT and SXW files
- and convert:
doc --> pdf, html, txt, rtf
xls --> pdf, html, csv
ppt --> pdf, swf
我会看一下 Apache POI 项目。这就是我过去用来与 MS 文档交互的方法。
http://poi.apache.org/
I would take a look at the Apache POI project. This is what I have used to interact with MS documents in the past.
http://poi.apache.org/
谢谢大家。我要尝试 http://www.dancrintea.ro/doc-to-pdf/< /a>
因为我需要转换经典的 DOC 文件(二进制)而不是 DOCX(zip 格式)。
Thanks all. I am gonna try http://www.dancrintea.ro/doc-to-pdf/
because I need to convert classic DOC file(binary) and not DOCX(zip format).