If I open the file in poi and save it straight away without making changes, the 
problem does still happen.
Once the problem happens the xlsx file is corrupted and Excel cannot open or 
save the file.
If I open the file in Excel prior to running and do a save-as, then run the 
program it still has an error.

I re-wrote to code in just the main method to simplify.  I also re-wrote it 
avoiding the OPCPackage (which eliminates the problem).

This code generates the error:

package areacontrol;

public class AreaControl_3 {
    
    public static void main(String[] args) {
      String filename = "C:\\java\\values.xlsx";
      
      try{
          org.apache.poi.openxml4j.opc.OPCPackage opc = 
                  org.apache.poi.openxml4j.opc.OPCPackage.open(filename);
          
          org.apache.poi.xssf.usermodel.XSSFWorkbook wb = 
                  new org.apache.poi.xssf.usermodel.XSSFWorkbook(opc);
          
          opc.close();
          
          java.io.FileOutputStream fileOut = 
                  new java.io.FileOutputStream(filename);
          
          wb.write(fileOut);
          
          fileOut.close();  
          
        }catch(Exception e){
            System.out.println(e);
        }
   }
}
If I comment out the wb.write(fileOut); statement I do not get the error.

This code runs fine:

package areacontrol;

public class AreaControl_3_1 {
    
    public static void main(String[] args) {
      String filename = "C:\\java\\values.xlsx";
      
      try{          
          java.io.FileInputStream fis = 
                  new java.io.FileInputStream(filename);
          
          org.apache.poi.xssf.usermodel.XSSFWorkbook wb = 
                  new org.apache.poi.xssf.usermodel.XSSFWorkbook(fis);
          
          fis.close();
                    
          java.io.FileOutputStream fileOut = 
                  new java.io.FileOutputStream(filename);
          
          wb.write(fileOut);
          
          fileOut.close();                    
          
        }catch(Exception e){
            System.out.println(e);
        }
   }
}

Hopefully you should be able to reproduce the error on your system with the 
above code.  Please let me know if you cannot since then it would seem to be 
something with my environment.  I am using POI version poi-bin-3.8-20120326.

James


-----Original Message-----
From: Nick Burch [mailto:[email protected]] 
Sent: Friday, July 27, 2012 8:09 AM
To: POI Developers List
Subject: Re: OpenXML4JRuntimeException: Rule M2.4 exception : this error should 
NEVER happen

On Fri, 27 Jul 2012, Batchelor, James wrote:
> It is an existing file. I created a new xlsx file using Excel and 
> populated cells A1 through D4 with "A1","B1"...etc. Then I was reading 
> from a cell and writing to a cell.

If you open the file in poi, and save it straight away without making any 
changes, does the problem still happen? If you open the file in excel, and do a 
save-as, can the file then be processed by POI without error?

Nick

---------------------------------------------------------------------
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