chgk
asked on
Export To Excel
I have an Html page with a button and also some data in table format
On click of button I have to call some servlet or any way. I have to create and Excel sheet and export all the data to that sheet. Any suggestions??
Can I give the HTML content type to Excel format
Thanks
On click of button I have to call some servlet or any way. I have to create and Excel sheet and export all the data to that sheet. Any suggestions??
Can I give the HTML content type to Excel format
Thanks
ASKER
I think we can set the content type of an HTML page to EXCEl
any suggesions on this
any suggesions on this
Perhaps you can, but I haven't worked with that. Anyway, you said:
>> On click of button I have to call some servlet or any way
So in the Servlet, you can put your Java code to write to the excel-sheet?
>> On click of button I have to call some servlet or any way
So in the Servlet, you can put your Java code to write to the excel-sheet?
ASKER
Any help on Setting the contents type
of html to Excel sheet
of html to Excel sheet
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try out something like this
public synchronized void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Log.skip();
Log.write("Servlet posting...");
try
{
String filename = request.getParameter("Down Load");
File file = new File(filename);
String lsContentDisposition = "attachment; filename=\"" + filename + "\";";
response.setContentType("a pplication /vnd.ms-ex cel");
response.setContentLength( (int)file. length());
response.setHeader("Conten t-Disposit ion", lsContentDisposition);
java.io.FileInputStream fis = new java.io.FileInputStream(fi le);
int i = 0;
javax.servlet.ServletOutpu tStream out = response.getOutputStream() ;
while((i=fis.read()) != -1)
{
out.write(i);
}
out.flush();
out.close();
fis.close();
response.flushBuffer();
}
catch(Throwable t)
{
//System.out.println("---D ownLoadFil e--:" + e1.getMessage() );
System.out.println("---Dow nLoadFile- -:" + t.getMessage() );
}
}
public synchronized void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Log.skip();
Log.write("Servlet posting...");
try
{
String filename = request.getParameter("Down
File file = new File(filename);
String lsContentDisposition = "attachment; filename=\"" + filename + "\";";
response.setContentType("a
response.setContentLength(
response.setHeader("Conten
java.io.FileInputStream fis = new java.io.FileInputStream(fi
int i = 0;
javax.servlet.ServletOutpu
while((i=fis.read()) != -1)
{
out.write(i);
}
out.flush();
out.close();
fis.close();
response.flushBuffer();
}
catch(Throwable t)
{
//System.out.println("---D
System.out.println("---Dow
}
}
http://jakarta.apache.org/poi/