Martin Lang wrote:
> Hi,
> 
> When I run the following very simple progam and try to open the writen
> .xls file with Excel XP I get
> an error message saying that the file is corrupted and some formatting
> information may got lost.
> The error occurs only when the file I read in (template.xls) has been
> created with Excel XP. When 
> I use a file that has been written by Excel 97 everything is o.k. 
> 
> Am I doing something wrong or is this a bug?
>

Issues

1. Close your output stream.  (and input stream too)
2. DO something with the IOException (you may be getting an 
error!)...like e.printStackTrace().
3. Secondly, there is no guarantee that its reading "template.xls" from 
the current directory or writing result.xls in the current directory 
(currdir is not defined and is therefore not platform inspecific) ... 
use a real path, suggest making use of args.

-Andy


> public static void main(String[] args) {
>       HSSFWorkbook wb;
>               
>       try {
>        FileInputStream template = new FileInputStream("template.xls");
>        FileOutputStream result = new FileOutputStream(new
> File("result.xls"));
>        POIFSFileSystem templatefs = new POIFSFileSystem(template);
>        wb = new HSSFWorkbook(templatefs);
>        wb.write(result);
>       }
>               catch (IOException e) {
>       }
> 
> 
>       }
> 
> 
> 
> 
> Dr. Martin Lang
> Cortex Brainware GmbH
> EMail: [EMAIL PROTECTED]





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

Reply via email to