• Post Reply Bookmark Topic Watch Topic
  • New Topic

rendering JSP in XLS format  RSS feed

 
Benjamin Samuel
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a jsp which i am rendering as an xls. I need to convert the numbers as text format.

for example: If i have a number as 00010345 it should be displayed as is when exported to an xls. Currently the number is displayed as, 10345 (Without the zeros)

Hope it was descriptive enough. Please help.
 
Ankit Garg
Sheriff
Posts: 9608
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you rendering a JSP as an excel file?? I don't know how you are actually doing it, but once I needed to create excel files and I created then using Apache POI library for that. Since it is not clear to me how you are rendering your JSP as an excel file, I wonder how you have a number like 00010345 in java. If you store that value in a numeric type, it will automatically remove the leading zeros. So if you have that value as a String in java, maybe you should render it as a string in your excel file...
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i have a number as 00010345 it should be displayed as is when exported to an xls. Currently the number is displayed as, 10345 (Without the zeros)

Excel can do this (as can the libraries used for creating proper XLS files - mainly Apache POI and jExcelApi). But since you mention JSPs, I'm pretty sure that you're not creating an XLS file, but rather some text file that you're trying to have Excel open by setting the content type; is that correct? If so, then this can't be done.
 
Benjamin Samuel
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I 'm pretty sure that you're not creating an XLS file, but rather some text file that you're trying to have Excel open by setting the content type; is that correct?



Yes, thats exactly what i have done. I am not creating a binary file and data writing into it.
I tried to display the field as a formula field[by prefixing and'=' sign], and tried appending a space [ ] to convert it to string format. But this is not how they want it to be done. please let me know if you are aware of any other workaround.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it would be useful to know how "they" want "it" to be done, and what "it" actually is. As I said, the original problem requires creating (and streaming) an actual XLS file, and that can't be done in a JSP - you need to use a servlet.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!