前景提要
HDC调试需求开发(15万预算),能者速来!>>>
我在使用POI解析word文档时,发现了一个问题,POI在解析图片、表格和文本时是分开的,因此,当我解析完图片、文本、表格后,就不知道图片在文本的那个位置。如下:
public static List<String> getWordContent2007(String path) throws IOException, XmlException, OpenXML4JException { InputStream is = new FileInputStream(path); List<String> list = new ArrayList<String>(); XWPFDocument doc1 = new XWPFDocument(is); List<XWPFParagraph> paras = doc1.getParagraphs(); // 创建图片容器 List<XWPFPictureData> picEs = doc1.getAllPictures(); for (XWPFPictureData pic : picEs) { System.out.println(pic.getPictureType() + File.separator + pic.suggestFileExtension() + File.separator + pic.getFileName()); byte[] bytev = pic.getData(); FileOutputStream fos = new FileOutputStream("G:\\test\\" + pic.getFileName()); fos.write(bytev); fos.close(); } for (XWPFParagraph graph : paras) { String text = graph.getParagraphText(); String style = graph.getStyle(); // System.out.println(style); if ("1".equals(style)) { // System.out.println(text + "--[" + style + "]"); } else if ("2".equals(style)) { // System.out.println(text + "--[" + style + "]"); } else if ("3".equals(style)) { // System.out.println(text + "--[" + style + "]"); } else { System.out.println(graph.getPictureText()); } list.add(text); } return list; }
我获取了图片和内容后,想把他们按照word文件中的内容顺序组合在一起,可是 我不知道怎么获取图片和文本的位置关系。