使用Java,如何让Word打开和编辑文件? [英] Using Java, how do I cause Word to open and edit a file?

查看:140
本文介绍了使用Java,如何让Word打开和编辑文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在java中打开excel文档

我有一个按钮我的Java应用程序,单击时,应该导致Word打开一个特定的文件。此文件位于文件系统中的某个位置,就像在用户的文档目录中一样。

I have a button in my Java application that, when clicked, should cause Word to open a particular file. This file is residing somewhere in the filesystem, like in a user's documents directory.

我如何用Java实现这样的东西?

How can I implement something like this in Java?

推荐答案

这是简单的演示应用程序,你可以修改按钮点击事件:

Here is the simple Demo App , you can modify it for button click event :

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;

public class Test {
 public static void main(String[] a) {
   try {
     if (Desktop.isDesktopSupported()) {
       Desktop.getDesktop().open(new File("c:\\a.doc"));
     }
   } catch (IOException ioe) {
     ioe.printStackTrace();
  }
}

}

这将使用默认的单词应用程序打开word文件。
有关桌面的更多详细信息

This would open word file with default word application . More detail here for Desktop

这篇关于使用Java,如何让Word打开和编辑文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆