java 如何在java中打印excel文件和word文档?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7336340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to print excel file and word document in java?
提问by Ahmed Ali
I am trying to print excel file and word document to printer, but I don't know how to do it in Java.
我正在尝试将 excel 文件和 word 文档打印到打印机,但我不知道如何在 Java 中进行。
Can anyone please help me and provide the code example?
任何人都可以帮助我并提供代码示例吗?
回答by Andrew Thompson
Desktop.getDesktop().print(new File("resume.doc"));
回答by Alex
I found that if you seeking for source code, surely someone would vote you down. What you need should be an idea, or some hint to the solution only.
我发现如果你寻找源代码,肯定有人会投票给你。您需要的应该是一个想法,或者只是对解决方案的一些提示。
For printing Office documents from java, One way is to call .NET from java, but this one is very slow and if you want to integrate the source code, you need a bridge. If you want to write serious projects, this method seems too weak.
从java打印Office文档,一种方法是从java调用.NET,但是这个很慢,如果你想集成源代码,你需要一个桥接器。如果你想写严肃的项目,这种方法似乎太弱了。
Another way is to use the Apache POI, as indicated by Nicholas. But POI also have some problem render Office documents. The positive sides is that it can be stable compared with calling .NET
另一种方法是使用 Apache POI,如 Nicholas 所指出的。但是 POI 在渲染 Office 文档时也存在一些问题。积极的一面是它可以比调用.NET稳定
For the java desktop way, seeing from java API, it seems to leave the solution to your OS. I am not sure about it. You can try it.
对于java桌面方式,从java API来看,似乎把解决方案留给了你的操作系统。我不确定。你可以试试看。
Anyway it is not a good way to print Microsoft things from Java, same applies to print PDF documents from .NET or other Microsoft things. Sigh!
无论如何,这不是从 Java 打印 Microsoft 内容的好方法,同样适用于从 .NET 或其他 Microsoft 内容打印 PDF 文档。叹!
回答by Nicholas
Apache POIis one of the more useful libraries for doing MS Word on java.
Apache POI是在 Java 上执行 MS Word 的更有用的库之一。
And Java already has a printing library
并且 Java 已经有一个打印库