Chart2/GetPositionOfAChart

From Apache OpenOffice Wiki
Jump to: navigation, search
Description: Get the position of a chart within a spreadsheet.
Programming Language: StarBasic
Author: Ingrid Halama, 2010
Sub Main
  Dim oTableChart as Object
  Dim oPosition as Object
  Dim Message as String    
  oTableChart = ThisComponent.Sheets(0).getCharts().getByIndex(0)
  oPosition = getPositionOfChart( oTableChart )
  Message = "Chart position: x=" & oPosition.X & " y=" & oPosition.Y 
  MsgBox Message
End Sub
 
function getPositionOfChart( oTableChart as object )
  dim oShape as object 
  oShape = getShapeForChartName( oTableChart.Name, oTableChart.EmbeddedObject.Parent )
  getPositionOfChart = oShape.Position
end function
 
function getShapeForChartName( sChartName as string, oSpreadSheetDocument ) as object
  'iterate over all shapes in a calc document
  dim oSheet as object
  dim oShape as object 
  SheetCount=oSpreadSheetDocument.Sheets.getCount
  SheetNo=0
  while( SheetNo<SheetCount )
    oSheet=ThisComponent.Sheets(SheetNo)
    oDrawPage=oSheet.DrawPage
    ShapeCount=oDrawPage.getCount
    ShapeNo=0
    while(ShapeNo<ShapeCount)
      oShape = oDrawPage.getByIndex(ShapeNo)
      if( oShape.getShapeType() = "com.sun.star.drawing.OLE2Shape" ) then
        if( oShape.PersistName = sChartName ) then
          getShapeForChartName = oShape
          exit function
        endif
      endif
      ShapeNo=ShapeNo+1
    wend
    SheetNo=SheetNo+1
  wend
end function
Personal tools