https://issues.apache.org/bugzilla/show_bug.cgi?id=50331

           Summary: Writing HSSFWorkbook with macro causes lost macro
                    project
           Product: POI
           Version: 3.7
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: major
          Priority: P2
         Component: HSSF
        AssignedTo: [email protected]
        ReportedBy: [email protected]


Created an attachment (id=26336)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=26336)
Sample Excel file with macro

Overview: 

Opening existing HSSFWorkbook that was created using Excel and contains a macro
and then writing the workbook to a new file causes the macro project to be lost
when opening the spreadsheet in Excel.

Steps to Reproduce:

1. Create a workbook using Excel application.  Create a macro within the
workbook.
2. Access workbook in Java using new HSSFWorkbook().
3. Write the workbook (no changes need to be made) to a new file.
4. Open newly saved workbook in Excel application.  Select enabled macros when
prompted.

Actual Results: 

Excel opens and presents security warning asking whether to enable or disable
macros (this is normal).  After selecting enable macros Excel presents a dialog
that says "File not found".  Click ok on this dialog and Excel presents a new
dialog that says "Excel found unreadable content in "test out.xls".  Do you
want to recover the contents of this workbook?  If you trust the source of this
workbook, click Yes."  After clicking yes Excel presents another security
warning.  Click enable macros and a final dialog reports "Errors were detected
in "test out.xls" but Microsoft Office Excel was able to open the file by
making the repairs listed below.".  The repair listed in the dialog is "Lost
Visual Basic project".  Close this dialog.

The contents of the worksheet appear correct, but go to Tools->Macro->Visual
Basic Editor and the VBA project is gone.

Expected Results:

Excel should open the file without any errors.  The VBA project should be
accessible.

Build Date & Platform: 

POI 3.7 beta3 2010-09-24
Windows XP Service Pack 3
Microsoft Office Excel 2003 SP3 (11.8324.8324)

Additional Information: 

Attached sample Excel file.

Java sample code:

public class TestHSSF {
   public static void main(String[] args) throws IOException {
      InputStream inputFile=null;
      FileOutputStream outputFile=null;
      inputFile=new FileInputStream("C:\\Documents and
Settings\\Administrator\\Desktop\\test.xls");
      HSSFWorkbook wb=new HSSFWorkbook(new POIFSFileSystem(inputFile),false);

      outputFile=new FileOutputStream("C:\\Documents and
Settings\\Administrator\\Desktop\\test out.xls");
      wb.write(outputFile);
      outputFile.close();
      inputFile.close();
   }
}

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to