aspose file tools*
The moose likes Servlets and the fly likes generating xls in servlet giving error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "generating xls in servlet giving error " Watch "generating xls in servlet giving error " New topic
Author

generating xls in servlet giving error

nitin singh
Greenhorn

Joined: Nov 07, 2006
Posts: 22
Hi
I have follwoing code in servlet/action class.
BinaryView docBinaryView =(BinaryView)documentInstance1.getView(OutputFormatType.XLS);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Type", "application/vnd.ms-excel");
response.setDateHeader("expires", 0);
docBinaryView.getContent(response.getOutputStream());
return mapping.findForward(null);

On click of a button I forward control to this servelet and a xls should get generated.
I get an alert message
could not open http://localhost:9080:/tilesPocxls.do
then after that
Microsoft xl cannot access http://localhost:9080:/tilesPocxls.do.There may be several reasons.

Same code I am using for generation of pdf .it works..
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

I done a google search on "BinaryView" class. It seems like your are using business object(BO)'s report engine Java library. If so,My wild guess,


Try changing this



to



Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
nitin singh
Greenhorn

Joined: Nov 07, 2006
Posts: 22
correct this is for Business objects.But it doesnt recognises excel.

Same code for pdfformat works fine but givees error for excel format.I have struts application caling this through action classs
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

I checked with API documentation for class OutputFormatType and there is no constant variable called OutputFormatType.XLS but it has OutputFormatType.EXCEL


URL which I read.
nitin singh
Greenhorn

Joined: Nov 07, 2006
Posts: 22
Thats True prabhu I too saw that link.But actually the implementation is xls only as when I say OutputFormatType. there is no EXCEL but xls.

The problem is If i open this in a new window I only get that error but if i try to open this excel in parent.I get same error dialog box but latter the excel opens.
So I see problem some where else.
nitin singh
Greenhorn

Joined: Nov 07, 2006
Posts: 22
Prabhu same code I use for pdf generation just chnage the content type to pdf and it runs fine ..
I really wonder how the say EXCEL in the documentaion actually its exl.

Regards,
Nitin
subramanian thiruppathi
Greenhorn

Joined: Jul 20, 2004
Posts: 12
oh..


----------------------------<br />Subramanian Thiruppathi<br />SCJP 1.4 - 84 %<br />SCWCD - 81 %<br />SCMAD - 70%<br />RAD 255 - 85%<br />IBM Websphere Portal Server V5.1 App Dev(Test :399) - 74.5%
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

Otherthan what I said above, It seems like there is no issue with your code. However, here is working code which return XLS to client.



It may be possible that client having issue in opening XLS. Here is some trouble shooting steps I know :

1. Conform the XLS file you are passing it to client is opening without any error by double click the file.
nitin singh
Greenhorn

Joined: Nov 07, 2006
Posts: 22
problem got thanks..
The change which I did was I moved this code to a servlet.And calling that servelet from my jsp.Something to do with API I guess.


public class Test extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
System.out.println("Welcome to test servlet");
HttpSession session = request.getSession();
String storageToken = (String) session.getAttribute("storageTokenXLPdf");
ReportEngine webiRepEngine = (ReportEngine) session.getAttribute("ReportEngine");
DocumentInstance documentInstance1 = webiRepEngine
.getDocumentFromStorageToken(storageToken);
Report report = documentInstance1.getReports().getItem(0);
ImageOption imageOption = documentInstance1.getImageOption();
imageOption.setImageCallback("getImage.jsp");
imageOption.setImageNameHolder("image");
imageOption.setStorageTokenHolder("storageToken");
BinaryView docBinaryView = (BinaryView) documentInstance1
.getView(OutputFormatType.XLS);

//response.reset();
//response.flushBuffer();
//response.isCommitted();
//response.getWriter();
System.out.println("commited "+response.isCommitted());
//response.resetBuffer();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Type", "application/vnd.ms-excel");
response.setDateHeader("expires", 0);
docBinaryView.getContent(response.getOutputStream());
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: generating xls in servlet giving error
 
Similar Threads
WebSphere -New Bie
Problem starting webshere
Error 400: Invalid path /main was requested
HTTP 404 not found
Serving Excel Content