You are viewing a plain text version of this content. The canonical link for it is here.
Posted to api@openoffice.apache.org by Jörg Schmidt <jo...@j-m-schmidt.de> on 2015/01/03 08:56:21 UTC
copy an existing style
A Happy New Year to all.
Hello,
I can access a paragraph style as follows:
the_style = ThisComponent.getStyleFamilies.getByName("ParagraphStyles").getByName("jms1")
I can also add a new style:
newStyle = ThisComponent.CreateInstance("com.sun.star.style.ParagraphStyle")
ThisComponent.getStyleFamilies.getByName("ParagraphStyles").insertByName("jms2", newStyle)
but how can I duplicate an existing style?
The following does _not_ work:
the_style = ThisComponent.getStyleFamilies.getByName("ParagraphStyles").getByName("jms1")
ThisComponent.getStyleFamilies.getByName("ParagraphStyles").insertByName("jms3", the_style)
Greetings,
Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: copy an existing style
Posted by Jörg Schmidt <jo...@j-m-schmidt.de>.
> From: LireCouleur [mailto:lirecouleur@arkaline.fr]
> Sent: Sunday, January 04, 2015 8:29 AM
> To: api@openoffice.apache.org
> Subject: Re: copy an existing style
>
> Hi Jörg. This is probably not exactly your question but if
> you want to
> copy styles from one document to another one, the function
> "loadStylesFromURL" is very useful.
> Sorry, this is Python code.
>
> url = ... # your template document URL
> try:
> ppp =
> createUnoStruct("com.sun.star.beans.PropertyValue")
> ppp.Name = "OverwriteStyles" # we don't want to
> ovewrite the existing styles with similar names
> ppp.Value = False
> res =
> xModel.getStyleFamilies().loadStylesFromURL(url,
> (ppp,))
> except:
> pass
yes, I think this is helpful.
I need to watch more detail to me first.
Greetings,
Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: copy an existing style
Posted by Oliver Brinzing <Ol...@gmx.de>.
Hi,
> res = xModel.getStyleFamilies().loadStylesFromURL(url, (ppp,))
yes, XStyleLoader should work in general but there are some limitations,
for example:
https://issues.apache.org/ooo/show_bug.cgi?id=75048
XStyleLoader - user defined number formats are not imported
Regards
Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: copy an existing style
Posted by LireCouleur <li...@arkaline.fr>.
Hi Jörg. This is probably not exactly your question but if you want to
copy styles from one document to another one, the function
"loadStylesFromURL" is very useful.
Sorry, this is Python code.
url = ... # your template document URL
try:
ppp = createUnoStruct("com.sun.star.beans.PropertyValue")
ppp.Name = "OverwriteStyles" # we don't want to
ovewrite the existing styles with similar names
ppp.Value = False
res = xModel.getStyleFamilies().loadStylesFromURL(url,
(ppp,))
except:
pass
Regards,
Marie
Le 04/01/2015 08:14, Jörg Schmidt a écrit :
>> From: Oliver Brinzing [mailto:Oliver.Brinzing@gmx.de]
>> Sent: Saturday, January 03, 2015 10:00 AM
>> To: api@openoffice.apache.org
>> Subject: Re: copy an existing style
>>
>> Hi Jörg,
>>
>> or try to set the parent style:
>>
>> newStyle.ParentStyle = oldStyle.Name
>> oStyles.insertByName("myNewStyle", newStyle)
>>
>> so newStyle inherits all properties from oldStyle
> that's very interesting, the following works here:
>
> oStyles = ThisComponent.StyleFamilies.getByName("ParagraphStyles")
> oldStyle = ThisComponent.getStyleFamilies.getByName("ParagraphStyles").getByName("jms1")
> newStyle = ThisComponent.CreateInstance("com.sun.star.style.ParagraphStyle")
> newStyle.ParentStyle = oldStyle.Name
> oStyles.insertByName("jms2", newStyle)
>
>
> But it is not so very helpful, because copying a template within a document is only a test, my true goal is to copy a template between two documents.
>
>
>
> Greetings,
> Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
> For additional commands, e-mail: api-help@openoffice.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: copy an existing style
Posted by Jörg Schmidt <jo...@j-m-schmidt.de>.
> From: Oliver Brinzing [mailto:Oliver.Brinzing@gmx.de]
> Sent: Saturday, January 03, 2015 10:00 AM
> To: api@openoffice.apache.org
> Subject: Re: copy an existing style
>
> Hi Jörg,
>
> or try to set the parent style:
>
> newStyle.ParentStyle = oldStyle.Name
> oStyles.insertByName("myNewStyle", newStyle)
>
> so newStyle inherits all properties from oldStyle
that's very interesting, the following works here:
oStyles = ThisComponent.StyleFamilies.getByName("ParagraphStyles")
oldStyle = ThisComponent.getStyleFamilies.getByName("ParagraphStyles").getByName("jms1")
newStyle = ThisComponent.CreateInstance("com.sun.star.style.ParagraphStyle")
newStyle.ParentStyle = oldStyle.Name
oStyles.insertByName("jms2", newStyle)
But it is not so very helpful, because copying a template within a document is only a test, my true goal is to copy a template between two documents.
Greetings,
Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: copy an existing style
Posted by Oliver Brinzing <Ol...@gmx.de>.
Hi Jörg,
or try to set the parent style:
newStyle.ParentStyle = oldStyle.Name
oStyles.insertByName("myNewStyle", newStyle)
so newStyle inherits all properties from oldStyle
Regards
Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: copy an existing style
Posted by Oliver Brinzing <Ol...@gmx.de>.
Hi Jörg,
> True, these questions are quite generally, but does anyone have any advice?
you can check whether your copied styles complies with the source on xml level.
open *.odt as a *.zip file, extract "styles.xml" and check whether the style properties are same.
> additionally, this question:
> Now I know that the method ".loadStylesFromURL" is to use problematic because of the following problem exists:
> https://issues.apache.org/ooo/show_bug.cgi?id=75048
> But does anyone know if there are more problems with ".loadStylesFromURL"?
just try ;-)
Regards
Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: copy an existing style
Posted by Andrew Douglas Pitonyak <an...@pitonyak.org>.
On 01/08/2015 12:55 AM, Jörg Schmidt wrote:
>
> How do I know that I really copy all the properties of every conceivable type of template (see: http://www.openoffice.org/api/docs/common/ref/com/sun/star/style/StyleFamilies.html)?
>
> Currently I know of the following 'areas':
> .NumberingRules
> .PropertySetInfo.Properties
>
> But there is more that I need to consider? How do I find these? Do I need to try everything, to be sure not to overlook anything?
>
> True, these questions are quite generally, but does anyone have any advice?
I typically rely on inspection, perhaps looking at the API docs to see
if there are any obvious properties or methods that are missed. Oh, and
if my code sees something that it is not sure what to do with, I
generally print a descriptive error message.
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info: http://www.pitonyak.org/oo.php
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: copy an existing style
Posted by Jörg Schmidt <jo...@j-m-schmidt.de>.
Hello Oliver, *,
> From: Oliver Brinzing [mailto:Oliver.Brinzing@gmx.de]
> i think you have to iterate over the "NumberingRules" Objects
> and Copy it's properties
>
> For j = 0 To oPStyle.NumberingRules.getCount()-1
> mArray() =oPStyle.NumberingRules.getByIndex(j)
> ...
> Next j
ok. Thank you.
But the following is a problem:
How do I know that I really copy all the properties of every conceivable type of template (see: http://www.openoffice.org/api/docs/common/ref/com/sun/star/style/StyleFamilies.html)?
Currently I know of the following 'areas':
.NumberingRules
.PropertySetInfo.Properties
But there is more that I need to consider? How do I find these? Do I need to try everything, to be sure not to overlook anything?
True, these questions are quite generally, but does anyone have any advice?
additionally, this question:
Now I know that the method ".loadStylesFromURL" is to use problematic because of the following problem exists:
https://issues.apache.org/ooo/show_bug.cgi?id=75048
But does anyone know if there are more problems with ".loadStylesFromURL"?
Greetings,
Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: copy an existing style
Posted by Oliver Brinzing <Ol...@gmx.de>.
Hi Jörg,
> Using the following code will _not_ transfer the setting
>"position-at" (in a german AOO "Position-bei") of an numbering style.
i think you have to iterate over the "NumberingRules" Objects and Copy it's properties
For j = 0 To oPStyle.NumberingRules.getCount()-1
mArray() =oPStyle.NumberingRules.getByIndex(j)
...
Next j
Regards
Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: copy an existing style
Posted by Jörg Schmidt <jo...@j-m-schmidt.de>.
Hello,
> From: Jörg Schmidt [mailto:joesch@j-m-schmidt.de]
> Thank You. The following works for me:
>
> Sub Vorlage_kopieren()
> ...
I use the same for numberingstyles it does not work properly.
Using the following code will _not_ transfer the setting "position-at" (in a german AOO "Position-bei") of an numbering style.
Sub Vorlage_kopieren()
On Local Error Goto ErrorHandler
Dim oDocument as Object
Dim oSheet as Object
Dim oPStyle as Object
Dim oStyles as Object
Dim oCpyStyle as Object
Dim aProperties as Object
Dim vTmp as Variant
Dim sCopy as String
Dim sX as String
Dim i as Integer
oDocument = ThisComponent
oStyles = oDocument.StyleFamilies.getByName("NumberingStyles")
oPStyle = oStyles.getByName("jms1")
sCopy = "jms2"
oCpyStyle = oDocument.createInstance("com.sun.star.style.NumberingStyle")
If oStyles.hasByName(sCopy) Then
oStyles.removeByName(sCopy)
EndIf
oStyles.insertByName(sCopy, oCpyStyle)
aProperties = oPStyle.PropertySetInfo.Properties
'XrayTool.XRAY(oPStyle)
For i = LBound(aProperties) to UBound(aProperties)
sX = aProperties(i).Name
'kk = kk & aProperties(i).Name & "|"
If Not IsNull(sX) Then
If sX <> "" Then
If oPStyle.getPropertyState(sX) = com.sun.star.beans.PropertyState.DIRECT_VALUE Then
vTmp = oPStyle.getPropertyValue(sX)
oCpyStyle.setPropertyValue(sX, vTmp)
EndIf
EndIf
EndIf
Next i
'Msgbox kk
Exit Sub
ErrorHandler:
msgbox Erl & "|" & Error & "|" & Err
Resume Next
End Sub
Greetings,
Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: copy an existing style
Posted by Jörg Schmidt <jo...@j-m-schmidt.de>.
> From: Oliver Brinzing [mailto:Oliver.Brinzing@gmx.de]
> i think you have to copy all Properties from old to new style.
> this should work for Pagestyles:
>
>
> REM ***** BASIC *****
> OPTION EXPLICIT
>
> Sub PageStyle
> [...]
Thank You. The following works for me:
Sub Vorlage_kopieren()
On Local Error Goto ErrorHandler
Dim oDocument as Object
Dim oSheet as Object
Dim oPStyle as Object
Dim oStyles as Object
Dim oCpyStyle as Object
Dim aProperties as Object
Dim vTmp as Variant
Dim sCopy as String
Dim sX as String
Dim i as Integer
oDocument = ThisComponent
oStyles = oDocument.StyleFamilies.getByName("ParagraphStyles")
oPStyle = oStyles.getByName("jms1")
sCopy = "jms2"
oCpyStyle = oDocument.createInstance("com.sun.star.style.ParagraphStyle")
If oStyles.hasByName(sCopy) Then
oStyles.removeByName(sCopy)
EndIf
oStyles.insertByName(sCopy, oCpyStyle)
aProperties = oPStyle.PropertySetInfo.Properties
For i = LBound(aProperties) to UBound(aProperties)
sX = aProperties(i).Name
If Not IsNull(sX) Then
If sX <> "" Then
If oPStyle.getPropertyState(sX) = com.sun.star.beans.PropertyState.DIRECT_VALUE Then
vTmp = oPStyle.getPropertyValue(sX)
oCpyStyle.setPropertyValue(sX, vTmp)
EndIf
EndIf
EndIf
Next i
Exit Sub
ErrorHandler:
msgbox Erl & "|" & Error & "|" & Err
Resume Next
End Sub
Greetings,
Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org
Re: copy an existing style
Posted by Oliver Brinzing <Ol...@gmx.de>.
Hi Jörg,
> the_style = ThisComponent.getStyleFamilies.getByName("ParagraphStyles").getByName("jms1")
> ThisComponent.getStyleFamilies.getByName("ParagraphStyles").insertByName("jms3", the_style)>
i think you have to copy all Properties from old to new style.
this should work for Pagestyles:
REM ***** BASIC *****
OPTION EXPLICIT
Sub PageStyle
On Local Error Goto ErrorHandler
Dim oDocument as Object
Dim oSheet as Object
Dim oPStyle as Object
Dim oStyles as Object
Dim oCpyStyle as Object
Dim aProperties as Object
Dim vTmp as Variant
Dim sCopy as String
Dim sX as String
Dim i as Integer
oDocument = ThisComponent
oSheet = oDocument.getSheets.getByIndex(0)
oStyles = oDocument.StyleFamilies.getByName("PageStyles")
oPStyle = oStyles.getByName("Default")
sCopy = "NewStyle"
oCpyStyle = oDocument.createInstance("com.sun.star.style.PageStyle")
If oStyles.hasByName(sCopy) Then
oStyles.removeByName(sCopy)
EndIf
oStyles.insertByName(sCopy, oCpyStyle)
oSheet.PageStyle = oCpyStyle.Name
aProperties = oPStyle.PropertySetInfo.Properties
For i = LBound(aProperties) to UBound(aProperties)
sX = aProperties(i).Name
If Not IsNull(sX) Then
If sX <> "" Then
If oPStyle.getPropertyState(sX) = com.sun.star.beans.PropertyState.DIRECT_VALUE Then
vTmp = oPStyle.getPropertyValue(sX)
oCpyStyle.setPropertyValue(sX, vTmp)
EndIf
EndIf
EndIf
Next i
Exit Sub
ErrorHandler:
msgbox Erl & Error & Err
Resume Next
End Sub
---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org