Chart2/ChangeTitleFormattingForAllChartsInACalc

From Apache OpenOffice Wiki
< Chart2
Revision as of 02:04, 10 March 2008 by Jirong (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Description: Iterate over all charts in a spreadsheet document, insert a title and do some formatting at the title.
Programming Language: StarBasic
Author: Ingrid Halama, 2008
  Sub Main
    changeAllChartsInCalc()	
  End Sub
 
  sub changeAllChartsInCalc()
    'iterate over all charts in a calc document
    dim oSheet as object
    dim oCharts as object 
    SheetCount=ThisComponent.Sheets.getCount
    SheetNo=0
    while( SheetNo<SheetCount )
      oSheet=ThisComponent.Sheets(SheetNo)
      oCharts=oSheet.Charts
      ChartCount=oCharts.getCount
      ChartNo=0
      while(ChartNo<ChartCount)
        dim oChartModel as object
        oChartModel = oCharts(ChartNo).EmbeddedObject
        changeOneChart( oChartModel )
        ChartNo=ChartNo+1
      wend
      SheetNo=SheetNo+1
    wend
  end sub
 
  sub changeOneChart( oChartModel as object )
    'prevent change notifications to optimize performance
    oChartModel.lockControllers
    ' insert a main title and set some properties
    oChartModel.HasMainTitle = True
    oChartModel.Title.String = "Example Title"
    'modify font and size
    oChartModel.Title.CharFontName = "Times New Roman"
    oChartModel.Title.CharHeight = 14
    'modify color
    'light gray 20% for the text for example
    oChartModel.Title.CharColor = RGB(204,204,204)
    'some blue color 'chart12' for the backround
    oChartModel.Title.FillStyle = com.sun.star.drawing.FillStyle.SOLID
    oChartModel.Title.FillColor = RGB(00,132,209)
    'add thin black lines around
    oChartModel.Title.LineStyle = com.sun.star.drawing.LineStyle.SOLID
    oChartModel.Title.LineColor = 0
    'allow change notifications again thus the chart view gets updated when necessary
    oChartModel.unlockControllers
  end sub
Personal tools