Win a copy of Svelte and Sapper in Action this week in the JavaScript 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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: 43016
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.
 
    Bookmark Topic Watch Topic
  • New Topic