OpenOffice Calc macro: check if a sheet exists

   oCalcDoc = ThisComponent 
   oSheets = oCalcDoc.getSheets() 

   If oSheets.hasByName( "Sheet2" ) Then 
      MsgBox( "This spreadsheet DOES have a sheet named Sheet2." ) 
   EndIf 

   If oSheets.hasByName( "MeowMix" ) Then 
      MsgBox( "This spreadsheet DOES have a sheet named MeowMix." ) 
   EndIf 

   oSheet = oSheets.getByName( "Sheet2" ) 
   ' Change cell B2 
   oSheet.getCellByPosition( 1, 1 ).setFormula( "July" ) 
   ' Change cell C2 
   oSheet.getCellByPosition( 2, 1 ).setValue( 2856 )

Reference:

check if sheet exists




Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>