[Solved] Attaching ott file into odt file using macro
[Solved] Attaching ott file into odt file using macro
Can anybody help me, how can I attach ott file[which contains some custom styles] into odt file using macro.
Last edited by Hagar Delest on Wed Jan 12, 2011 1:53 pm, edited 1 time in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
OpenOffice 3.1 on Windows XP
Re: Attaching ott file into odt file using macro
See OOo Help:
"Using Styles From Another Document or Template "
And see:
http://user.services.openoffice.org/en/ ... es#p169079
"Using Styles From Another Document or Template "
And see:
http://user.services.openoffice.org/en/ ... es#p169079
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: Attaching ott file into odt file using macro
Thank you! I can load the styles using menu, but I want to do it via macro, is there any option?
OpenOffice 3.1 on Windows XP
Re: Attaching ott file into odt file using macro
You can modify the properties of styles (Page Styles, Paragraph Styles Character Styles) by Basic SUBs. There is an example for modify PAGESTYLE. See attached "Running_head_macro.ods" in link below That is an ods example, but for Writer you need very similar one:
http://user.services.openoffice.org/en/ ... 20&t=32063
and see:
http://user.services.openoffice.org/en/ ... 20&t=31913
(Maybe those pages will help you.)
http://user.services.openoffice.org/en/ ... 20&t=32063
and see:
http://user.services.openoffice.org/en/ ... 20&t=31913
(Maybe those pages will help you.)
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: Attaching ott file into odt file using macro
This extension use macros to import styles from a different template, it seems (I've never used it):
Template Changer
Template Changer
There are two types of people: those who believe that there are two types of people and those who do not.
openSUSE Leap with KDE Plasma / LibreOffice
openSUSE Leap with KDE Plasma / LibreOffice
Re: Attaching ott file into odt file using macro
CMohua, maybe you should describe a bit more in detail what you mean when you say "attach .ott file" into .odt? Is it what you mentioned in your second post "loading styles from the menu"?
Conceptually there can only be one template file for a document. That's specified in the file meta.xml inside the .odt zip archive: Typcically the second last line:
Technically you can exchange a template by simply changing the xlink:href and xlink:title attribute. That's actually what the Template-Changer extension does for you. But it does this with some additional checks. Existing style definitions (paragraph styles, character styles, page styles, ..
with the same name (all the pre-existing ones at least) will be overwritten with the style setting from the new template. Other styles, with names that are not used in the new template, will still continue to exist in the .odt document. So that's a merge or a union of all the styles in the new template and the document.
You might think "Great, so I simply continue this procedure with the third and the fourth and all following templates and all the style definitions will be collected in my .odt document." But that's a wrong assumption, styles from the template will only be copied or referenced in the .odt document when the style is actually used for some text content in the document. If you have a paragraph style "Very-clever-indentation" in the Template2, you apply this template with the template changer, but you don't use such a paragraph in your content, the "Very-clever-indentation" style will vanish from the document when you use the Template Changer extension again and apply Template-3.
By the way, as RGB mentioned, the Extension uses macros and it is good macro code, so you might have a look at it and learn how to use it. It also takes care of the outline numbering. Something on which you can find many threads in the Writer forum that mention that the menu or F11-Stylist command "Load Styles" did spoil outline or list numbering.
Conceptually there can only be one template file for a document. That's specified in the file meta.xml inside the .odt zip archive: Typcically the second last line:
Code: Select all
<meta:template xlink:type="simple" xlink:href="../otherTemplate.ott" xlink:title="" ../>

You might think "Great, so I simply continue this procedure with the third and the fourth and all following templates and all the style definitions will be collected in my .odt document." But that's a wrong assumption, styles from the template will only be copied or referenced in the .odt document when the style is actually used for some text content in the document. If you have a paragraph style "Very-clever-indentation" in the Template2, you apply this template with the template changer, but you don't use such a paragraph in your content, the "Very-clever-indentation" style will vanish from the document when you use the Template Changer extension again and apply Template-3.
By the way, as RGB mentioned, the Extension uses macros and it is good macro code, so you might have a look at it and learn how to use it. It also takes care of the outline numbering. Something on which you can find many threads in the Writer forum that mention that the menu or F11-Stylist command "Load Styles" did spoil outline or list numbering.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Re: Attaching ott file into odt file using macro
Actually similar to attaching style template in MS word, I need to use it in openoffice.
I have found some code like this
--------------------------------------------------------------------------------------------------------------
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "FileName"
args1(0).Value = "file:///C:/temp/style.ott"
args1(1).Name = "Flags"
args1(1).Value = 21
dispatcher.executeDispatch(document, ".uno:LoadStyles", "", 0, args1())
--------------------------------------------------------------------------------------------------------------
But it is not loading the custom styles into the current file
I have found some code like this
--------------------------------------------------------------------------------------------------------------
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "FileName"
args1(0).Value = "file:///C:/temp/style.ott"
args1(1).Name = "Flags"
args1(1).Value = 21
dispatcher.executeDispatch(document, ".uno:LoadStyles", "", 0, args1())
--------------------------------------------------------------------------------------------------------------
But it is not loading the custom styles into the current file
OpenOffice 3.1 on Windows XP
Re: Attaching ott file into odt file using macro
Based on what do you make your judgement? Looking at the code it looks a lot like a macro that was recorded when using "Load Styles" from the F11/Stylist (the upper right icon). Though I wasn't able to record this operation. Maybe it is possible with a different version then mine?!CMohua wrote:But it is not loading the custom styles into the current file
Please note that there are checkbox options for the categories of styles, that should be imported from the file. And the default is Text styles (Paragraph and Character) only, and not to overwrite existing ones. Frankly I have no clue what the "magic" value 21 in your code means ... but my stomach feeling tells me that it simply reflects the default for this dialog.
The best way to check if styles are imported is to import from a file that has "very exclusive" Custom Styles and then later on change in the Stylist from "All Styles" to "Custom Styles".
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Re: Attaching ott file into odt file using macro
Thanks for the entire help.
My problem has been solved by changing the FileName argument.
My problem has been solved by changing the FileName argument.
OpenOffice 3.1 on Windows XP