在Java中打开Excel文档

在Java中打开Excel文档

本文介绍了在Java中打开Excel文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Java程序中打开excel文档.实际上,我想在程序中单击按钮时打开excel文档.我尝试过

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

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

其中workbook.xls位于项目文件夹的根目录中,但是它不起作用.异常表示无法打开程序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

推荐答案

我想您要使用默认程序(例如Excel)打开Excel文件吗?如果是这样,您可以使用 台式机 -class :

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

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

这篇关于在Java中打开Excel文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 22:44