我正在尝试从 Java 导出 Excel 工作表。在本地主机中,我尝试使用
FileOutputStream fileOut = new FileOutputStream("C:\\Filename.xls")
它正在运行,并且在 C:
驱动器中生成了 Excel 文件。在服务器上部署它时,它不会在 C 驱动器中生成。
要将文件下载到我的本地系统,我应该更改什么?
最佳答案
要下载到客户端,您需要调整页面的生成方式。这可能会有所不同,具体取决于您生成它的方式,但在 jsp 下,您可以执行以下操作:
response.setContentType("application/plain");
response.setHeader("Content-Disposition", "attachment; filename=FileName.xls");
在这种情况下,您通常还需要更改您的 css 访问权限:
<link rel="stylesheet" href="xxx.css" type="text/css"/>
到
<style type="text/css">
<%@include file="xxx.css"%>
</style>
关于java - Java 中的 Excel 文件导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20347702/