openoffice中插入图片问题
用java实现做成ods文档时,如何往表格的指定位置插入图片? --------------------编程问答-------------------- 自己顶下在线等高手 --------------------编程问答-------------------- 没用过,关注! --------------------编程问答-------------------- public void insertPicsToCell(XTextDocument xDoc, String tableName,
String CellName, String[] picPaths) throws Exception {
XMultiServiceFactory xMSFDoc = (XMultiServiceFactory) UnoRuntime
.queryInte易做图ce(XMultiServiceFactory.class, xDoc);
XTextTable xTextTable = saerchTable(xDoc, tableName);
XText xTableText = (XText) UnoRuntime.queryInte易做图ce(XText.class,
xTextTable.getCellByName(CellName));
XText xText = xTableText.getText();
XTextCursor xTextCursor = xText.createTextCursor();
for (int i = 0; i < picPaths.length; i++) {
Object oGraphic = xMSFDoc
.createInstance("com.sun.star.text.TextGraphicObject");
XTextContent xTextContent = (XTextContent) UnoRuntime
.queryInte易做图ce(XTextContent.class, oGraphic);
xTextCursor.gotoEnd(false);
xText.insertTextContent(xTextCursor, xTextContent, true);
XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInte易做图ce(
XPropertySet.class, oGraphic);
File sourceFile = new File(picPaths[i]);
StringBuffer sUrl = new StringBuffer("file:///");
sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
System.out.println("insert graphic \"" + sUrl + "\"");
xPropSet.setPropertyValue("AnchorType", TextContentAnchorType.AT_PARAGRAPH_value);
xPropSet.setPropertyValue("GraphicURL", sUrl.toString());
//GraphicCrop graphicCrop = (GraphicCrop) xMSFDoc.createInstance("com.sun.star.text.GraphicCrop");
//xPropSet.setPropertyValue("GraphicCrop", graphicCrop);
// xPropSet.setPropertyValue("HoriOrientPosition", new Integer(5500 * (i + 1)));
// xPropSet.setPropertyValue("VertOrientPosition", new Integer(4200 * (i + 1)));
// xPropSet.setPropertyValue("Width", new Integer(4400));
// xPropSet.setPropertyValue("Height", new Integer(4000));
xText.insertString(xTextCursor, "\n", false);
}
} --------------------编程问答--------------------
补充:Java , Web 开发