tags:

views:

187

answers:

1

Hi all,

I am exporting my List to CSV file through Servlet. Everything is working fine. but i want to set default/ dynamic width for cell/column?

Here is my coding. Your swift reply will be helpful..

Thanks in advance.

package com.uson.stat.action;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ExportAction extends HttpServlet {

        public void doPost(HttpServletRequest req, HttpServletResponse res)
                        throws ServletException, IOException  {

          res.setContentType("application/CSV");
          res.setHeader("Cache-Control", "public");
          res.setHeader("Pragma", "public");
          res.setHeader("Content-Disposition", "attachment;  filename= \"test.csv"+ "\"");

               String content = "Test Article"+","+"Viewed on 01-02-2010"+","+"Guest";

               System.out.println("content >>>>>>" + content);
           res.getOutputStream().print(content);
        }
}

output will be:

Test Article       Viewed on 01-01-2010      Guest

But output is displaying like this:

Test ArtiViewed on Guest

It is displaying fine in each cell. But I need to increase the size manually in Excel. file. How can i set the cell width dynamically/default size?

How to resolve this?

  • Gnaniyar Zubair
+1  A: 

"How can i set the cell width dynamically/default size?"

You can't.

CSV is just the data. Nothing more. No color, no font, no width. Nothing.

S.Lott
Thanks for your quick reply. But how can i set the same in EXCEL with color, with font, with width......etc.
Gnaniyar Zubair
Are you asking about sending a complete `.XLS` file?
S.Lott
Yes exactly....
Gnaniyar Zubair
If you want to send an `.XLS` file, then you should *not* be sending a CSV file. Please close this question, since it's *not* what you wish to do. If you wish to send an `.XLS` file, then create an `.XLS` file with column widths and other features. Do not create a CSV file and hope that it contains more information than it actually contains. Create an `.XLS` file.
S.Lott