OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

access embedded objects and modify it with java

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
richard23
Guest





PostPosted: Wed Jan 28, 2004 7:41 am    Post subject: access embedded objects and modify it with java Reply with quote

Hi, i have a swriter document with a spreadsheet embedded object inside. I want to access this spreadsheet and fill it with java.
I can access embedded objects in the swriter document but I can access its in the right format to modify it.
Please help me.

Here is the code to access embedded objects :
public XNameAccess getEmbeddedObjects()
{
XTextEmbeddedObjectsSupplier xTextEmbeddedObjectsSupplier =
(XTextEmbeddedObjectsSupplier)UnoRuntime.
queryInterface(XTextEmbeddedObjectsSupplier.class, super.getDocument());
this.fEmbeddedObject = xTextEmbeddedObjectsSupplier.getEmbeddedObjects();
return this.fEmbeddedObject;
}
Back to top
altrent
General User
General User


Joined: 08 Aug 2005
Posts: 5

PostPosted: Fri Aug 19, 2005 9:40 am    Post subject: [java] Update pie chart data embedded in writer Reply with quote

Hi,

I know this post is really old, but since I spent quite a fair amount of time on the same topic I wanted to share with others how to update the data of an already existing pie chart embedded in a writer document.

Code:

    private void updatePie(XTextDocument myDoc) {
        XTextEmbeddedObjectsSupplier xTextEmbeddedObjectsSupplier =
                 (XTextEmbeddedObjectsSupplier)UnoRuntime.queryInterface(
                            XTextEmbeddedObjectsSupplier.class,
                            myDoc);
        XNameAccess xName = (XNameAccess) UnoRuntime.queryInterface(
                             XNameAccess.class,
                             xTextEmbeddedObjectsSupplier.getEmbeddedObjects());
        try {
            XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
                                    XPropertySet.class,
                                    xName.getByName("mypie" )); // put the name of your pie chart
            XChartDocument aResult = (XChartDocument) UnoRuntime.queryInterface(
                                   XChartDocument.class,
                                   xPropSet.getPropertyValue( "Model" ));
            XChartDataArray aDataArray = (XChartDataArray)
                        UnoRuntime.queryInterface(XChartDataArray.class,
                                                  aResult.getData());
            int num = 5;
            String[] description = {"Kate", "Bruce", "Ian", "Charlie", "Kilian"};
            double[] m = {10.0, 15.0, 5.0, 8.0, 62.0};
            double[][] data = new double[num][1];
            XDiagram diagram = aResult.getDiagram();
            for(int i = 0; i < data.length; i++ ) { //4
                for (int j = 0; j<data[i].length; j++) { //1
                    data[i][j] = m[i];
                }
            }
            aDataArray.setData(data);
            aDataArray.setRowDescriptions(description);

            for(int i = 0; i < data.length; i++ ) { //4
                for (int j = 0; j<data[i].length; j++) { //1
                    XPropertySet ptProp = diagram.getDataPointProperties(i, j);
                    ptProp.setPropertyValue("CharHeight", new Float(8.0));
                    ptProp.setPropertyValue("CharColor", new Integer( 0x993366 ));
                }
            }
        } catch(com.sun.star.container.NoSuchElementException x) {
            x.printStackTrace();
        } catch(com.sun.star.lang.WrappedTargetException wx) {
            wx.printStackTrace();
        } catch (com.sun.star.beans.UnknownPropertyException ux) {
            ux.printStackTrace();
        } catch (com.sun.star.lang.IndexOutOfBoundsException iobx) {
            iobx.printStackTrace();
        } catch (com.sun.star.beans.PropertyVetoException pvx) {
            pvx.printStackTrace();
        } catch (com.sun.star.lang.IllegalArgumentException iax) {
            iax.printStackTrace();
        }
    }
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group