java - 弹出 excel 文件而不是在 apache poi 内部保存

标签 java spring apache-poi file-handling

我需要在转换为 Excel 文件后在弹出窗口中生成一个文件。我为此使用 apache poi。

这是我的代码:

try {
    FileInputStream file = new FileInputStream(new File("C:\\update.xls"));

   **excel coding here..**

    file.close();

    FileOutputStream outFile =new FileOutputStream(new File("C:\\update.xls"));
    workbook.write(outFile);
    outFile.close();

} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

我可以在 FileOutputStream 或其他东西中做什么并让用户将其保存到他们想要的任何地方?

最佳答案

您正在将 URL C:\update.xls 硬编码到文件中。根据您的项目,您可以创建一个 UI,在其中添加(一个文本字段,用户可以在其中输入所需的文件名\路径,或文件选择对话框)。或者您可以从控制台读取文件路径。检索路径后,您可以使用

创建文件

FileOutputStream outFile =new FileOutputStream(new File(NewFilePath))

关于java - 弹出 excel 文件而不是在 apache poi 内部保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20041909/

相关文章:

java - 如何限制 Firebase 电子邮件登录中的错误密码尝试?

java - 在 Hadoop 2.2.0 中运行作业的 IBM_JAVA 错误

java - 反序列化失败时的 Kafka 消费者行为

java - 在 Java 中从 Excel 中获取值的问题

java - 如何修复线程 "main"java.lang.NoSuchMethodError : org. apache.poi.POIXMLDocumentPart.getPackageRelationship 中的此异常

Java Apache POI : Read/Write from . 文档文件问题

java - 如何使用 Spring Security + Angular 登录/认证

java - Prepare 语句出现无效的列索引错误

java - 保留带有primefaces <p :selectManyMenu> while clicking NEXT/BACK of wizard component的选定项目

java.lang.ClassCastException : com. sun.proxy.$Proxy29 无法转换为 com.frodo.questionbank.service.impl.QuestionService