 | OO-Snippets: Automatically create a paragraph style named codeCommons| Keywords | create, paragraph, style, code |
|---|
| Language | ooRexx |
|---|
| Application | Writer |
|---|
| Authors | Josef Frysak (initial)
|
|---|
| Supported Versions | 2.4.1 |
|---|
| Supported OS | All |
|---|
| Question | How to automatically create a paragraph style with name "code"?
|
|---|
| Answer | First get a list of all paragraph styles of the current document. ("XStyleFamiliesSupplier"). Then search it for the name "code". If no paragraph style named "code" exists, create a new one using the documents "XMultiServiceFactory" interface. Next configurate the newly created paragrah style object by changing its properties. Finally add this object to the list of paragraph styles. For further details see http://wi.wu-wien.ac.at/rgf/diplomarbeiten/BakkStuff/2008/200809_Frysak/200809_Frysak_Automating_OOo_ooRexx_Nutshells.pdf. |
|---|
x_ScriptContext = uno.getScriptContext()
if (x_ScriptContext <> .nil) then
do
x_ComponentContext = x_ScriptContext~getComponentContext
x_Desktop = x_ScriptContext~getDesktop
x_Document = x_ScriptContext~getDocument
end
else
do
x_ComponentContext = UNO.connect()
service = "com.sun.star.frame.Desktop"
s_Desktop = x_ComponentContext~getServiceManager~XMultiServiceFactory~createInstance(service)
x_Desktop = s_Desktop~XDesktop
x_Document = x_Desktop~getCurrentComponent()
end
x_StyleFamiliesSupplier = x_Document~XStyleFamiliesSupplier
x_StyleFamilies = x_StyleFamiliesSupplier~getStyleFamilies()
s_StyleFamily = x_StyleFamilies~getByName("ParagraphStyles")
x_NameAccess = s_StyleFamily~XNameAccess
if x_NameAccess~hasByName("code") then
do
.bsf.dialog~messageBox('PageStyle "code" allready exists!', "ERROR", "error")
end
else
do
x_MultiServiceFactory = x_Document~XMultiServiceFactory
s_ParagraphStyle = x_MultiServiceFactory~createInstance("com.sun.star.style.ParagraphStyle")
s_ParagraphProperties = s_ParagraphStyle~XPropertySet
paracolor = .bsf~new("java.lang.Integer", X2D("FFFFCC"))
s_ParagraphProperties~setPropertyValue("ParaBackColor", paracolor)
pramargin = .bsf~new("java.lang.Integer", 500)
s_ParagraphProperties~setPropertyValue("ParaLeftMargin", pramargin)
s_ParagraphProperties~setPropertyValue("ParaRightMargin", pramargin)
o_Border = .bsf~new("com.sun.star.table.BorderLine")
o_Border~bsf.setFieldValue("Color", 0)
o_Border~bsf.setFieldValue("InnerLineWidth", 0)
o_Border~bsf.setFieldValue("OuterLineWidth", 1)
o_Border~bsf.setFieldValue("LineDistance", 0)
s_ParagraphProperties~setPropertyValue("LeftBorder", o_Border)
s_ParagraphProperties~setPropertyValue("RightBorder", o_Border)
s_ParagraphProperties~setPropertyValue("TopBorder", o_Border)
s_ParagraphProperties~setPropertyValue("BottomBorder", o_Border)
borderdist = .bsf~new("java.lang.Integer", 50)
s_ParagraphProperties~setPropertyValue("LeftBorderDistance", borderdist)
s_ParagraphProperties~setPropertyValue("RightBorderDistance", borderdist)
s_ParagraphProperties~setPropertyValue("TopBorderDistance", borderdist)
s_ParagraphProperties~setPropertyValue("BottomBorderDistance", borderdist)
s_ParagraphProperties~setPropertyValue("CharFontName", "Arial")
x_NameAccess~insertByName("code", s_ParagraphStyle)
end
::requires UNO.CLS
|
Changelog| Date | User | Modification |
|---|
| 2008-10-14 | 1 | Initial version |
|