Re: copy an existing style

2015-01-03 Thread Jörg Schmidt

> From: LireCouleur [mailto:lirecoul...@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-unsubscr...@openoffice.apache.org
For additional commands, e-mail: api-h...@openoffice.apache.org



Re: copy an existing style

2015-01-03 Thread LireCouleur
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.brinz...@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-unsubscr...@openoffice.apache.org
For additional commands, e-mail: api-h...@openoffice.apache.org




-
To unsubscribe, e-mail: api-unsubscr...@openoffice.apache.org
For additional commands, e-mail: api-h...@openoffice.apache.org



Re: copy an existing style

2015-01-03 Thread Jörg Schmidt
> From: Oliver Brinzing [mailto:oliver.brinz...@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-unsubscr...@openoffice.apache.org
For additional commands, e-mail: api-h...@openoffice.apache.org



Re: copy an existing style

2015-01-03 Thread Jörg Schmidt
> From: Oliver Brinzing [mailto:oliver.brinz...@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-unsubscr...@openoffice.apache.org
For additional commands, e-mail: api-h...@openoffice.apache.org



Re: copy an existing style

2015-01-03 Thread Oliver Brinzing

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-unsubscr...@openoffice.apache.org
For additional commands, e-mail: api-h...@openoffice.apache.org



Re: copy an existing style

2015-01-03 Thread Oliver Brinzing

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-unsubscr...@openoffice.apache.org
For additional commands, e-mail: api-h...@openoffice.apache.org