aspose file tools*
The moose likes GWT and the fly likes How do I read a excel file from the response 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 » Frameworks » GWT
Bookmark "How do I read a excel file from the response" Watch "How do I read a excel file from the response" New topic
Author

How do I read a excel file from the response

renisha suny
Greenhorn

Joined: May 12, 2011
Posts: 5
I am sending an excel file from backend as a servlet reponse.

Example:

response.set("Content-Type", "application/vnd.ms-excel");
response.set("Content-Disposition", "attachment; filename=sampleName.xls");

WritableWorkbook w = Workbook.createWorkbook(responseBody);
WritableSheet s = w.createSheet("Demo", 0);

s.addCell(new Label(0, 0, "Hello World"));
w.write();
w.close();
responseBody.flush();
responseBody.close();

Now, I need to read the excel file in the client side .
Can anyone please provide me withe sample code.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
What kind of client are we talking about - web browser, Java desktop app, something else?


Ping & DNS - updated with new look and Ping home screen widget
renisha suny
Greenhorn

Joined: May 12, 2011
Posts: 5
I have a GWT code on whose button click I invoke this servlet:

I have a servlet which connects to another server using HttpURLConnection

urlParameters = "operation=getData";
HttpURLConnection connection = HTTPUtils.getConnection(PropertyRemoteServlet.Host);
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(urlParameters);
wr.flush();
wr.close();

And in the backend server:

I am fetching some data and writing to an excel as:

public class HttpDataHandler implements HttpHandler {
Headers responseHeaders = exchange.getResponseHeaders();
exchange.sendResponseHeaders(200, 0);
OutputStream responseBody = exchange.getResponseBody();


exchange.getResponseHeaders().set("Content-Type", "application/vnd.ms-excel");
exchange.getResponseHeaders().set("Content-Disposition", "attachment; filename=sampleName.xls");

WritableWorkbook w = Workbook.createWorkbook(responseBody);
WritableSheet s = w.createSheet("Demo", 0);
s.addCell(new Label(0, 0, "Hello World"));
w.write();
w.close();
responseBody.flush();
responseBody.close();

}


Now, I need to display this excel in the browser.
I am not able to get the reponse in the abpve mentioned servlet from the backend server.

Please can figure out the issue with the above code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I read a excel file from the response
 
Similar Threads
file name issue
how to extract data to an xl sheet
Excel file manipulation
how to write and read excel file
JSF uploaded file location