Difference between revisions of "Chart2/ChangeTitleFormattingForAllChartsInACalc"

From Apache OpenOffice Wiki
Jump to: navigation, search
m
(3 intermediate revisions by one other user not shown)
Line 7: Line 7:
 
|}
 
|}
  
<code>[starbasic]
+
<source lang="oobas">
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 )
 
+
    'prevent change notifications to optimize performance
sub changeOneChart( oChartModel as object )
+
    oChartModel.lockControllers
  'prevent change notifications to optimize performance
+
    ' insert a main title and set some properties
  oChartModel.lockControllers
+
    oChartModel.HasMainTitle = True
 
+
    oChartModel.Title.String = "Example Title"
  ' insert a main title and set some properties
+
    'modify font and size
  oChartModel.HasMainTitle = True
+
    oChartModel.Title.CharFontName = "Times New Roman"
  oChartModel.Title.String = "Example Title"
+
    oChartModel.Title.CharHeight = 14
  'modify font and size
+
    'modify color
  oChartModel.Title.CharFontName = "Times New Roman"
+
    'light gray 20% for the text for example
  oChartModel.Title.CharHeight = 14
+
    oChartModel.Title.CharColor = RGB(204,204,204)
  'modify color
+
    'some blue color 'chart12' for the backround
  'light gray 20% for the text for example
+
    oChartModel.Title.FillStyle = com.sun.star.drawing.FillStyle.SOLID
  oChartModel.Title.CharColor = 13421772
+
    oChartModel.Title.FillColor = RGB(00,132,209)
  'some blue color 'chart12' for the backround
+
    'add thin black lines around
  oChartModel.Title.FillStyle = com.sun.star.drawing.FillStyle.SOLID
+
    oChartModel.Title.LineStyle = com.sun.star.drawing.LineStyle.SOLID
  oChartModel.Title.FillColor = 34001
+
    oChartModel.Title.LineColor = 0
  'add thin black lines around
+
    'allow change notifications again thus the chart view gets updated when necessary
  oChartModel.Title.LineStyle = com.sun.star.drawing.LineStyle.SOLID
+
    oChartModel.unlockControllers
  oChartModel.Title.LineColor = 0
+
  end sub
 
+
</source>
  'allow change notifications again thus the chart view gets updated when necessary
+
  oChartModel.unlockControllers
+
end sub
+
</code>
+
 
[[Category:API]]
 
[[Category:API]]
 
[[Category:Samples]]
 
[[Category:Samples]]
 
[[Category:StarBasic]]
 
[[Category:StarBasic]]
 
[[Category:Chart]]
 
[[Category:Chart]]

Revision as of 02:04, 10 March 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
  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