aspose file tools*
The moose likes Servlets and the fly likes Setting the column width of an Excel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Setting the column width of an Excel" Watch "Setting the column width of an Excel" New topic
Author

Setting the column width of an Excel

Vijay Kumar Prabhakar
Greenhorn

Joined: Oct 06, 2003
Posts: 2
HI,
I am calling a servlet from javascript which opens up in a new window. The servlet is responsible for sending the data to the client as content type application/vnd.ms-excel. The data exported on to the client as an Excel Sheet has fixed column width. Is there any possible way to fix the column
width of Excel?
Below is my servlet code
response.setContentType("application/vnd.ms-excel");
//response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
out = response.getWriter();
for (......) {
buf.append("xxx....")
buf.append("xxx....")
buf.append("xxx....")
......
out.println(buf);
}
out.flush();
out.close();

Below is the way I am calling the servlet from jsp having javascript
win = window.open( "servlet being called", "windowname" );
A Couple more questions.
a. The line
response.setHeader("Cache-Control", "no-cache");
does not work even though I am using HTTP1.1. I get an error page cannot be found on the browser.
b. If I comment the line stated in (a), then it works fine. The data is exported on to excel on the browser. If I keep the browser open, then try to call the servlet again, the data is not getting refresed with the new data from the servlet.
Please help me out on these Issues. Thanks.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Hi Vijay,
As usual, I am going to try to answer this question, without any experience or knowledge.
Well, the only knowledge and experience is dealing with outside programs creating Excel spreadsheets.
The cool thing about Excel, like Word, is that they are completely Objectified. Meaning there is an Object for every part of an Excel Spreadsheet, and threfore can be manipulated through the Object model. Their Object model is pretty simple and straight-forward.
So I would also hope that the Object Model can be called and manipulated through the web page. You might need to use a little of ASP and VBScript, or it might be able to be done in Javascript once you have the Object of the Excel spreadsheet.
So, basically, I gave you my thoughts on what might be helpful, without any specific answers. Microsofts Technet online should be able to give you the entire Object model of Excel. There is a Cell object, which will have the method/property that you want to set.
Good Luck.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Vijay Kumar Prabhakar
Greenhorn

Joined: Oct 06, 2003
Posts: 2
Hi Mark, Thanks a lot for your response. In your reply, I think you are talking about use OLE Automation Object. To use this I think we may need to reset Security feature of the browser (maybe to a lower level). I am not sure whether what I am stating is true. Please let me have your views/comments.
Thanks again for sparing some time for the reply.
Vijay
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30776
    
157

Vijay,
You can manipulate the details of Excel using a library instead of just outputing a deliminated file. Apache's POI contains HSSF (horrible spreadsheet format) which is a great open source library for manipulating Excel files. You can do almost anything in HSSF that you could do with your mouse if you had the file in front of you. It's pretty easy to use and comes with samples.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
Jeanne,
where did place the the commons-logging.jar. Will it work instead giving a class path , if i place it in comm/lib in tomcat?
thanks in advance
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30776
    
157

That's more of a Tomcat question. On the server I am using (Webbsphere) it needs to be in the classpath. Does Tomcat add jars in that directory to a default classpath?
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
I was able to figure it out. I have to keep all three jar files in the common/lib.Thanks
Basavaraju Banakar
Greenhorn

Joined: Jul 18, 2002
Posts: 25
Sunitha,
U can also keep the jars in common/endorsed
It should also be possible to keep the application specific jars in the WEB-INF/lib folder....


It is impossible to make anything foolproof because fools are so ingenious..Murphy<br />Basu.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Setting the column width of an Excel