我需要在转换为 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/