aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml/src/main/java
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-10-23 09:27:35 +0000
committerPJ Fanning <fanningpj@apache.org>2021-10-23 09:27:35 +0000
commit802165ecd0cf8ae6590e751ce7d02c13ca3919a9 (patch)
treeb43cc87d3a47bda14b0cd568b93fa9880d871ca5 /poi-ooxml/src/main/java
parent03fc88b18b0a8ecab6ecaa2c8a877d5ad24a28fb (diff)
downloadpoi-802165ecd0cf8ae6590e751ce7d02c13ca3919a9.tar.gz
poi-802165ecd0cf8ae6590e751ce7d02c13ca3919a9.zip
add XSLFPictureShape setName
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894505 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src/main/java')
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java37
1 files changed, 32 insertions, 5 deletions
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,11 +282,11 @@ 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();
}
}
}
@@ -294,6 +294,33 @@ public class XSLFPictureShape extends XSLFSimpleShape
}
/**
+ * @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
*/
public XSLFPictureData getSvgImage() {