
以下代码对应的是word2010
Java代码 1. public class JacobTest
2. public static void wordToPDF(String
3. ActiveXComponentword
4. try {
5. app.setProperty(
6. Dispatch docs
7. Dispatch doc
8. docs,
9. "Open",
10. Dispatch.Method,
11. new Object[]
12. new
13. //new Variant(type)
14. Dispatch.invoke(doc,
15. toFile, new
16. Variant f = new
17. Dispatch.call(doc,
18. } catch (Exception
19. e.printStackTrace()
20. } finally {
21. app.invoke("Quit"
22. }
23. }
24.
25. public static void main(String[]
26. //源文件全路径
27. String docfile ="D:
28. for (int i = 0i <
29. //些路径test为实际存在的目录
30. String toFile=
31. wordToPDF(docfile,
32. }
33. }
34. }
JacobTest {wordToPDF(String docfile, String toFile,int type) { ActiveXComponent app = new ActiveXComponent("Word.Application"app.setProperty("Visible", new Variant(false)) docs = app.getProperty("Documents").toDispatch() = Dispatch.invoke( Dispatch.Method, Object[] { docfile, new Variant(false), new Variant(true) }, new int[1]).toDispatch() Variant(type),这里面的type的决定另存为什么类型的文件Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] new Variant(type) }, new int[1]) new Variant(false) Dispatch.call(doc, "Close", f) (Exception e) { e.printStackTrace() "Quit", new Variant[] {}) main(String[] args) {源文件全路径"D:\\服务实施描述报告(企业门户).docx" <18i++) { 为实际存在的目录,s后面为要另存为的文件名toFile="d:\\test\\s"+i wordToPDF(docfile, toFile,i)"Word.Application")// 启动 的决定另存为什么类型的文件
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)