wood burning stoves*
The moose likes General Computing and the fly likes How to set width of cells in excel on browser ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "How to set width of cells in excel on browser ?" Watch "How to set width of cells in excel on browser ?" New topic
Author

How to set width of cells in excel on browser ?

Dhondiba Joshi
Ranch Hand

Joined: Jan 23, 2004
Posts: 39
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,


SCJP,SCWCD
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
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 ]

42
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

Clearly not a JSP issue, but not really an HTML one either, so I'm moving this to the General Computing forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dhondiba Joshi
Ranch Hand

Joined: Jan 23, 2004
Posts: 39
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

Joined: Oct 12, 2000
Posts: 5093
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

Joined: Nov 27, 2002
Posts: 451
Since, you are displaying it as an Excel file, can't you simply just set the column width directly within Excel ?


kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set width of cells in excel on browser ?
 
Similar Threads
Problem in Excel Format of Jasper Report
cell formatting in excel using jsp
Uploading files with JSF
Fixed Cellsize in GridBagLayout
JExcel Help