You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "Kong, Yong" <Yo...@compuware.com> on 2004/09/24 21:54:38 UTC

Problem with VBScript

Hi,

I'm new to POI and I'm running into a problem that I need some help with. 
I'd like to read in an Excel template with VBScripts built in, insert/modify
some data and write out a new Excel file with the VBScripts intact. I run
the following sample program but the VBScript in Excel was corrupted. Any
ideas what caused the corruption and how to fix it? Thanks.

public class ReadWriteWorkbook
{
    public static void main(String[] args)
        throws IOException
    {
        POIFSFileSystem fs      =
                new POIFSFileSystem(new FileInputStream("c:/workbook.xls"));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row = sheet.getRow(4);
        if (row == null)
            row = sheet.createRow(4);
        HSSFCell cell = row.getCell((short)3);
        if (cell == null)
            cell = row.createCell((short)3);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue("test name");

        // Write the output to a file
        FileOutputStream fileOut = new FileOutputStream("c:/workbook.xls");
        wb.write(fileOut);
        fileOut.close();

    }
}



The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it. 


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org


RE: Problem with VBScript

Posted by Mikael Sitruk <mi...@bezeqint.net>.
Can your problem be related to the fact that you read and write on the
same file with two different streams ("c:/workbook.xls")?


> -----Original Message-----
> From: Kong, Yong [mailto:Yong.Kong@compuware.com]
> Sent: 24 September, 2004 21:55
> To: 'poi-dev@jakarta.apache.org'
> Subject: Problem with VBScript
> 
> Hi,
> 
> I'm new to POI and I'm running into a problem that I need some help
with.
> I'd like to read in an Excel template with VBScripts built in,
> insert/modify
> some data and write out a new Excel file with the VBScripts intact. I
run
> the following sample program but the VBScript in Excel was corrupted.
Any
> ideas what caused the corruption and how to fix it? Thanks.
> 
> public class ReadWriteWorkbook
> {
>     public static void main(String[] args)
>         throws IOException
>     {
>         POIFSFileSystem fs      =
>                 new POIFSFileSystem(new
> FileInputStream("c:/workbook.xls"));
>         HSSFWorkbook wb = new HSSFWorkbook(fs);
>         HSSFSheet sheet = wb.getSheetAt(0);
>         HSSFRow row = sheet.getRow(4);
>         if (row == null)
>             row = sheet.createRow(4);
>         HSSFCell cell = row.getCell((short)3);
>         if (cell == null)
>             cell = row.createCell((short)3);
>         cell.setCellType(HSSFCell.CELL_TYPE_STRING);
>         cell.setCellValue("test name");
> 
>         // Write the output to a file
>         FileOutputStream fileOut = new
> FileOutputStream("c:/workbook.xls");
>         wb.write(fileOut);
>         fileOut.close();
> 
>     }
> }
> 
> 
> 
> The contents of this e-mail are intended for the named addressee only.
It
> contains information that may be confidential. Unless you are the
named
> addressee or an authorized designee, you may not copy or use it, or
> disclose
> it to anyone else. If you received it in error please notify us
> immediately
> and then destroy it.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: poi-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org