hi!
what you do only works if the servlet container is installed on the same
machine as Excel!
instead of writing to a file and opening up excel with that file, write the
excel-stuff directly to response.getOutputStream, if your client uses IE and
has Excel installed, Excel should start up opening that file, if he doen't
use IE or hasn't Excel installed on his box, he can save the file to a
locatoin he wants.
hope this helps!
-mw
----- Original Message -----
From: "Balaji M (CTC)" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 02, 2002 12:13 PM
> Hi,
>
> I have got a grid in an Applet
>
> <<...OLE_Obj...>>
>
> On click of Export, I need to open the Selected Rows in MS Excel, I have
th
> following Method for doing this Job.
>
> public void ExportDataToExcel(HttpServletRequest request,
> HttpServletResponse response) throws IOException
> {
> try
> {
> File excel = new File("c:\\export.xls");
> String args = request.getParameter("ExportData");
> System.out.println("Inside try tuuutt");
> StringBuffer sb = new StringBuffer();
> //
response.setContentType("application/vnd.ms-excel");
> // PrintWriter pw = response.getWriter();
> sb.append("<TABLE border=1 cellpadding=0
> cellspacing=0 width=600 height=600>");
> sb.append("<B>");
> sb.append("<TR align=\"center\"
bgcolor=\"aqua\">");
> sb.append("<TD width=\"20\">Claim #</TD>");
> sb.append("<TD width=\"150\">Sym</TD>");
> sb.append("<TD width=\"150\">MJC</TD>");
> sb.append("<TD width=\"30\">Trans Date</TD>");
> sb.append("<TD width=\"150\">Err. Code</TD>");
> sb.append("<TD width=\"30\">Policy #</TD>");
> sb.append("<TD width=\"150\">Mod</TD>");
> sb.append("<TD width=\"120\">AS/Co</TD>");
> sb.append("<TD width=\"30\">Eff. Date</TD>");
> sb.append("<TD width=\"125\">Insured Name</TD>");
> sb.append("<TD width=\"160\">Claimant Name</TD>");
> sb.append("<TD width=\"150\">Adj #</TD>");
> sb.append("<TD width=\"30\">Handling
Office</TD>");
> sb.append("<TD width=\"40\">Issu Co #</TD>");
> sb.append("<TD width=\"30\">Division</TD>");
> sb.append("<TD width=\"40\">Pol Exp Date</TD>");
> sb.append("<TD width=\"30\">Error Desc</TD>");
>
> sb.append("</TR>");
> StringTokenizer st2 = new StringTokenizer(args,
> "@");
> int totalrows = st2.countTokens();
> System.out.println("total rows "+ totalrows);
> String sToken= new String();
> for(; st2.hasMoreTokens(); sb.append("</TR>"))
> {
> sb.append("<TR>");
> for(StringTokenizer st1 = new
> StringTokenizer(st2.nextToken(), "~"); st1.hasMoreTokens();
> sb.append("</TD>"))
> {
>
> sb.append("<TD width=\"120\">");
> sToken=st1.nextToken();
> sToken.trim();
> if(sToken.equals("SPACE"))
> {
> sToken=" ";
> }
> sb.append(sToken);
>
>
> //sb.append(st1.nextToken());
> }
>
> }
> sb.append("</B>");
> sb.append("</TABLE>");
> System.out.println("before Catch");
> FileOutputStream fileToWrite = new
> FileOutputStream(excel);
>
> fileToWrite.write(sb.toString().getBytes(),0,sb.toString().length());
> fileToWrite.close();
> }
> catch(Exception e)
> {
> e.printStackTrace();
> }
> try {
>
> Runtime r = Runtime.getRuntime();
> Process p = null;
> p = r.exec("C:\\Program Files\\Microsoft
> Office\\Office\\EXCEL.EXE C:\\export.xls");
> } catch (Exception Ex){
> Ex.printStackTrace();
> }
>
> }
>
> The Problems that I face are
> 1. I need to hardcode the path of Excel.exe, is there any other way to
doing
> this.
> 2. When I click Export again When the excel file is open, I need the Newly
> selected rows, Instead I am unable to write to the file (as it is open),
as
> it is open it gives the following exception
>
> "java.io.FileNotFoundException: c:\export.xls (The process cannot access
the
> file because
> it is being used by another process)"
>
> and Excel is opening and giving this alert.
>
> <<...OLE_Obj...>>
>
>
> Can you please give a solution.
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html