[英]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框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.