Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set width of cells in excel on browser ?

 
Dhondiba Joshi
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!
I am showing an excel sheet which user can open/save in browser. I am not using POI and doing it plainly by setting content type to excel. The problem is data in some cells does not fit in defalut size and user has to widen the cell manually to see the data properly.
Whats the way to avoid it ? Can defalut cell size be increased ? or can i format cellc width as per the data size. I dont want ot use any extra things like XSL.
please help,
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're outputting as CSV it's not possible.
If you're outputting as SLK it is possible.
SLK quickly gets very very ugly though.
This is one example...

Don't ask me exactly what everything does. One person here figured it out and he's dead without documenting it properly (he died suddenly last year).
We're just changing things as needed and hoping more or less...
I put in replace(',','.') because the data is formatted with a comma as decimal separator where Excel expects a period for numeric values.
Mind that this is output using a Servlet not a JSP so the string is pushed into the ServletOutputStream

Where sheet contains the result from the function.
The List that goes into the function contains a series of Maps, one per row of data.
I devices that system to pass tabular data around our webapp as it's convenient not only for internal use but also to output using JSP tags (JSTL or our own tabular data tag).
[ January 23, 2004: Message edited by: Jeroen Wenting ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clearly not a JSP issue, but not really an HTML one either, so I'm moving this to the General Computing forum.
 
Dhondiba Joshi
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeroen Wenting.
Though I am not clear about the code snippet. What does SLK mean ? (semicolon seperated ?) Also you have set contentype to text/plain. The way i was doing it is:

Is there any other way to decide cell width of excel. Specifying width of the td etc??
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SLK are SYLK files, which stands for SYmbolic LinK.
It's a textual representation of binary data (more or less) which Excell can read.
 
Ken Krebs
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since, you are displaying it as an Excel file, can't you simply just set the column width directly within Excel ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic