use of org.apache.poi.POIXMLProperties in project poi by apache.
the class WorkbookProperties method main.
public static void main(String[] args) throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
workbook.createSheet("Workbook Properties");
POIXMLProperties props = workbook.getProperties();
/**
* Extended properties are a predefined set of metadata properties
* that are specifically applicable to Office Open XML documents.
* Extended properties consist of 24 simple properties and 3 complex properties stored in the
* part targeted by the relationship of type
*/
POIXMLProperties.ExtendedProperties ext = props.getExtendedProperties();
ext.getUnderlyingProperties().setCompany("Apache Software Foundation");
ext.getUnderlyingProperties().setTemplate("XSSF");
/**
* Custom properties enable users to define custom metadata properties.
*/
POIXMLProperties.CustomProperties cust = props.getCustomProperties();
cust.addProperty("Author", "John Smith");
cust.addProperty("Year", 2009);
cust.addProperty("Price", 45.50);
cust.addProperty("Available", true);
FileOutputStream out = new FileOutputStream("workbook.xlsx");
workbook.write(out);
out.close();
workbook.close();
}
use of org.apache.poi.POIXMLProperties in project poi by apache.
the class TestXWPFDocument method testZeroLengthLibreOfficeDocumentWithWaterMarkHeader.
@Test
public void testZeroLengthLibreOfficeDocumentWithWaterMarkHeader() throws IOException {
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("zero-length.docx");
POIXMLProperties properties = doc.getProperties();
assertNotNull(properties.getCoreProperties());
XWPFHeader headerArray = doc.getHeaderArray(0);
assertEquals(1, headerArray.getAllPictures().size());
assertEquals("image1.png", headerArray.pictures.get(0).getFileName());
assertEquals("", headerArray.getText());
POIXMLProperties.ExtendedProperties extendedProperties = properties.getExtendedProperties();
assertNotNull(extendedProperties);
assertEquals(0, extendedProperties.getUnderlyingProperties().getCharacters());
doc.close();
}
use of org.apache.poi.POIXMLProperties in project poi by apache.
the class TestXSSFWorkbook method workbookProperties.
/**
* Test setting of core properties such as Title and Author
* @throws IOException
*/
@Test
public void workbookProperties() throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
try {
POIXMLProperties props = workbook.getProperties();
assertNotNull(props);
//the Application property must be set for new workbooks, see Bugzilla #47559
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties();
assertNotNull(opcProps);
opcProps.setTitleProperty("Testing Bugzilla #47460");
assertEquals("Apache POI", opcProps.getCreatorProperty().getValue());
opcProps.setCreatorProperty("poi-dev@poi.apache.org");
XSSFWorkbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(workbook);
assertEquals("Apache POI", wbBack.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
opcProps = wbBack.getProperties().getCoreProperties().getUnderlyingProperties();
assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue());
assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue());
wbBack.close();
} finally {
workbook.close();
}
}
use of org.apache.poi.POIXMLProperties in project poi by apache.
the class TestXWPFDocument method testWorkbookProperties.
@Test
public void testWorkbookProperties() throws Exception {
XWPFDocument doc = new XWPFDocument();
POIXMLProperties props = doc.getProperties();
assertNotNull(props);
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
doc.close();
}
use of org.apache.poi.POIXMLProperties in project poi by apache.
the class TestXSSFBugs method bug54764.
@Test
public void bug54764() throws IOException, OpenXML4JException, XmlException {
OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("54764.xlsx");
// Check the core properties - will be found but empty, due
// to the expansion being too much to be considered valid
POIXMLProperties props = new POIXMLProperties(pkg);
assertEquals(null, props.getCoreProperties().getTitle());
assertEquals(null, props.getCoreProperties().getSubject());
assertEquals(null, props.getCoreProperties().getDescription());
// Now check the spreadsheet itself
try {
new XSSFWorkbook(pkg).close();
fail("Should fail as too much expansion occurs");
} catch (POIXMLException e) {
// Expected
}
pkg.close();
// Try with one with the entities in the Content Types
try {
XSSFTestDataSamples.openSamplePackage("54764-2.xlsx").close();
fail("Should fail as too much expansion occurs");
} catch (Exception e) {
// Expected
}
// Check we can still parse valid files after all that
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
assertEquals(3, wb.getNumberOfSheets());
wb.close();
}
Aggregations