You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by anshkumar <an...@gmail.com> on 2020/05/30 15:34:25 UTC

Apache POI unable to open embedded files

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

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Apache POI unable to open embedded files

Posted by Dominik Stadler <do...@gmx.at>.
Hi,

You can create one document via Excel which works and another one via
Apache POI which does not work for you and then compare the xml-files in
the .xlsx-files (you can unzip it as it is a Zip-file).

This way you can check how Excel itself stores such embedded objects and
how you need to build the file via POI to simulate this.

Dominik.

On Sat, May 30, 2020 at 5:34 PM anshkumar <an...@gmail.com>
wrote:

> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>