Forums Register Login

JSP - POI project - facing problem while writing excel sheet from jsp.

+Pie Number of slices to send: Send
Hi

I have been using POI project with core java and it works just fine.
But when i try to use it in jsp code my excel sheet is blank.

The code below is what works fine with java - remove the commect for core java below to run it.

im providin a dummy code -

response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition","attachment;filename=Web_Transact_Report.xls");

int rownum= 0 ;
HSSFWorkbook wb= new HSSFWorkbook();
HSSFSheet sheet= wb.createSheet("Transaction Report");
HSSFSheet sheet1= wb.createSheet("Net Banking");
HSSFRow row = sheet.createRow((short)rownum);
rownum++;
HSSFCellStyle headerStyle= wb.createCellStyle();
HSSFFont headerfont= wb.createFont();
headerfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
headerfont.setColor((short)9);
headerfont.setFontName("Arial");
headerStyle.setFont(headerfont);
headerStyle.setFillBackgroundColor((short)18);
headerStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
HSSFCellcel ;
cel = row.createCell((short)0);
cel.setCellValue("Service");
cel.setCellStyle(headerStyle);
cel = row.createCell((short)1);
cel.setCellValue("TXN ID");
cel.setCellStyle(headerStyle);

/* this line is used with java code*/
//FileOutputStream file = new FileOutputStream("Web_Transact_Report.xls");

/* this line below is used for jsp output stream and gives me a message that this out put stream has already been called for this response*/

wb.write(response.getOutputStream());

/*used with java code*/
//file.close();

The problem is if i use response.getOutputStream() the jsp gives error output stream already called. The above code is all my jsp page has except the directive.

If i use the conventional way of out put stream then on jsp it gives a blank excelsheet but works fine with normal code.

Need some urgent help .
Thanks
Avneet
+Pie Number of slices to send: Send
You should be handling this in a servlet, not a JSP. JSPs have so many assumptions about output of HTML. In this case your JSP is getting the output stream and writing a bunch of output before it gets to your code.

Bill
+Pie Number of slices to send: Send
If you want to get the values from a jsp page to an excel sheet..
you don't want to write these much lines..
it can be fixes with 2 lines.. itself

if u want the code for that program
i can send to u now

regards
Aravind
+Pie Number of slices to send: Send
Moved to the Other Open Source Projects forum.
+Pie Number of slices to send: Send
Hey

So what you are sayin is do this with servelet, but im sure this could be implemented on a jsp page to.Just need to fix this output stream already called issue.Would apreciate some more help on this.



Aravind you have some dummy code can i have a look .
Doing this the table way is not good because then i cant format my excel sheet.

Thanks Avneet
+Pie Number of slices to send: Send
It is theoretically possible to do this on a JSP page, but not practically. Trust Williams advice, and do this in a servlet.
+Pie Number of slices to send: Send
Wel im gonna try this on a servlet, but i would like to know why this reponse already been set or getOutputStream() for this response is already been used comes even when im nt using the response object any where else.
except setting the header of the page.

Thanks
Avneet
+Pie Number of slices to send: Send
That's a questions about how JSP works. You might have a look at the Java source code that gets produced from the JSP page (if you're using Tomcat it's somewhere deep in the "work" directory). That should show you how the stream is used in places other than the ones where you use it.
+Pie Number of slices to send: Send
thanks william and ulf for your valuable suggestions i have been able to implement the poi and create sheet thru servlets.

Thanks for your help guys.
+Pie Number of slices to send: Send
Hello Avneet,
I m new commer in the ranch ;-)
could you please send me any example code of excel export using poi (jsp or servlet)

Many thanks.
+Pie Number of slices to send: Send
hi all,
can any one provide the code for sending JSP data(which is From DataBase) as well as the API used for it.And Where to place the API in my project directory.
It's never done THAT before. Explain it to me tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4411 times.
Similar Threads
Generate Excel report in java
how to extract data from html page to excel sheet
how to extract data to an xl sheet
apache pio?
How to make POI HSSF support Chinese Encoding?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:29:17.