As you say it's an excel problem not a java/servlet/tomcat problem.
Excel has always been this way. Really annoying when leading zeroes do
mean something (like in telephone numbers, for example).
If this is a display issue only then try adding a leading single quote
to the data:

out.writeBytes("'00667115");

Adding the single quote works when using excel manually, the zeroes are
displayed but not the qoute (unless you select the cell).

Of course, that modifies the data. You could try writing the excel file
with POI's HSSF project (http://jakarta.apache.org/poi/). You'll then be
able to control the column type.

Good luck,

Jon

Cui Xiaojing-a13339 wrote:
> Hello All,
> 
> I use below commands to generate a Excel file:
> 
>               DataOutputStream out = new DataOutputStream(new 
> FileOutputStream("e:/report.xls"));
>               out.writeBytes("Commerce ID");
>                       out.write(9);
>               out.writeBytes("Name");
>                       out.write(13);
>               out.write(10);
> 
>               out.writeBytes("00667115");
>                       out.write(9);
>               out.writeBytes("Cindy");
>                       out.write(13);
>               out.write(10);
>               out.close();
> 
> Then I  use below a set  of commands to download the Excel file.  
> 
>               FileDAO fd=new FileDAO();
>               response.setHeader("Cache-Control", "no-cache");
>               File f=new File("e:/report.xls");
>               response.addHeader("Content-disposition", "inline; filename=" 
> +f.getName());
>               ServletOutputStream out = response.getOutputStream();
>                               
>               FileInputStream in=new FileInputStream(f);
>               int b;
>               while ((b=in.read())!=-1){
>                       out.write(b);
>               }
>               in.close();
>               out.close();
> 
> But the downloaded Excel file only show 667115, but not 00667115 that is output when 
> the file is generated. I know that it is due to the default Excel field format is 
> General, but not Text. Could please give me some advice about how to let the Excel 
> file's field default format is Text? In another words, let the field contains 
> 00667115, but not 667115. Thanks.
> 
> Regards,
> Xiaojing
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to