Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting the column width of an Excel

 
Vijay Kumar Prabhakar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vijay Kumar Prabhakar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sunitha reghu
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to figure it out. I have to keep all three jar files in the common/lib.Thanks
 
Basavaraju Banakar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic