需求:查看官网的 doc java 能够进行图片插入,但具体位置不知如何控制
参考code如下:
- Code: Select all
//Create a Document object
Document doc = new Document();
doc.loadFromStream(sourceFile.getInputStream(),FileFormat.Auto);
//Add a section
Section section = doc.addSection();
//Add a paragraph to the section
//Add another paragraph to the section
Paragraph paragraph2 = section.addParagraph();
//Append an image from local file to the paragraph
DocPicture picture = paragraph2.appendPicture("C:\\Users\\Administrator\\Desktop\\sign.png");
//Set image width
picture.setWidth(50f);
//Set image height
picture.setHeight(50f);
//Set horizontal alignment for paragraph 1 and paragraph 2
paragraph2.getFormat().setHorizontalAlignment(HorizontalAlignment.Right);
//Save the Document object
doc.saveToFile("C:\\InsertImage.docx", FileFormat.Docx_2010);
目标:需要具体api实现或demo