1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
public void insertImageIntoCell(String cellName, String path) {
try {
XCell xCell = xTextTable.getCellByName(cellName);
xCellText.setString("");
XTextRange xTextRange = (XTextRange) UnoRuntime.queryInterface(
XTextRange.class, xCell);
Object graphicObjet = xDocFactory
.createInstance("com.sun.star.text.GraphicObject");
XTextContent xTextContent = (XTextContent) UnoRuntime
.queryInterface(XTextContent.class, graphicObjet);
XPropertySet xProperties = (XPropertySet) UnoRuntime
.queryInterface(XPropertySet.class, graphicObjet);
xProperties.setPropertyValue("AnchorType",
TextContentAnchorType.AS_CHARACTER);
xProperties.setPropertyValue("GraphicURL", path);
xCellText.insertTextContent(xTextRange, xTextContent, false);
} catch (Exception e) {
e.printStackTrace();
}
} |
Partager