简体   繁体   English

Java中的Excel文件导出

[英]Excel File Export in Java

I am trying to Export an Excel sheet from Java. 我正在尝试从Java导出Excel工作表。 In localhost I tried with 在本地主机我尝试

FileOutputStream fileOut = new FileOutputStream("C:\\Filename.xls")

and it is working and Excel file is generated in C: drive. 并且它正在工作,并且在C:驱动器中生成了Excel文件。 On deploying it on server it is not generated in C drive. 在服务器上部署时,它不会在C驱动器中生成。

What should I change to download the file to my local system? 将文件下载到本地系统时应该更改什么?

For download to the client you need to adjust how the page is generated. 要下载到客户端,您需要调整页面的生成方式。 This may vary depending on how you are generating it but under jsp you can do: 这可能会有所不同,具体取决于生成方式,但是在jsp下可以执行以下操作:

response.setContentType("application/plain");
response.setHeader("Content-Disposition", "attachment; filename=FileName.xls");

in this case you also usually need to change your css access from: 在这种情况下,您通常还需要从以下位置更改css访问权限:

<link rel="stylesheet" href="xxx.css" type="text/css"/>

to

<style type="text/css">
  <%@include file="xxx.css"%>
</style>

First thing you should never hardcode the path like this. 第一件事,您永远不要这样硬编码路径。 Always use relative paths and read from some property file instead. 始终使用相对路径,而是从某些属性文件读取。 Secondly, you can follow the advice given in the link for using the files getting eclipse project absolute path (in web application using tomcat server) 其次,您可以按照链接中给出的建议使用文件获取eclipse项目的绝对路径(在使用tomcat服务器的Web应用程序中)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM