removed temporary fix for compatibility with Mac Excel 2008 Sp2

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@802539 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2009-08-09 13:08:59 +00:00
parent 4a1aba8ff8
commit 31161f94db
6 changed files with 8 additions and 39 deletions

View File

@ -74,36 +74,5 @@
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>

View File

@ -28,6 +28,7 @@ import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
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";

View File

@ -229,9 +229,8 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
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());
@ -253,7 +252,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
// 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){

View File

@ -169,7 +169,7 @@ public class XWPFDocument extends POIXMLDocument {
// 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){
@ -190,7 +190,7 @@ public class XWPFDocument extends POIXMLDocument {
ctDocument.addNewBody();
POIXMLProperties.ExtendedProperties expProps = getProperties().getExtendedProperties();
expProps.getUnderlyingProperties().setApplication("Microsoft Office Word");
expProps.getUnderlyingProperties().setApplication(DOCUMENT_CREATOR);
}
/**

View File

@ -261,7 +261,7 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
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);
@ -271,7 +271,7 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
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());

View File

@ -125,7 +125,7 @@ public class TestXWPFDocument extends TestCase {
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());
}
}