This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How do I read a excel file from the response

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of client are we talking about - web browser, Java desktop app, something else?
 
renisha suny
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!