Apache POI unable to open embedded files

anshkumar <[email protected]>
Newsgroups gmane.comp.jakarta.poi.user
Message-ID <[email protected]>
Hi,

I am trying to embed a PDF file in an excel, I am able to embed the file but
it is not opening. Excel is showing the image I had anchored to, but on
click of it, nothing happens as it is just an image.

XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream("dr.xlsx"));
FileInputStream fs = new FileInputStream("test.pdf");
FileInputStream fs1 = new FileInputStream("download.png");
int pdf = wb.addOlePackage(IOUtils.toByteArray(fs), "text.pdf", "text.pdf",
"text.pdf");
int anc = wb.addPicture(IOUtils.toByteArray(fs1),
HSSFPicture.PICTURE_TYPE_PNG);
XSSFSheet sheet = wb.getSheetAt(0);
XSSFDrawing draw = sheet.createDrawingPatriarch();
ClientAnchor anchor = draw.createAnchor(0, 0, 0, 0, 1, 2, 2, 4);
anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
XSSFObjectData objectData = draw.createObjectData(anchor, pdf, anc);
objectData.getCTShape().getNvSpPr().getCNvPr().setName( "text.pdf");
objectData.getCTShape().getNvSpPr().getCNvPr().setHidden(false);



--
Sent from: http://apache-poi.1045710.n5.nabble.com/POI-User-f2280730.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.