我使用 jxl 库创建了一个 Excel 文件。代码运行正常,但唯一的问题是每次从服务中获取动态值来构建 Excel 文件时,Excel 内容都会覆盖到 "test.xls" 文件上,如下所示。是否有方法可以在内存中构建 Excel,并传递字节以下载它,而不是创建一个外部文件 ("test.xls")。
File file = new File("test.xls");
WritableWorkbook workbook = Workbook.createWorkbook(file);
:
:
:
:
InputStream in = new FileInputStream(file);
if (in == null) {
out.close();
}
else
{
byte[] buffer = new byte[4096];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
out.flush();
in.close();
out.close();
}
有人能帮我解决这个问题吗?
out
是什么意思?谢谢。 - mehnet ali