Difference between revisions of "API/Samples/StarBasic/Impress/Insert a Chart"

From Apache OpenOffice Wiki
< API‎ | Samples‎ | StarBasic
Jump to: navigation, search
(Basic Code for creating a chart on a slide)
 
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{|
 
{|
| Snippet:              || InsertChart.BAS
+
| Description:          || Create a new [[Chart2| Chart]] object on a slide of a presentation or the page of a draw document.
|+
+
| Description:          || Create a new [[Chart2| Chart]] object on a slide of a presentation.
+
 
|+
 
|+
 
| Programming Language: || StarBasic
 
| Programming Language: || StarBasic
 
|+
 
|+
 
| Author:              || [[User:bm@openoffice.org| Björn Milcke]], 2007
 
| Author:              || [[User:bm@openoffice.org| Björn Milcke]], 2007
|+
 
| License:              || Public Domain
 
 
|}
 
|}
  
<code>[basic]
+
<source lang="oobas">
 
Sub Main
 
Sub Main
 +
    ' get the first slide
 
     Set oPage = ThisComponent.getDrawPages().getByIndex(0)
 
     Set oPage = ThisComponent.getDrawPages().getByIndex(0)
 +
    ' create an OLE2Shape
 
     Set oOLEShape = ThisComponent.createInstance( "com.sun.star.drawing.OLE2Shape" )
 
     Set oOLEShape = ThisComponent.createInstance( "com.sun.star.drawing.OLE2Shape" )
 
   
 
   
 
     ' important: first add the shape
 
     ' important: first add the shape
 
     oPage.add( oOLEShape )
 
     oPage.add( oOLEShape )
 +
 +
    Dim oPos As New com.sun.star.awt.Point
 +
    Dim oSize As New com.sun.star.awt.Size
 +
    oPos.X = 0
 +
    oPos.Y = 0
 +
    oSize.Width = 8000
 +
    oSize.Height = 7000
 +
    oOLEShape.Size = oSize
 +
    oOLEShape.Position = oPos
 
   
 
   
     ' make the OLE object a chart
+
     ' then make the OLE object a chart. The class-id is for charts, use exactly this one
 
     oOLEShape.CLSID = "12dcae26-281f-416f-a234-c3086127382e"
 
     oOLEShape.CLSID = "12dcae26-281f-416f-a234-c3086127382e"
 
   
 
   
 +
    ' get the chart's model for modification
 
     Set oChartModel = oOLEShape.Model
 
     Set oChartModel = oOLEShape.Model
 
     If Not IsNull( oChartModel ) Then
 
     If Not IsNull( oChartModel ) Then
 +
        ' e.g., Set a main title
 
         oChartModel.HasMainTitle = True
 
         oChartModel.HasMainTitle = True
 
         oChartModel.Title.String = "Created via UNO API"
 
         oChartModel.Title.String = "Created via UNO API"
 
     EndIf
 
     EndIf
 
End Sub
 
End Sub
</code>
+
</source>
 +
[[Category:API]]
 +
[[Category:Samples]]
 +
[[Category:StarBasic]]
 +
[[Category:Impress]]
 +
[[Category:Draw]]
 +
[[Category:Chart]]

Latest revision as of 13:59, 19 October 2009

Description: Create a new Chart object on a slide of a presentation or the page of a draw document.
Programming Language: StarBasic
Author: Björn Milcke, 2007
Sub Main
    ' get the first slide
    Set oPage = ThisComponent.getDrawPages().getByIndex(0)
    ' create an OLE2Shape
    Set oOLEShape = ThisComponent.createInstance( "com.sun.star.drawing.OLE2Shape" )
 
    ' important: first add the shape
    oPage.add( oOLEShape )
 
    Dim oPos As New com.sun.star.awt.Point
    Dim oSize As New com.sun.star.awt.Size
    oPos.X = 0
    oPos.Y = 0	
    oSize.Width = 8000
    oSize.Height = 7000
    oOLEShape.Size = oSize
    oOLEShape.Position = oPos
 
    ' then make the OLE object a chart. The class-id is for charts, use exactly this one
    oOLEShape.CLSID = "12dcae26-281f-416f-a234-c3086127382e"
 
    ' get the chart's model for modification
    Set oChartModel = oOLEShape.Model
    If Not IsNull( oChartModel ) Then
        ' e.g., Set a main title
        oChartModel.HasMainTitle = True
        oChartModel.Title.String = "Created via UNO API"
    EndIf
End Sub
Personal tools