[Solved] Open CellStyle dialog with StarBasic
[Solved] Open CellStyle dialog with StarBasic
Hello,
Some years ago there was a (unfortunately unresolved) thread about opening the CellStyle dialog via Basic, see:
viewtopic.php?f=45&t=83211
Is there a solution in the meantime?
Note:
Maybe the former questioner (Mr.Dandy) has found a solution, but unfortunately I am newly registered so that I cannot send "Mr.Dandy" a direct message.
Greetings,
joesch
Some years ago there was a (unfortunately unresolved) thread about opening the CellStyle dialog via Basic, see:
viewtopic.php?f=45&t=83211
Is there a solution in the meantime?
Note:
Maybe the former questioner (Mr.Dandy) has found a solution, but unfortunately I am newly registered so that I cannot send "Mr.Dandy" a direct message.
Greetings,
joesch
Last edited by joesch on Mon Apr 20, 2020 4:15 pm, edited 1 time in total.
OOo 3.3.0 (Windows) AOO 4.1.7 (Windows) AOO 4.x (Xubuntu)
my tips for AOO/LO (in the forum de.openoffice.info) · ProOO-Box - Information, instructions, supplementary materials about OpenOffice (german)
my tips for AOO/LO (in the forum de.openoffice.info) · ProOO-Box - Information, instructions, supplementary materials about OpenOffice (german)
Re: Open CellStyle dialog with StarBasic
It is unbelievable (because I had already tried a lot of things without success), but I just now found(*) a solution:
Greetings,
joesch
(*)
I have recorded "New template from selection" via macro recorder and received:
From this I could read the property value "Family" and combine it with ".uno:NewStyle"[/size]
Code: Select all
sub OpenCellStyleDialog_NewStyle()
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args(0) as new com.sun.star.beans.PropertyValue
args(0).Name = "Family"
args(0).Value = 2
dispatcher.executeDispatch(document, ".uno:NewStyle", "", 0, args())
end sub
Greetings,
joesch
(*)
I have recorded "New template from selection" via macro recorder and received:
Code: Select all
sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Param"
args1(0).Value = "test"
args1(1).Name = "Family"
args1(1).Value = 2
dispatcher.executeDispatch(document, ".uno:StyleNewByExample", "", 0, args1())
end sub
OOo 3.3.0 (Windows) AOO 4.1.7 (Windows) AOO 4.x (Xubuntu)
my tips for AOO/LO (in the forum de.openoffice.info) · ProOO-Box - Information, instructions, supplementary materials about OpenOffice (german)
my tips for AOO/LO (in the forum de.openoffice.info) · ProOO-Box - Information, instructions, supplementary materials about OpenOffice (german)
Re: Open CellStyle dialog with StarBasic
Here is an example code, hoy you can get the style name of the selected cell, and then edit the cell style of the selected cell (in the built-in dialog):
Just select a cell formatted by the built-in cell styles, and then click on the button (the macro is assigned to the button), but you can assign the macro to a new Menu item.
Just select a cell formatted by the built-in cell styles, and then click on the button (the macro is assigned to the button), but you can assign the macro to a new Menu item.
Code: Select all
Sub EditStyle
rem ----------------------------------------------------------------------
rem define variables
dim oDoc as object
Dim oSelection as object
Dim oSheet as object
Dim oCell as object
Dim sCellStyleName as string
dim oDispatcher as object
Dim Args1(1) as new com.sun.star.beans.PropertyValue
rem ----------------------------------------------------------------------
rem get access to the document
oDoc = ThisComponent.CurrentController.Frame
oSelection = ThisComponent.CurrentSelection
if NOT oSelection.SupportsService("com.sun.star.sheet.SheetCell") then exit sub
oCell = oSelection
sCellStyleName = oCell.CellStyle
rem Print sCellStyleName
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
Args1(0).Name = "Param"
Args1(0).Value = sCellStyleName
Args1(1).Name = "Family"
Args1(1).Value = 2
oDispatcher.executeDispatch(oDoc, ".uno:EditStyle", "", 0, Args1())
End Sub
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Open CellStyle dialog with StarBasic
Yes, interesting, but not my intention.Here is an example code, hoy you can get the style name of the selected cell, and then edit the cell style of the selected cell
OK... maybe my formulation "Open CellStyle Dialog" was irritating, but please look on the screenshot in the linked thread:
viewtopic.php?f=45&t=83211
the title of the dialog is only "Cell Style" there and that's what I was talking about. The dialog for editing an existing style has the name of the (existing) style in the title.
Greetings,
joesch
OOo 3.3.0 (Windows) AOO 4.1.7 (Windows) AOO 4.x (Xubuntu)
my tips for AOO/LO (in the forum de.openoffice.info) · ProOO-Box - Information, instructions, supplementary materials about OpenOffice (german)
my tips for AOO/LO (in the forum de.openoffice.info) · ProOO-Box - Information, instructions, supplementary materials about OpenOffice (german)
Re: Open CellStyle dialog with StarBasic
The linked dialog box layout will be appeared, when you want to CREATE a NEW STYLE. The dialog box is same, but it has different settings.
This is a different task.
You can open it
- as "StyleNewByExample": in this case the new style will inherit the properties of the example style/direct formatting properties.
- as "NewStyle": in this case there is not a sample style.
Of course the passed parameters must be different in the different cases.
Please study the API descriptions of the AOO/LO, and the Andrew Pitonyak's free macro programming books.
API: Application Programming Interface.
This is a different task.
You can open it
- as "StyleNewByExample": in this case the new style will inherit the properties of the example style/direct formatting properties.
- as "NewStyle": in this case there is not a sample style.
Of course the passed parameters must be different in the different cases.
Please study the API descriptions of the AOO/LO, and the Andrew Pitonyak's free macro programming books.
API: Application Programming Interface.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Open CellStyle dialog with StarBasic
Yes, exactly. And that's the dialog I wanted to display, not the dialog for editing an existing style.The linked dialog box layout will be appeared, when you want to CREATE a NEW STYLE.
I'm familiar with this information, I've been a volunteer (https://people.apache.org/committer-index.html#joesch) in the OO project (first OOo, now AOO) for about 15 years and have been programming in StarBasic since then.Please study the API descriptions of the AOO/LO, and the Andrew Pitonyak's free macro programming books.
Greetings,
joesch
OOo 3.3.0 (Windows) AOO 4.1.7 (Windows) AOO 4.x (Xubuntu)
my tips for AOO/LO (in the forum de.openoffice.info) · ProOO-Box - Information, instructions, supplementary materials about OpenOffice (german)
my tips for AOO/LO (in the forum de.openoffice.info) · ProOO-Box - Information, instructions, supplementary materials about OpenOffice (german)
Re: Open CellStyle dialog with StarBasic
The third button works for me in my LO 6.2.8 only, but not in my AOO 4.1.5 portable
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Open CellStyle dialog with StarBasic
Are you sure that "Param" expects a property value array?
OK, "Param" sounds like a Property-Value-Array but i think "Param" musst be a simple string as name for the new template, because that's what the macro recorder records.
The following works for me, for LO and AOO (If you want it to look better you can replace the InputBox with a dialog.):
Greetings,
joesch
OK, "Param" sounds like a Property-Value-Array but i think "Param" musst be a simple string as name for the new template, because that's what the macro recorder records.
The following works for me, for LO and AOO (If you want it to look better you can replace the InputBox with a dialog.):
Code: Select all
Sub NewStyleBasedOnASample
rem ----------------------------------------------------------------------
rem define variables
Dim oDoc as object
Dim oSelection as object
Dim oSheet as object
Dim oCell as object
Dim sCellStyleName as string
dim oDispatcher as object
Dim Args1(1) as new com.sun.star.beans.PropertyValue
rem ----------------------------------------------------------------------
rem get access to the document
oDoc = ThisComponent.CurrentController.Frame
oSelection = ThisComponent.CurrentSelection
if NOT oSelection.SupportsService("com.sun.star.sheet.SheetCell") then exit sub
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
csn = Inputbox("Please enter a name for the new cellstyle","Create cellstyle")
Args1(0).Name = "Param"
Args1(0).Value = csn
Args1(1).Name = "Family"
Args1(1).Value = 2
oDispatcher.executeDispatch(oDoc, ".uno:StyleNewByExample", "", 0, Args1())
End Sub
Greetings,
joesch
- Attachments
-
- EditAndCreateStyleII.ods
- (16.86 KiB) Downloaded 190 times
OOo 3.3.0 (Windows) AOO 4.1.7 (Windows) AOO 4.x (Xubuntu)
my tips for AOO/LO (in the forum de.openoffice.info) · ProOO-Box - Information, instructions, supplementary materials about OpenOffice (german)
my tips for AOO/LO (in the forum de.openoffice.info) · ProOO-Box - Information, instructions, supplementary materials about OpenOffice (german)
Re: [Solved] Open CellStyle dialog with StarBasic
It does even create a sub-style of the current selected style.
And it replaces the stlye when you use the same name for the same parent style twice.
Sometimes dispatch macros do the right thing without excessive coding.
And it replaces the stlye when you use the same name for the same parent style twice.
Sometimes dispatch macros do the right thing without excessive coding.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice