apache poi 3.17
XWPFDocument document = new XWPFDocument(new FileInputStream("test.docx"));
Iterator<IBodyElement> iterator = document.getBodyElementsIterator();
while (iterator.hasNext()) {
IBodyElement iBodyElement = iterator.next();
switch (iBodyElement.getElementType()) {
case PARAGRAPH:
XWPFParagraph paragraph = (XWPFParagraph) iBodyElement;
for(XWPFRun run :paragraph.getRuns()){
for(XWPFPicture picture : run.getEmbeddedPictures()){
System.out.println(picture.getPictureData().getFileName());
}
}
break;
}
}
输出
image3.png
image4.png
image5.png
image6.png
image7.png
image8.png
image9.png
image10.png
image11.png
image12.png
image13.png
image14.png
image1.emf
和image2.emf
已不复存在
document.getAllPictures()
可以获取所有图片,但它是XWPFPictureData
我想采取picture.GetCTPicture().getSpPr().getXfrm().getExt().getCx();
document.getAllPictures()
可以获得所有图片。
我找到了CTObject
,我可以得到宽度和高度。
但我怎么知道哪个CTObject
对应XWPFPictureData
?