Difference between revisions of "Chart2/ChangeTitleFormattingForAllChartsInACalc"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 8: Line 8:
  
 
<code>[starbasic]
 
<code>[starbasic]
Sub Main
+
  Sub Main
changeAllChartsInCalc()
+
    changeAllChartsInCalc()
End Sub
+
  End Sub
  
sub changeAllChartsInCalc()
+
  sub changeAllChartsInCalc()
  'iterate over all charts in a calc document
+
    'iterate over all charts in a calc document
  dim oSheet as object
+
    dim oSheet as object
  dim oCharts as object  
+
    dim oCharts as object  
  SheetCount=ThisComponent.Sheets.getCount
+
    SheetCount=ThisComponent.Sheets.getCount
  SheetNo=0
+
    SheetNo=0
  while( SheetNo<SheetCount )
+
    while( SheetNo<SheetCount )
    oSheet=ThisComponent.Sheets(SheetNo)
+
      oSheet=ThisComponent.Sheets(SheetNo)
    oCharts=oSheet.Charts
+
      oCharts=oSheet.Charts
    ChartCount=oCharts.getCount
+
      ChartCount=oCharts.getCount
    ChartNo=0
+
      ChartNo=0
    while(ChartNo<ChartCount)
+
      while(ChartNo<ChartCount)
      dim oChartModel as object
+
        dim oChartModel as object
      oChartModel = oCharts(ChartNo).EmbeddedObject
+
        oChartModel = oCharts(ChartNo).EmbeddedObject
      changeOneChart( oChartModel )
+
        changeOneChart( oChartModel )
      ChartNo=ChartNo+1
+
        ChartNo=ChartNo+1
 +
      wend
 +
      SheetNo=SheetNo+1
 
     wend
 
     wend
    SheetNo=SheetNo+1
+
   end sub
   wend
+
end sub
+
  
sub changeOneChart( oChartModel as object )
+
  sub changeOneChart( oChartModel as object )
  'prevent change notifications to optimize performance
+
    'prevent change notifications to optimize performance
  oChartModel.lockControllers
+
    oChartModel.lockControllers
 
+
    ' insert a main title and set some properties
  ' insert a main title and set some properties
+
    oChartModel.HasMainTitle = True
  oChartModel.HasMainTitle = True
+
    oChartModel.Title.String = "Example Title"
  oChartModel.Title.String = "Example Title"
+
    'modify font and size
  'modify font and size
+
    oChartModel.Title.CharFontName = "Times New Roman"
  oChartModel.Title.CharFontName = "Times New Roman"
+
    oChartModel.Title.CharHeight = 14
  oChartModel.Title.CharHeight = 14
+
    'modify color
  'modify color
+
    'light gray 20% for the text for example
  'light gray 20% for the text for example
+
    oChartModel.Title.CharColor = 13421772
  oChartModel.Title.CharColor = 13421772
+
    'some blue color 'chart12' for the backround
  'some blue color 'chart12' for the backround
+
    oChartModel.Title.FillStyle = com.sun.star.drawing.FillStyle.SOLID
  oChartModel.Title.FillStyle = com.sun.star.drawing.FillStyle.SOLID
+
    oChartModel.Title.FillColor = 34001
  oChartModel.Title.FillColor = 34001
+
    'add thin black lines around
  'add thin black lines around
+
    oChartModel.Title.LineStyle = com.sun.star.drawing.LineStyle.SOLID
  oChartModel.Title.LineStyle = com.sun.star.drawing.LineStyle.SOLID
+
    oChartModel.Title.LineColor = 0
  oChartModel.Title.LineColor = 0
+
    'allow change notifications again thus the chart view gets updated when necessary
 
+
    oChartModel.unlockControllers
  'allow change notifications again thus the chart view gets updated when necessary
+
  end sub
  oChartModel.unlockControllers
+
end sub
+
 
</code>
 
</code>
 
[[Category:API]]
 
[[Category:API]]

Revision as of 12:12, 25 February 2008

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

[starbasic]

 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 = 13421772
   'some blue color 'chart12' for the backround
   oChartModel.Title.FillStyle = com.sun.star.drawing.FillStyle.SOLID
   oChartModel.Title.FillColor = 34001
   '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