java 用java打开excel文档

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6167585/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:38:40  来源:igfitidea点击:

Open excel document in java

java

提问by maks

I want to open excel document from my program in java. Actually I want excel document to be opened when I click on button in my program. I have tried

我想用java从我的程序中打开excel文档。实际上,当我单击程序中的按钮时,我希望打开 excel 文档。我努力了

Runtime.getRuntime().exec("workbook.xls");

where workbook.xls is located in the root of project folder, but it doesn't work. Exception says that it can not open program workbook.xls. How can I do this

其中 workbook.xls 位于项目文件夹的根目录中,但它不起作用。异常表示无法打开程序 workbook.xls。我怎样才能做到这一点

回答by Lukas Knuth

I guess you want to open your Excel-file with it's default program (like Excel)? If so, you can use the Desktop-class:

我猜你想用它的默认程序(比如 Excel)打开你的 Excel 文件?如果是这样,您可以使用Desktop-class

Desktop.getDesktop().open(new File("path/to/your/file.xls"));

回答by 8bitme

You can use Apache POIto work with Microsoft documents. Have a look herefor examples on how to use this.

您可以使用Apache POI来处理 Microsoft 文档。看看这里关于如何使用它的例子。