Java 如何从ApachePOI XSLF获取文本框的线宽?
使用ApachePOI5.0.0从pptx文件获取简单文本框的线宽的正确方法是什么?我用maven apache poi、poi ooxml和poi scratchpad创建了一个小项目 当我创建一个名为Java 如何从ApachePOI XSLF获取文本框的线宽?,java,apache-poi,xslf,Java,Apache Poi,Xslf,使用ApachePOI5.0.0从pptx文件获取简单文本框的线宽的正确方法是什么?我用maven apache poi、poi ooxml和poi scratchpad创建了一个小项目 当我创建一个名为test.pptx的pptx时,有三个文本框 无边框(宽度为0.0) 默认边框(宽度为0.75) 宽度为2.0的边框 然后输出以下代码 FileInputStream fis = new FileInputStream("test.pptx"); XMLS
test.pptx
的pptx时,有三个文本框
- 无边框(宽度为0.0)
- 默认边框(宽度为0.75)
- 宽度为2.0的边框
FileInputStream fis = new FileInputStream("test.pptx");
XMLSlideShow ppt = new XMLSlideShow(fis);
fis.close();
for (XSLFSlide slide : ppt.getSlides()) {
for (XSLFShape shape : slide.getShapes()) {
if (shape instanceof XSLFTextBox) {
XSLFTextBox textBox = (XSLFTextBox) shape;
String text = textBox.getText();
System.out.println(text);
double borderWidth = textBox.getLineWidth();
System.out.println("line: "+borderWidth+", "+textBox.getLineColor());
}
}
}
- 无边框:
行:0.0,空
- 默认值:
line:0.0,java.awt.Color[r=91,g=155,b=213]
- 边框2.0:
line:2.0,java.awt.Color[r=91,g=155,b=213]
文档中说宽度
0.0
没有边框。但是,当无边框和默认边框都返回0.0
时,如何区分它们呢。颜色不应为空。如果PowerPoint形状具有使用默认线宽的线条设置,则不会设置宽度。只有线条本身设置了颜色设置。在形状的XML
中,如下所示:
<p:sp>
...
<p:spPr>
...
<a:ln>
<a:solidFill>
<a:schemeClr val="..."/>
</a:solidFill>
</a:ln>
...
</p:spPr>
...
</p:sp>
<p:sp>
...
<p:spPr>
...
<a:ln>
<a:gradFill>
<a:gsLst>
...
</a:gsLst>
<a:lin scaled="1" ang="5400000"/>
</a:gradFill>
</a:ln>
...
</p:spPr>
...
</p:sp>
boolean isShapeLineSet(XSLFShape shape) {
boolean result = false;
org.apache.xmlbeans.XmlObject shapeXmlObjekt = shape.getXmlObject();
if (shapeXmlObjekt instanceof org.openxmlformats.schemas.presentationml.x2006.main.CTShape) {
org.openxmlformats.schemas.presentationml.x2006.main.CTShape cTShape = (org.openxmlformats.schemas.presentationml.x2006.main.CTShape)shapeXmlObjekt;
if (cTShape.getSpPr() != null) {
if (cTShape.getSpPr().getLn() != null) {
result = true;
}
}
}
return result;
}