From 802165ecd0cf8ae6590e751ce7d02c13ca3919a9 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 23 Oct 2021 09:27:35 +0000 Subject: add XSLFPictureShape setName git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894505 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xslf/usermodel/XSLFPictureShape.java | 37 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'poi-ooxml/src/main/java') diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java index 9205a74112..c011c5db98 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java @@ -282,17 +282,44 @@ public class XSLFPictureShape extends XSLFSimpleShape XmlObject xmlObject = getXmlObject(); if (xmlObject instanceof CTPicture) { CTPicture ctPicture = (CTPicture)xmlObject; - CTPictureNonVisual nvSpPr = ctPicture.getNvPicPr(); - if (nvSpPr != null) { - CTNonVisualDrawingProps cnv = nvSpPr.getCNvPr(); - if (cnv != null) { - name = cnv.getName(); + CTPictureNonVisual nvPicPr = ctPicture.getNvPicPr(); + if (nvPicPr != null) { + CTNonVisualDrawingProps cnvdProps = nvPicPr.getCNvPr(); + if (cnvdProps != null) { + name = cnvdProps.getName(); } } } return name; } + /** + * @param name picture name + * @return returns true if the name was set + * @since POI 5.1.0 + */ + public boolean setName(String name) { + XmlObject xmlObject = getXmlObject(); + if (xmlObject instanceof CTPicture) { + CTPicture ctPicture = (CTPicture)xmlObject; + CTPictureNonVisual nvPicPr = ctPicture.getNvPicPr(); + if (nvPicPr == null) { + nvPicPr = ctPicture.addNewNvPicPr(); + } + if (nvPicPr != null) { + CTNonVisualDrawingProps cnvdProps = nvPicPr.getCNvPr(); + if (cnvdProps == null) { + cnvdProps = nvPicPr.addNewCNvPr(); + } + if (cnvdProps != null) { + cnvdProps.setName(name); + return true; + } + } + } + return false; + } + /** * @return SVG image data -- can return null if no SVG image is found */ -- cgit v1.2.3