Difference between revisions of "Documentation/DevGuide/Charts/Creating a Chart OLE Object in Draw and Impress"
m |
|||
Line 14: | Line 14: | ||
A draw page collection is obtained from the <idl>com.sun.star.drawing.XDrawPagesSupplier</idl> of a draw or presentation document. To retrieve a single draw page, use <idl>com.sun.star.container.XIndexAccess</idl>. | A draw page collection is obtained from the <idl>com.sun.star.drawing.XDrawPagesSupplier</idl> of a draw or presentation document. To retrieve a single draw page, use <idl>com.sun.star.container.XIndexAccess</idl>. | ||
− | A spreadsheet document is also a <idl>com.sun.star.drawing.XDrawPagesSupplier</idl> that provides draw pages for all sheets, that is, the draw page for the third sheet is obtained by calling <code>getByIndex(2)</code> on the interface <idl>com.sun.star.container.XIndexAccess</idl> of the container, returned by | + | A spreadsheet document is also a <idl>com.sun.star.drawing.XDrawPagesSupplier</idl> that provides draw pages for all sheets, that is, the draw page for the third sheet is obtained by calling <code>getByIndex(2)</code> on the interface <idl>com.sun.star.container.XIndexAccess</idl> of the container, returned by <idlm>com.sun.star.drawing.XDrawPagesSupplier:getDrawPages<idlm>(). |
A spreadsheet draw page can be acquired directly at the corresponding sheet object. A single sheet supports the service <idl>com.sun.star.sheet.Spreadsheet</idl> that supplies a single page, <idl>com.sun.star.drawing.XDrawPageSupplier</idl>, where the page is acquired using the method <code>getDrawPage()</code>. | A spreadsheet draw page can be acquired directly at the corresponding sheet object. A single sheet supports the service <idl>com.sun.star.sheet.Spreadsheet</idl> that supplies a single page, <idl>com.sun.star.drawing.XDrawPageSupplier</idl>, where the page is acquired using the method <code>getDrawPage()</code>. | ||
− | The {{ | + | The {{AOo}} Writer currently does not support the creation of OLE Charts or Charts based on a text table in a Writer document using the API. |
The document model is required once a chart is inserted. In charts inserted as OLE2Shape, the document model is available at the property <code>Model</code> of the OLE2Shape after setting the <code>CLSID</code>. | The document model is required once a chart is inserted. In charts inserted as OLE2Shape, the document model is available at the property <code>Model</code> of the OLE2Shape after setting the <code>CLSID</code>. | ||
Line 26: | Line 26: | ||
The following example assumes a valid drawing document in the variable <code>aDrawDoc</code> and creates a chart in a Draw document. See [[Documentation/DevGuide/Drawings/Drawing Documents and Presentation Documents|Drawing Documents and Presentation Documents]] for an example of how to create a drawing document. | The following example assumes a valid drawing document in the variable <code>aDrawDoc</code> and creates a chart in a Draw document. See [[Documentation/DevGuide/Drawings/Drawing Documents and Presentation Documents|Drawing Documents and Presentation Documents]] for an example of how to create a drawing document. | ||
<!--[SOURCE:Charts/ChartHelper.java]--> | <!--[SOURCE:Charts/ChartHelper.java]--> | ||
− | < | + | <syntaxhighlight lang="java"> |
... | ... | ||
final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e"; | final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e"; | ||
Line 82: | Line 82: | ||
} | } | ||
} | } | ||
− | </ | + | </syntaxhighlight> |
{{PDL1}} | {{PDL1}} | ||
[[Category:Documentation/Developer's Guide/Charts]] | [[Category:Documentation/Developer's Guide/Charts]] |
Revision as of 19:22, 20 December 2020
- Creating and Adding a Chart to a Spreadsheet
- Creating a Chart OLE Object in Draw and Impress
- Setting the Chart Type
- Accessing Existing Chart Documents
The alternative is to create an OLE shape and insert it into a draw page. Writer, Spreadsheet documents and Draw/Impress documents have access to a draw page. The shape is told to be a chart by setting the unique class-id.
A draw page collection is obtained from the com.sun.star.drawing.XDrawPagesSupplier of a draw or presentation document. To retrieve a single draw page, use com.sun.star.container.XIndexAccess.
A spreadsheet document is also a com.sun.star.drawing.XDrawPagesSupplier that provides draw pages for all sheets, that is, the draw page for the third sheet is obtained by calling A spreadsheet draw page can be acquired directly at the corresponding sheet object/ A single sheet supports the service com.sun.star.sheet.Spreadsheet that supplies a single page, com.sun.star.drawing.XDrawPageSupplier, where the page is acquired using the method The Apache OpenOffice Writer currently does not support the creation of OLE Charts or Charts based on a text table in a Writer document using the API/
The document model is required once a chart is inserted/ In charts inserted as OLE2Shape, the document model is available at the property The following example assumes a valid drawing document in the variable A spreadsheet draw page can be acquired directly at the corresponding sheet object/ A single sheet supports the service com.sun.star.sheet.Spreadsheet that supplies a single page, com.sun.star.drawing.XDrawPageSupplier, where the page is acquired using the method The Apache OpenOffice Writer currently does not support the creation of OLE Charts or Charts based on a text table in a Writer document using the API/
The document model is required once a chart is inserted/ In charts inserted as OLE2Shape, the document model is available at the property The following example assumes a valid drawing document in the variable getByIndex(2)
on the interface com.sun.star.container.XIndexAccess of the container, returned by getDrawPage()
/
Model
of the OLE2Shape after setting the CLSID
/
aDrawDoc
and creates a chart in a Draw document/ See for an example of how to create a drawing document/
...
final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e";
com.sun.star.frame.XModel aDrawDoc;
// get a draw document into aDrawDoc
// ...
// this will become the resulting chart
XChartDocument aChartDoc;
com.sun.star.drawing.XDrawPagesSupplier aSupplier = (com.sun.star.drawing.XDrawPagesSupplier)
UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPagesSupplier.class, aDrawDoc);
com.sun.star.drawing.XShapes aPage = null;
try {
// get first page
aPage = (com.sun.star.drawing.XShapes) aSupplier.getDrawPages().getByIndex(0);
} catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
System.out.println("Document has no pages: " + ex);
}
if (aPage != null) {
// the document should be a factory that can create shapes
XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime.queryInterface(
XMultiServiceFactory.class, aDrawDoc);
if (aFact != null) {
try {
// create an OLE 2 shape
com.sun.star.drawing.XShape aShape = (com.sun.star.drawing.XShape)
UnoRuntime.queryInterface(
com.sun.star.drawing.XShape.class,
aFact.createInstance("com.sun.star.drawing.OLE2Shape"));
// insert the shape into the page
aPage.add(aShape);
aShape.setPosition(new com.sun.star.awt.Point(1000, 1000));
aShape.setSize(new com.sun.star.awt.Size(15000, 9271));
// make the OLE shape a chart
XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, aShape );
// set the class id for charts
aShapeProp.setPropertyValue("CLSID", msChartClassID);
// retrieve the chart document as model of the OLE shape
aChartDoc = (XChartDocument) UnoRuntime.queryInterface(
XChartDocument.class,
aShapeProp.getPropertyValue("Model"));
} catch(com.sun.star.uno.Exception ex) {
System.out.println("Couldn't change the OLE shape into a chart: " + ex);
}
}
}
Content on this page is licensed under the Public Documentation License (PDL)/
getDrawPage()
/
Model
of the OLE2Shape after setting the CLSID
/
aDrawDoc
and creates a chart in a Draw document/ See Drawing Documents and Presentation Documents for an example of how to create a drawing document/
...
final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e";
com.sun.star.frame.XModel aDrawDoc;
// get a draw document into aDrawDoc
// ...
// this will become the resulting chart
XChartDocument aChartDoc;
com.sun.star.drawing.XDrawPagesSupplier aSupplier = (com.sun.star.drawing.XDrawPagesSupplier)
UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPagesSupplier.class, aDrawDoc);
com.sun.star.drawing.XShapes aPage = null;
try {
// get first page
aPage = (com.sun.star.drawing.XShapes) aSupplier.getDrawPages().getByIndex(0);
} catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
System.out.println("Document has no pages: " + ex);
}
if (aPage != null) {
// the document should be a factory that can create shapes
XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime.queryInterface(
XMultiServiceFactory.class, aDrawDoc);
if (aFact != null) {
try {
// create an OLE 2 shape
com.sun.star.drawing.XShape aShape = (com.sun.star.drawing.XShape)
UnoRuntime.queryInterface(
com.sun.star.drawing.XShape.class,
aFact.createInstance("com.sun.star.drawing.OLE2Shape"));
// insert the shape into the page
aPage.add(aShape);
aShape.setPosition(new com.sun.star.awt.Point(1000, 1000));
aShape.setSize(new com.sun.star.awt.Size(15000, 9271));
// make the OLE shape a chart
XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, aShape );
// set the class id for charts
aShapeProp.setPropertyValue("CLSID", msChartClassID);
// retrieve the chart document as model of the OLE shape
aChartDoc = (XChartDocument) UnoRuntime.queryInterface(
XChartDocument.class,
aShapeProp.getPropertyValue("Model"));
} catch(com.sun.star.uno.Exception ex) {
System.out.println("Couldn't change the OLE shape into a chart: " + ex);
}
}
}
Content on this page is licensed under the Public Documentation License (PDL)/
getDrawPage()
/
The Apache OpenOffice Writer currently does not support the creation of OLE Charts or Charts based on a text table in a Writer document using the API/
The document model is required once a chart is inserted/ In charts inserted as OLE2Shape, the document model is available at the property Model
of the OLE2Shape after setting the CLSID
/
The following example assumes a valid drawing document in the variable aDrawDoc
and creates a chart in a Draw document/ See for an example of how to create a drawing document/
... final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e"; com.sun.star.frame.XModel aDrawDoc; // get a draw document into aDrawDoc // ... // this will become the resulting chart XChartDocument aChartDoc; com.sun.star.drawing.XDrawPagesSupplier aSupplier = (com.sun.star.drawing.XDrawPagesSupplier) UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPagesSupplier.class, aDrawDoc); com.sun.star.drawing.XShapes aPage = null; try { // get first page aPage = (com.sun.star.drawing.XShapes) aSupplier.getDrawPages().getByIndex(0); } catch (com.sun.star.lang.IndexOutOfBoundsException ex) { System.out.println("Document has no pages: " + ex); } if (aPage != null) { // the document should be a factory that can create shapes XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime.queryInterface( XMultiServiceFactory.class, aDrawDoc); if (aFact != null) { try { // create an OLE 2 shape com.sun.star.drawing.XShape aShape = (com.sun.star.drawing.XShape) UnoRuntime.queryInterface( com.sun.star.drawing.XShape.class, aFact.createInstance("com.sun.star.drawing.OLE2Shape")); // insert the shape into the page aPage.add(aShape); aShape.setPosition(new com.sun.star.awt.Point(1000, 1000)); aShape.setSize(new com.sun.star.awt.Size(15000, 9271)); // make the OLE shape a chart XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, aShape ); // set the class id for charts aShapeProp.setPropertyValue("CLSID", msChartClassID); // retrieve the chart document as model of the OLE shape aChartDoc = (XChartDocument) UnoRuntime.queryInterface( XChartDocument.class, aShapeProp.getPropertyValue("Model")); } catch(com.sun.star.uno.Exception ex) { System.out.println("Couldn't change the OLE shape into a chart: " + ex); } } }
Content on this page is licensed under the Public Documentation License (PDL)/ |
A spreadsheet draw page can be acquired directly at the corresponding sheet object/ A single sheet supports the service com.sun.star.sheet.Spreadsheet that supplies a single page, com.sun.star.drawing.XDrawPageSupplier, where the page is acquired using the method getDrawPage()
/
The Apache OpenOffice Writer currently does not support the creation of OLE Charts or Charts based on a text table in a Writer document using the API/
The document model is required once a chart is inserted/ In charts inserted as OLE2Shape, the document model is available at the property Model
of the OLE2Shape after setting the CLSID
/
The following example assumes a valid drawing document in the variable aDrawDoc
and creates a chart in a Draw document/ See Drawing Documents and Presentation Documents for an example of how to create a drawing document/
... final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e"; com.sun.star.frame.XModel aDrawDoc; // get a draw document into aDrawDoc // ... // this will become the resulting chart XChartDocument aChartDoc; com.sun.star.drawing.XDrawPagesSupplier aSupplier = (com.sun.star.drawing.XDrawPagesSupplier) UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPagesSupplier.class, aDrawDoc); com.sun.star.drawing.XShapes aPage = null; try { // get first page aPage = (com.sun.star.drawing.XShapes) aSupplier.getDrawPages().getByIndex(0); } catch (com.sun.star.lang.IndexOutOfBoundsException ex) { System.out.println("Document has no pages: " + ex); } if (aPage != null) { // the document should be a factory that can create shapes XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime.queryInterface( XMultiServiceFactory.class, aDrawDoc); if (aFact != null) { try { // create an OLE 2 shape com.sun.star.drawing.XShape aShape = (com.sun.star.drawing.XShape) UnoRuntime.queryInterface( com.sun.star.drawing.XShape.class, aFact.createInstance("com.sun.star.drawing.OLE2Shape")); // insert the shape into the page aPage.add(aShape); aShape.setPosition(new com.sun.star.awt.Point(1000, 1000)); aShape.setSize(new com.sun.star.awt.Size(15000, 9271)); // make the OLE shape a chart XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, aShape ); // set the class id for charts aShapeProp.setPropertyValue("CLSID", msChartClassID); // retrieve the chart document as model of the OLE shape aChartDoc = (XChartDocument) UnoRuntime.queryInterface( XChartDocument.class, aShapeProp.getPropertyValue("Model")); } catch(com.sun.star.uno.Exception ex) { System.out.println("Couldn't change the OLE shape into a chart: " + ex); } } }
Content on this page is licensed under the Public Documentation License (PDL)/ |