- package
util; -
- import
java.io.IOException; - import
java.io.InputStream; -
- import
org.apache.poi.openxml4j.opc.OPCPackage; - import
org.apache.poi.xwpf.usermodel.XWPFDocument; - import
org.apache.xmlbeans.XmlException; - import
org.apache.xmlbeans.XmlToken; - import
org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; - import
org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D; - import
org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline; -
-
- public
class CustomXWPFDocument extends XWPFDocument { -
public CustomXWPFDocument(InputStream in) throws IOException { -
super(in); -
} -
-
-
public CustomXWPFDocument() { -
super(); -
// TODO Auto-generated constructor stub -
} -
-
-
public CustomXWPFDocument(OPCPackage pkg) throws IOException { -
super(pkg); -
// TODO Auto-generated constructor stub -
} -
-
public void createPicture(int id, int width, int height) { -
final int EMU = 9525; -
width *= EMU; -
height *= EMU; -
String blipId = getAllPictures().get(id).getPackageRelationship() -
.getId(); -
-
CTInline inline = createParagraph().createRun().getCTR() -
.addNewDrawing().addNewInline(); -
-
String picXml = "" -
+ "" -
+ " " -
+ " " -
+ " " + " -
+ id -
+ "\" name=\"Generated\"/>" -
+ " " -
+ " " -
+ " " -
+ " -
+ blipId -
+ "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>" -
+ " " -
+ " " -
+ " " -
+ " " -
+ " " -
+ " " -
+ " " -
+ " -
+ width -
+ "\" cy=\"" -
+ height -
+ "\"/>" -
+ " " -
+ " " -
+ " " -
+ " " -
+ " " -
+ " " -
+ " " + ""; -
-
// CTGraphicalObjectData graphicData = -
inline.addNewGraphic().addNewGraphicData(); -
XmlToken xmlToken = null; -
try { -
xmlToken = XmlToken.Factory.parse(picXml); -
} catch (XmlException xe) { -
xe.printStackTrace(); -
} -
inline.set(xmlToken); -
// graphicData.set(xmlToken); -
-
inline.setDistT(0); -
inline.setDistB(0); -
inline.setDistL(0); -
inline.setDistR(0); -
-
CTPositiveSize2D extent = inline.addNewExtent(); -
extent.setCx(width); -
extent.setCy(height); -
-
CTNonVisualDrawingProps docPr = inline.addNewDocPr(); -
docPr.setId(id); -
docPr.setName("图片" + id); -
docPr.setDescr("现场监理图片"); -
} - }
-
poi导出word[1]
最新推荐文章于 2022-06-08 17:43:46 发布