use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class EmbeddedObjects method main.
public static void main(String[] args) throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(args[0]);
for (PackagePart pPart : workbook.getAllEmbedds()) {
String contentType = pPart.getContentType();
InputStream is = pPart.getInputStream();
Closeable document;
if (contentType.equals("application/vnd.ms-excel")) {
// Excel Workbook - either binary or OpenXML
document = new HSSFWorkbook(is);
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
// Excel Workbook - OpenXML file format
document = new XSSFWorkbook(is);
} else if (contentType.equals("application/msword")) {
// Word Document - binary (OLE2CDF) file format
document = new HWPFDocument(is);
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) {
// Word Document - OpenXML file format
document = new XWPFDocument(is);
} else if (contentType.equals("application/vnd.ms-powerpoint")) {
// PowerPoint Document - binary file format
document = new HSLFSlideShow(is);
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) {
// PowerPoint Document - OpenXML file format
document = new XMLSlideShow(is);
} else {
// Any other type of embedded object.
document = is;
}
document.close();
is.close();
}
workbook.close();
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class DrawingDump method main.
public static void main(String[] args) throws IOException {
OutputStreamWriter osw = new OutputStreamWriter(System.out, Charset.defaultCharset());
PrintWriter pw = new PrintWriter(osw);
NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(args[0]));
HSSFWorkbook wb = new HSSFWorkbook(fs);
try {
pw.println("Drawing group:");
wb.dumpDrawingGroupRecords(true);
int i = 1;
for (Sheet sheet : wb) {
pw.println("Sheet " + i + "(" + sheet.getSheetName() + "):");
((HSSFSheet) sheet).dumpDrawingRecords(true, pw);
}
} finally {
wb.close();
fs.close();
}
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestProper method testValidHSSF.
@Test
public void testValidHSSF() {
HSSFWorkbook wb = new HSSFWorkbook();
evaluator = new HSSFFormulaEvaluator(wb);
confirm(wb);
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestExcelConverterSuite method testHtml.
@Test
public void testHtml() throws Exception {
HSSFWorkbook workbook;
try {
workbook = ExcelToHtmlUtils.loadXls(child);
} catch (Exception exc) {
// unable to parse file -- not ExcelToFoConverter fault
return;
}
ExcelToHtmlConverter excelToHtmlConverter = new ExcelToHtmlConverter(XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().newDocument());
excelToHtmlConverter.processWorkbook(workbook);
StringWriter stringWriter = new StringWriter();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
transformer.setOutputProperty(OutputKeys.INDENT, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "html");
transformer.transform(new DOMSource(excelToHtmlConverter.getDocument()), new StreamResult(stringWriter));
assertNotNull(stringWriter.toString());
}
use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.
the class TestVariantSupport method newNumberTypes.
@Test
public void newNumberTypes() throws Exception {
ClipboardData cd = new ClipboardData();
cd.setValue(new byte[10]);
Object[][] exp = { { Variant.VT_CF, cd.toByteArray() }, { Variant.VT_BOOL, true }, { Variant.VT_LPSTR, "codepagestring" }, { Variant.VT_LPWSTR, "widestring" }, // int, not short ... :(
{ Variant.VT_I2, -1 }, { Variant.VT_UI2, 0xFFFF }, { Variant.VT_I4, -1 }, { Variant.VT_UI4, 0xFFFFFFFFL }, { Variant.VT_I8, -1L }, { Variant.VT_UI8, BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.TEN) }, { Variant.VT_R4, -999.99f }, { Variant.VT_R8, -999.99d } };
HSSFWorkbook wb = new HSSFWorkbook();
POIFSFileSystem poifs = new POIFSFileSystem();
DocumentSummaryInformation dsi = PropertySetFactory.newDocumentSummaryInformation();
CustomProperties cpList = new CustomProperties();
for (Object[] o : exp) {
int type = (Integer) o[0];
Property p = new Property(PropertyIDMap.PID_MAX + type, type, o[1]);
cpList.put("testprop" + type, new CustomProperty(p, "testprop" + type));
}
dsi.setCustomProperties(cpList);
dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
poifs.writeFilesystem(bos);
poifs.close();
poifs = new POIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
dsi = (DocumentSummaryInformation) PropertySetFactory.create(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
cpList = dsi.getCustomProperties();
int i = 0;
for (Object[] o : exp) {
Object obj = cpList.get("testprop" + o[0]);
if (o[1] instanceof byte[]) {
assertArrayEquals("property " + i, (byte[]) o[1], (byte[]) obj);
} else {
assertEquals("property " + i, o[1], obj);
}
i++;
}
poifs.close();
}
Aggregations