How to add download option for openwith and saveAs on exporting file to excel in servlet
Hii Sir,
I made an application in which i need to export data from database into .excel formate in which i have given hard coded path for generated .excel file to save at particular position on the system.Now as per my requirement I need to give download option for openwith and saveAs from the browser. Below I am postion my code .Plz guys help me ...will be gratefull.Thanx in advance...
String datum1 = request.getParameter("fromdate");
String datum2 = request.getParameter("todate");
SimpleDateFormat sdfSource = new SimpleDateFormat("dd-MM-yyyy");
Date date = sdfSource.parse(datum1);
Date date2 = sdfSource.parse(datum2);
SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd");
datum1 = sdfDestination.format(date);
System.out.println(datum1);
datum2 = sdfDestination.format(date2);
System.out.println(datum2);
String filename = "d:/".concat(datum1).concat(" ").concat("To").concat(" ").concat(datum2).concat(".xls");
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("CallBillingSystem");
HSSFRow rowhead = sheet.createRow((short) 0);
rowhead.createCell((short) 0).setCellValue("calldate");
rowhead.createCell((short) 1).setCellValue("src");
rowhead.createCell((short) 2).setCellValue("dst");
String strQuery = "";
ResultSet rs = null;
conexion conexiondb = new conexion();
conexiondb.Conectar();
strQuery = "SELECT * FROM cdrcost where date(calldate) between '" + datum1 + "' and '" + datum2 + "'";
// strQuery = "SELECT * FROM cdrcost where date(calldate) between '2011-09-01' and '2012-01-01'";
rs = conexiondb.Consulta(strQuery);
int i = 1;
while (rs.next()) {
HSSFRow row = sheet.createRow((short) i);
row.createCell((short) 0).setCellValue(rs.getString("calldate"));
row.createCell((short) 1).setCellValue(rs.getString("src"));
row.createCell((short) 2).setCellValue(rs.getString("dst"));
i++;
}
FileOutputStream fileOut = new FileOutputStream(filename);
hwb.write(fileOut);
fileOut.close();
System.out.println("Your excel file has been generated!");
} catch (Exception ex) {
System.out.println(ex);
}
}
View Answers
Ads
Related Tutorials/Questions & Answers:
Advertisements
Exporting to excel using display tag?
Exporting to
excel using display tag? Hai ,
I am implementing pagination in struts.It has export to
excel option.When I am clicking on it ,it is displaying a alert box stating "the
file you are trying to open
download excel
download excel hi i create an
excel file but i don't i know
how to give
download link to that
excel file please give me any code or steps to give
download link
how to add a file in GZIP
how to
add a
file in GZIP Hi,
how to
add a
file in GZIP using Java.
Hi,
I have found a good referral site for
How to
Add a
file in GZIP
file format using Java.
http://www.roseindia.net/java/examples/io
Capture browser file download event - JSP-Servlet
Capture browser
file download event Hi,
I appreciate your help and thaanks for that.But my question was when filedownload dialog box comes in browser,
how we can come to know that user has clicked on Open,save or cancel button
How to add the servlet api to my pom.xml?
have to
add the
servlet api in pom.xml
file.
Let's know
how to
add the
servlet...
How to
add the
servlet api to my pom.xml? Hi,
I have learned Maven... pom.xml
file:
<dependency>
<groupId>javax.servlet</groupId>
how to download a file from a folder??
how to
download a
file from a folder?? i can upload any kind of files to a folder, and only the path of the
file is saved into the database, now
how a client can
download the
file from my folder. pls provide me the jsp code
How to upload and download file in hadoop?
How to upload and
download file in hadoop? Hi,
I am trying to learn to upload the
file on the Hadoop HDFS and then
download the same
file for learning the process.
How to upload and
download file in hadoop?
What
how to display the excel file content in the jsp
how to display the
excel file content in the jsp
How to present the content of the newly created
excel file in the following jsp to the web browser...="application/vnd.ms-
excel" %>
<%@ page import="java.io.*" %>
<
How to download a file from URL in Java?
How to
download a
file from URL?
If you are looking for example code in Java... is for you. You will learn
how to write
code in Java for downloading a
file from URL and then saving the
file on your
computer.
In this tutorial you will learn
how
How to add Apache Commons IO in pom.xml file?
How to
add Apache Commons IO in pom.xml
file? Hi,
How to
add the dependency of the Apache Commons IO library in the pom.xml
file in a Java project? My Project is using the maven for dependency management and compilation