Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing xlsx document to servlet response  RSS feed

 
renisha suny
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following servlet code which sends request to generate excel file in xlsx format:



And in the middleware server

the final code which generates the excel doc in zip format is :



But I am not able to retrieve the excel in the frontend .
Could anyone please point out if I am missing some thing here ?

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That code looks nasty. Are you trying to recreate the file format by zipping a collection of XML files? Why? Why not use Apache POI?
 
renisha suny
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please find attached the full source code where I am generating the Excel document
 
renisha suny
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is the code snippet from where I iniitiate the request

ExcelWorkBookWriter ew = new ExcelWorkBookWriter();
LinkedHashMap sheets = new LinkedHashMap();
sheets.put("sheet1", null);
sheets.put("sheet2", null);
sheets.put("sheet3", null);
sheets.put("sheet4", null);
sheets.put("sheet5",null);
try {
ew.init("myxls.xlsx", sheets, null);
} catch (Exception e) {
logger.error("Exception handler " + e.getMessage(), e);
}
ew.importViewData(results);
ew.flushDataIntoWorkbook(exchange.getResponseBody());
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch! I added some code tags to your post, which make it easier to read. What happens at the front end now? I'm confused by your mixing of Excel and zip files. Also, you set your content type to something that looks like it should be Excel, but then write a zip file?

My advice is to start small and build up. Can you write a working Excel file locally? Maybe start with just one sheet and not zipped. Can you use a servlet to download a simple text file? Once you get the pieces working, you can tie them all together.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
renisha suny wrote:ExcelWorkBookWriter

What is that? Are you sure you're using it right?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!