Page 1 of 1

Set Data->Validity in OOo Calc Macro

Posted: Tue Apr 13, 2010 12:05 am
by LinuksGuru
Hi!

Anyone can suggest how to set data validity for cell in OO Calc (via OOoBasic Macro, of course, not manually)?
Data validity option looks like this:
1 - Ins. P-P
2 - Ins. S-S
3 - Ins. P-S
4 - None

and format of the cell (like #,##0.00 + bold/font size 9 for example)?

Thanks in advance for any suggestion(s)

Re: Set Data->Validity in OOo Calc Macro

Posted: Thu Apr 22, 2010 5:36 am
by mauriciobaeza
Hi...

The following macro sets the validation you want for the cell A1, the second macro formats the current selection.

Code: Select all

Option Explicit

Sub Validate()
Dim oCel As Object
Dim oValidation As Object

	oCel = ThisComponent.getCurrentController.getActiveSheet.getCellRangeByName( "A1" )
	oValidation = oCel.getPropertyValue("Validation")
	With oValidation
		.Type = com.sun.star.sheet.ValidationType.LIST
		.setFormula1 ( "'Ins. P-P';'Ins. S-S';'Ins. P-S';'NONE'" )
		.ShowList = com.sun.star.sheet.TableValidationVisibility.SORTEDASCENDING
		.ShowErrorMessage = True
		.ErrorAlertStyle = com.sun.star.sheet.ValidationAlertStyle.STOP
		.ErrorTitle = "Erroneous data"
		.ErrorMessage = "The value entered is not valid"
	End With 
	oCel.setPropertyValue("Validation", oValidation)		

End Sub

Sub FormatCell()
Dim oSel As Object

        oSel = ThisComponent.getCurrentSelection()           
        With oSel
                'Font Name
                .CharFontName = "Liberation Sans"
                'Size font
                .CharHeight = 20
                'Bold
                .CharWeight = 150
                'Italic
                .CharPosture = 2  
                'Underline
                .CharUnderline = 1
        End With

End Sub
Best Regards