• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How do I read a excel file from the response

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Grow your own food... or this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic