问题描述
HWPFDocument wordDoc =新HWPFDocument(新的FileInputStream(文件名));
HWPFDocument wordDoc = new HWPFDocument(new FileInputStream(fileName));
列表picturesList = wordDoc.getPicturesTable()getAllPictures();
List picturesList = wordDoc.getPicturesTable().getAllPictures();
上面的语句给出了一个文档中的所有图片的列表。我想知道,之后在doc文/位置的图像将位于?
The above statement gives the list of all pictures inside a document. I want to know after which text/position in the doc the image will be located at?
推荐答案
你得到这些照片的错误的方式,这就是为什么你没有找到任何职位!
You're getting at the pictures the wrong way, which is why you're not finding any positions!
您需要做的是过程中的每个依次文件。传递到,并检查是否性格运行在一个图片。如果是的话,取回来从表中的图片,你知道在文档中属于它的地方,你必须从
What you need to do is process each CharacterRun of the document in turn. Pass that to the PicturesTable, and check if the character run has a picture in. If it does, fetch back the picture from the table, and you know where in the document it belongs as you have the run it comes from
在最简单的,它会是这样的:
At the simplest, it'd be something like:
PicturesTable pictureTable = document.getPicturesTable();
Range r = document.getRange();
for(int i=0; i<r.numParagraphs(); i++) {
Paragraph p = r.getParagraph(i);
for(int j=0; j<p.numCharacterRuns(); j++) {
CharacterRun cr = p.getCharacterRun(j);
if (pictureTable.hasPicture(cr)) {
Picture picture = pictures.getFor(cr);
// Do something useful with the picture
}
}
}
您可以找到在阿帕奇提卡解析器为Microsoft Word的.doc 的,这是由Apache的POI供电
You can find a good example of doing this in the Apache Tika parser for Microsoft Word .doc, which is powered by Apache POI
这篇关于如何知道的图像或画面的位置,而使用Apache POI在Java解析MS Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!