older HSSF supported (.xls) binary files.
</p>
</section>
- <section>
- <title>Compatibility of POI-generated .xlsx files with MS Office 2008 for Mac SP2</title>
- <p>
- Office 2008 for Mac SP2 version 12.2.0 introduced a serious bug causing some Open XML files to fail to open.
- This bug is affecting Open XML files from a variety of sources including the Apache POI project.
- The Apache POI project adjusted the XSSF module to produce "MS-compatible OOXML" by setting the Application extended property to "Microsoft Excel". This will allow users to produce OOXML documents that will work with Office 2008 for Mac SP2.
- Please see <link href="https://issues.apache.org/bugzilla/show_bug.cgi?id=47559">Bugzilla 47559</link> for more information.
- </p>
- <p>
- Users are advised to patch existing .xlsx files by the following code:
- </p>
- <source>
- XSSFWorkbook wb = new XSSFWorkbook(path);
-
- POIXMLProperties.ExtendedProperties ext = wb.getProperties().getExtendedProperties();
- expProps.getUnderlyingProperties().setApplication("Microsoft Excel");
-
- FileOutputStream out = new FileOutputStream(path);
- wb.write(out);
- out.close();
- </source>
- <p>To unset the Application property use the following code:</p>
- <source>
- POIXMLProperties.ExtendedProperties ext = workbook.getProperties().getExtendedProperties();
- expProps.getUnderlyingProperties().unsetApplication();
- </source>
- <warning>
- This is an effective workaround for a short-term bug which is likely to be removed in future versions of POI,
- when Microsoft returns to compliance with the standard. The proper value for Apache POI created documents would to be "Apache POI" and not "Microsoft Excel".
- </warning>
- </section>
</body>
</document>
import org.apache.poi.openxml4j.opc.*;
public abstract class POIXMLDocument extends POIXMLDocumentPart{
+ public static final String DOCUMENT_CREATOR = "Apache POI";
public static final String CORE_PROPERTIES_REL_TYPE = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
public static final String EXTENDED_PROPERTIES_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
bv.setActiveTab(0);
workbook.addNewSheets();
- //required by Excel 2008 Mac sp2, see Bugzilla #47559
POIXMLProperties.ExtendedProperties expProps = getProperties().getExtendedProperties();
- expProps.getUnderlyingProperties().setApplication("Microsoft Excel");
+ expProps.getUnderlyingProperties().setApplication(DOCUMENT_CREATOR);
sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.getInstance());
stylesSource = (StylesTable)createRelationship(XSSFRelation.STYLES, XSSFFactory.getInstance());
// Create main document part
pkg.createPart(corePartName, XSSFRelation.WORKBOOK.getContentType());
- pkg.getPackageProperties().setCreatorProperty("Apache POI");
+ pkg.getPackageProperties().setCreatorProperty(DOCUMENT_CREATOR);
return pkg;
} catch (Exception e){
// Create main document part
pkg.createPart(corePartName, XWPFRelation.DOCUMENT.getContentType());
- pkg.getPackageProperties().setCreatorProperty("Apache POI");
+ pkg.getPackageProperties().setCreatorProperty(DOCUMENT_CREATOR);
return pkg;
} catch (Exception e){
ctDocument.addNewBody();
POIXMLProperties.ExtendedProperties expProps = getProperties().getExtendedProperties();
- expProps.getUnderlyingProperties().setApplication("Microsoft Office Word");
+ expProps.getUnderlyingProperties().setApplication(DOCUMENT_CREATOR);
}
/**
POIXMLProperties props = workbook.getProperties();
assertNotNull(props);
//the Application property must be set for new workbooks, see Bugzilla #47559
- assertEquals("Microsoft Excel", props.getExtendedProperties().getUnderlyingProperties().getApplication());
+ assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties();
assertNotNull(opcProps);
opcProps.setCreatorProperty("poi-dev@poi.apache.org");
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
- assertEquals("Microsoft Excel", workbook.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
+ assertEquals("Apache POI", workbook.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
opcProps = workbook.getProperties().getCoreProperties().getUnderlyingProperties();
assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue());
assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue());
XWPFDocument doc = new XWPFDocument();
POIXMLProperties props = doc.getProperties();
assertNotNull(props);
- assertEquals("Microsoft Office Word", props.getExtendedProperties().getUnderlyingProperties().getApplication());
+ assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
}
}