【问题标题】:how to open excel file in eclipse internal editor如何在eclipse内部编辑器中打开excel文件
【发布时间】:2016-05-09 10:10:21
【问题描述】:

我需要在 Eclipse 内部编辑器中从项目资源管理器中打开 excel 文件。我正在调用下面的函数在编辑器中打开文件。

public static void openFileIntoEditor(String filePath) {
    File fileToOpen = new File(filePath);
    if (fileToOpen.exists() && fileToOpen.isFile()) {
        try {
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());
            IWorkbenchPage page = GUIHandler.getPage();
            try {
                IDE.openInternalEditorOnFileStore(page, fileStore);
                //IDE.openEditorOnFileStore(page, fileStore);
            } catch (PartInitException e) {
                System.out.println("ERORR in openFileIntoEditor : " + e.getMessage());
            }
        } catch (Exception e) {
            System.out.println("ERORR in openFileIntoEditor2 : " + e.getMessage());
        }
    } else {
    }
}

它适用于文本文件,但当我尝试在内部编辑器中打开 excel 文件时显示一些二进制代码。我在哪里做错了,或者我应该怎么做才能通过 java 程序在内部 Eclipse 编辑器中打开 excel 文件。

【问题讨论】:

    标签: java eclipse eclipse-plugin


    【解决方案1】:

    标准 Eclipse 中没有用于 Excel 文件的内部编辑器。所以你只是让普通的文本编辑器尝试编辑二进制文件。

    您可以尝试IDE.openEditorOnFileStore,这可能会在 Eclipse 中打开一个“就地系统编辑器”(您需要在“常规 > 编辑器”页面的“首选项”中设置“允许就地系统编辑器”选项)。

    【讨论】:

      【解决方案2】:

      如果 excel 文件没有损坏,您只需双击它即可在编辑器中打开它。 对于 excel 文件的读取或写入,您应该使用 apache poi 框架。

      https://poi.apache.org/spreadsheet/index.html

      【讨论】:

      • 我需要用java程序打开excel文件
      猜你喜欢
      • 1970-01-01
      • 2015-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-28
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      相关资源
      最近更新 更多