List of usage examples for org.apache.poi.poifs.filesystem Ole10Native OLE10_NATIVE
String OLE10_NATIVE
To view the source code for org.apache.poi.poifs.filesystem Ole10Native OLE10_NATIVE.
Click Source Link
From source file:com.orange.ocara.model.export.docx.AuditDocxExporter.java
License:Mozilla Public License
/** * Create OleObject using a sample.//from ww w . j av a 2 s. co m * * @param from File to embed * @param to Destination file */ private void createOleObject(File from, File to) throws IOException, Ole10NativeException { File existingOleObject = new File(templateDirectory, "word/embeddings/oleObject.bin"); OutputStream os = null; try { // When POIFSFileSystem fs = new POIFSFileSystem(FileUtils.openInputStream(existingOleObject)); fs.getRoot().getEntry(Ole10Native.OLE10_NATIVE).delete(); Ole10Native ole = new Ole10Native(from.getName(), from.getName(), from.getName(), IOUtils.toByteArray(FileUtils.openInputStream(from))); ByteArrayOutputStream stream = new ByteArrayOutputStream(); ole.writeOut(stream); fs.getRoot().createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(stream.toByteArray())); os = FileUtils.openOutputStream(to); fs.writeFilesystem(os); } finally { IOUtils.closeQuietly(os); } }
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 v a 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(); }