List of usage examples for org.apache.poi.hpsf ClassID OLE10_PACKAGE
ClassID OLE10_PACKAGE
To view the source code for org.apache.poi.hpsf ClassID OLE10_PACKAGE.
Click Source Link
From source file:com.vodafone.poms.ii.helpers.ExportManager.java
private static String addFile(XSSFSheet sh, String filePath, double oleId) throws IOException, InvalidFormatException { File file = new File(filePath); FileInputStream fin = new FileInputStream(file); byte[] data;//from w w w.j a va 2 s . c o m data = new byte[fin.available()]; fin.read(data); Ole10Native ole10 = new Ole10Native(file.getAbsolutePath(), file.getAbsolutePath(), file.getAbsolutePath(), data); ByteArrayOutputStream bos = new ByteArrayOutputStream(500); ole10.writeOut(bos); POIFSFileSystem poifs = new POIFSFileSystem(); poifs.getRoot().createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray())); poifs.getRoot().setStorageClsid(ClassID.OLE10_PACKAGE); final PackagePartName pnOLE = PackagingURIHelper .createPartName("/xl/embeddings/oleObject" + oleId + Math.random() + ".bin"); final PackagePart partOLE = sh.getWorkbook().getPackage().createPart(pnOLE, "application/vnd.openxmlformats-officedocument.oleObject"); PackageRelationship prOLE = sh.getPackagePart().addRelationship(pnOLE, TargetMode.INTERNAL, POIXMLDocument.OLE_OBJECT_REL_TYPE); OutputStream os = partOLE.getOutputStream(); poifs.writeFilesystem(os); os.close(); poifs.close(); return prOLE.getId(); }