Set Data->Validity in OOo Calc Macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
LinuksGuru
Posts: 36
Joined: Fri Feb 12, 2010 11:32 pm

Set Data->Validity in OOo Calc Macro

Post 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)
mauriciobaeza
Posts: 56
Joined: Thu Apr 22, 2010 5:03 am

Re: Set Data->Validity in OOo Calc Macro

Post 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
______________________________________________
Everything not given is lost
AOO 4.1 / LibO 4.3 on ArchLinux with Gnome3
Please, I do not answer private questions, you use the forum
Post Reply