簡體   English   中英

如何在eclipse內部編輯器中打開excel文件

[英]how to open excel file in eclipse internal editor

我需要在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文件。

標准Eclipse中沒有Excel文件的內部編輯器。 所以你只是讓普通的文本編輯器試圖編輯二進制文件。

您可以嘗試IDE.openEditorOnFileStore ,這可能會在Eclipse中打開“就地系統編輯器”(您需要在“常規”>“編輯器”頁面的“首選項”中設置“允許就地系統編輯器”選項)。

如果excel文件沒有損壞,您只需雙擊它就可以在編輯器中打開它。 要讀取或寫入excel文件,您應該使用apache poi框架。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM