简体   繁体   中英

Excel File Export in Java

I am trying to Export an Excel sheet from Java. In localhost I tried with

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

and it is working and Excel file is generated in C: drive. On deploying it on server it is not generated in C drive.

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:

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:

<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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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