2011-06-04 29 views
5

मैं टेम्पलेट से ओपनऑफिस लेखक दस्तावेज़ बनाने की कोशिश कर रहा हूं। मैं इस कोडजावा के साथ ओपनऑफिस लेखक दस्तावेज़ में कोई छवि कैसे सम्मिलित करें?

private static void searchAndReplace(final String search, 
     final String replace, final XTextDocument mxDoc) { 
    XReplaceable xReplaceable = (XReplaceable) UnoRuntime.queryInterface(
      XReplaceable.class, mxDoc); 
    XReplaceDescriptor xRepDesc = xReplaceable.createReplaceDescriptor(); 
    xRepDesc.setSearchString(search); 
    xRepDesc.setReplaceString(replace); 
    xReplaceable.replaceAll(xRepDesc); 
} 

मैं लिंक या xTextDocument में एक छवि एम्बेड करने के लिए here से कुछ नमूना कोड मिला साथ रिपोर्ट के पाठ भागों बदल सकते हैं। लेकिन, मैं xTextDocument में सम्मिलित नहीं कर सकता। जावा के साथ ऐसा करने का कोई और तरीका है? ओपनऑफिस संस्करण 3.1.0 है।

कोई जवाब?

उत्तर

1

मैं इस पाया गया: https://svn.apache.org/repos/asf/openoffice/ooo-site/trunk/content/api/Examples/Snippets/Writer/Writer.EmbedAGraphicIntoATextdocument.snip

private void embedGraphic(GraphicInfo grProps, 
      XMultiServiceFactory xMSF, XTextCursor xCursor) { 

    XNameContainer xBitmapContainer = null; 
    XText xText = xCursor.getText(); 
    XTextContent xImage = null; 
    String internalURL = null; 

    try { 
      xBitmapContainer = (XNameContainer) UnoRuntime.queryInterface(
          XNameContainer.class, xMSF.createInstance(
              "com.sun.star.drawing.BitmapTable")); 
      xImage = (XTextContent) UnoRuntime.queryInterface(
          XTextContent.class,  xMSF.createInstance(
              "com.sun.star.text.TextGraphicObject")); 
      XPropertySet xProps = (XPropertySet) UnoRuntime.queryInterface(
          XPropertySet.class, xImage); 

      // helper-stuff to let OOo create an internal name of the graphic 
      // that can be used later (internal name consists of various checksums) 
      xBitmapContainer.insertByName("someID", grProps.unoURL); 
      internalURL = AnyConverter.toString(xBitmapContainer 
          .getByName("someID")); 

      xProps.setPropertyValue("AnchorType", 
          com.sun.star.text.TextContentAnchorType.AS_CHARACTER); 
      xProps.setPropertyValue("GraphicURL", internalURL); 
      xProps.setPropertyValue("Width", (int) grProps.widthOfGraphic); 
      xProps.setPropertyValue("Height", (int) grProps.heightOfGraphic); 

      // inser the graphic at the cursor position 
      xText.insertTextContent(xCursor, xImage, false); 

      // remove the helper-entry 
      xBitmapContainer.removeByName("someID"); 
    } catch (Exception e) { 
      System.out.println("Failed to insert Graphic"); 
    } 
} 
+0

अपने आपकी प्रतिक्रिया के लिए धन्यवाद। मुझे उस समस्या के लिए एक अस्थायी समाधान मिला। यह समस्या के बाद एक लंबा समय हो गया है। मैं आपके समाधान का प्रयास करूंगा और परिणाम के बारे में आपको सूचित करूंगा। –