Name
itcluno::Writer - A Writer Class for Openoffice.org's Swriter
Description
Creating, manipulating, and converting OpenOffice.org's Writer documents.
Synopsis
itcluno::Writer objectname ?options?
Inheritance
Methods
objectname appendFormula formula {propertyList ""}
appends the formula at the end of the document, optionally set properties
Return-Value:
objectname appendParagraph string {propertyList ""}
appends the string and a paragraph break at the end of the document, optionally set properties
Return-Value:
objectname appendTable rows columns
appends a TextTable to the document with $rows rows and $columns columns
Return-Value: returns a new TextTable object
objectname appendText string {propertyList ""}
appends the string at the end of the document, optionally set properties
Return-Value:
objectname exportToPdf filename
export the document to pdf
Return-Value:
objectname getNumberingStyleProperties styleName {idxList ""}
the numbering properties of a style, eventually only for the given indices in idxList (an index may be a value from 0 to 9)
Return-Value: a list of all available or the given properties
objectname getPropertyValues object {propertyList ""}
if the object handle is known you can query the (given) properties
Return-Value: a list of all available or the given properties
objectname getStyleFamilies
style families e.g. ParagraphStyle, PageStyle, ...
Return-Value: a list of all available style families
objectname getStyleProperties family style {propertyList ""}
the properties of a style within a family
Return-Value: a list of all available or the given properties
objectname getStyles family
styles like heading, title, standard within ParagraphStyle
Return-Value: a list of all available styles
objectname setNumberingStyleProperties styleName idxList propertyList
sets the specified properties for the style and the given indices (an index may be a value from 0 to 9)
Return-Value:
Examples
simple
write a simple "hallo" to the Writer document
package require itcluno
catch {itcl::delete object new_document}
itcluno::Writer new_document
new_document appendText hallo
ParagraphStyles
This examples shows all properties of all styles of all style families.
It produces about 350 pages in the writer document
package require itcluno
catch {itcl::delete object new_document}
itcluno::Writer new_document
set numberingStyleName "Numbering 5"
set paraStyle "Text body"
new_document setNumberingStyleProperties $numberingStyleName \
[list 0 1 2] \
[list Prefix "(" Suffix ")."]
set numberingStyle [list NumberingStyleName "Numbering 1" NumberingLevel %d]
set tmpFormat [concat [list ParaStyleName "Heading 1"] [format $numberingStyle 0]]
new_document appendParagraph "StyleFamilies" $tmpFormat
set familyCount 0
foreach family [lsort [new_document getStyleFamilies]] {
if {$familyCount == 0} {
set familyStartValue "NumberingStartValue 1"
incr familyCount
}
set tmpFormat [concat [list ParaStyleName "Heading 2"] [format $numberingStyle 1]]
new_document appendParagraph "$family" $tmpFormat
set styleCount 0
set counter 0
foreach style [lsort [new_document getStyles $family]] {
if {$styleCount == 0} {
set styleStartValue "NumberingStartValue 1"
incr styleCount
}
set tmpFormat [concat [list ParaStyleName "Heading 3"] [format $numberingStyle 2]]
new_document appendParagraph "$style" $tmpFormat
set props [new_document getStyleProperties $family $style]
set propList [list]
foreach {prop value} $props {
lappend propList [list $prop\t$value]
}
new_document appendParagraph [join $propList "\n"] [list ParaStyleName "Text body" NumberingStyleName ""]
incr counter
if {$counter > 1000} break
}
}
Enumeration with Graphics
This example shows the use of the enumeration capabilities of a Writer document
package require itcluno
catch {itcl::delete object new_document}
itcluno::Writer new_document
set numberingStyleName "List 1"
array set properties [new_document getNumberingStyleProperties $numberingStyleName]
parray properties
set coffeeSize [::tcluno_soffice::createSize [list 500 500]]
set arrowSize [::tcluno_soffice::createSize [list 370 190]]
array set properties [new_document getNumberingStyleProperties $numberingStyleName]
set lineBulletDir [itcluno::OfficeUtilities::filenameToURL $OOoTopDir/share/gallery/bullets]
new_document setNumberingStyleProperties $numberingStyleName \
[list 0 2] \
[list \
NumberingType 8 \
GraphicSize $arrowSize \
GraphicURL [file join $lineBulletDir coffee_5.gif] \
BulletFontName Webdings \
BulletId 227 \
BulletFont 37 \
]
unset properties
array set properties [new_document getNumberingStyleProperties $numberingStyleName [list 0 2]]
parray properties
new_document setNumberingStyleProperties $numberingStyleName \
[list 0] \
[list \
NumberingType 8 \
GraphicSize $coffeeSize \
GraphicURL [file join $lineBulletDir coffee_5.gif] \
]
new_document setNumberingStyleProperties $numberingStyleName \
[list 2] \
[list \
NumberingType 8 \
GraphicSize $arrowSize \
GraphicURL [file join $lineBulletDir bluarrow.gif] \
]
set paraStyle "Text body"
set docHandle [new_document document]
set paraTabStops [itcluno::OfficeUtilities::makeSequence [list \
[list 6000 0 [$docHandle ::tcluno::getTclunoChar [list CharClass "."]] [$docHandle ::tcluno::getTclunoChar [list CharClass "."]]] \
[list 10000 3 [$docHandle ::tcluno::getTclunoChar [list CharClass ","]] [$docHandle ::tcluno::getTclunoChar [list CharClass "-"]]] \
[list 15000 2 [$docHandle ::tcluno::getTclunoChar [list CharClass ","]] [$docHandle ::tcluno::getTclunoChar [list CharClass "-"]]] \
] com.sun.star.style.TabStop]
new_document setStyleProperties ParagraphStyles $paraStyle \
[list ParaTabStops $paraTabStops]
set numberingStyle [list \
ParaStyleName $paraStyle \
NumberingStyleName $numberingStyleName \
NumberingLevel %d\
]
new_document appendParagraph "\tThis is a numbering level 1" [eval list [format $numberingStyle 0]]
new_document appendParagraph "\tThis is level 2 of numbering\t3,1" [eval list [format $numberingStyle 1] NumberingStartValue 18]
new_document appendText "\tThis is level 2 of numbering" [eval list [format $numberingStyle 1]]
new_document appendParagraph ", but with bold addition" [list CharWeight [itcluno::OfficeUtilities::constant com.sun.star.awt.FontWeight BOLD]]
new_document appendText "\tThis is level 2 of numbering" [format $numberingStyle 1]
new_document appendParagraph ", but with red wavelike underlining" \
[list \
CharUnderlineHasColor True \
CharUnderlineColor 0xff0000 \
CharUnderline [itcluno::OfficeUtilities::constant com.sun.star.awt.FontUnderline WAVE] \
CharWeight [itcluno::OfficeUtilities::constant com.sun.star.awt.FontWeight BOLD] \
]
new_document appendParagraph "\tThis is level 2 of numbering" [format $numberingStyle 1]
new_document appendParagraph "\tThis is level 3 of numbering" [eval list [format $numberingStyle 2] NumberingStartValue 1]
new_document appendParagraph "\tThis is level 3 of numbering" [format $numberingStyle 2]
new_document appendParagraph "\tThis is again level 1 of numbering" [format $numberingStyle 0]
new_document appendParagraph "\tThis is again level 1 of numbering" [format $numberingStyle 0]
new_document appendParagraph "\tdecimal alignment\t3,1\tright aligned" [format $numberingStyle 0]
new_document appendParagraph "\tdecimal alignment\t123,1\talso right aligned" [format $numberingStyle 0]
Enumeration and Tabulators
This example shows the use of the tabulator and the enumeration capabilities of a Writer document
package require itcluno
catch {itcl::delete object new_document}
itcluno::Writer new_document
set numberingStyleName "List 1"
array set properties [new_document getNumberingStyleProperties $numberingStyleName]
parray properties
new_document setNumberingStyleProperties $numberingStyleName \
[list 0 2] \
[list \
NumberingType 6 \
BulletFontName Webdings \
BulletId 227 \
BulletFont 37 \
]
unset properties
array set properties [new_document getNumberingStyleProperties $numberingStyleName [list 0 2]]
parray properties
new_document setNumberingStyleProperties $numberingStyleName \
[list 0 2] \
[list \
NumberingType 6 \
BulletFontName Webdings \
BulletId 227 \
BulletFont 37 \
]
unset properties
array set properties [new_document getNumberingStyleProperties $numberingStyleName [list 0 2]]
parray properties
set paraStyle "Text body"
set docHandle [new_document document]
set paraTabStops [itcluno::OfficeUtilities::makeSequence [list \
[list 6000 0 [$docHandle ::tcluno::getTclunoChar [list CharClass "."]] [$docHandle ::tcluno::getTclunoChar [list CharClass "."]]] \
[list 10000 3 [$docHandle ::tcluno::getTclunoChar [list CharClass ","]] [$docHandle ::tcluno::getTclunoChar [list CharClass "-"]]] \
[list 15000 2 [$docHandle ::tcluno::getTclunoChar [list CharClass ","]] [$docHandle ::tcluno::getTclunoChar [list CharClass "-"]]] \
] com.sun.star.style.TabStop]
new_document setStyleProperties ParagraphStyles $paraStyle [list ParaTabStops $paraTabStops]
set numberingStyle [list ParaStyleName $paraStyle NumberingStyleName $numberingStyleName NumberingLevel %d]
new_document appendParagraph "\tThis is a numbering level 1" [eval list [format $numberingStyle 0]]
new_document appendParagraph "\tThis is level 2 of numbering\t3,1" [eval list [format $numberingStyle 1] NumberingStartValue 18]
new_document appendText "\tThis is level 2 of numbering" [eval list [format $numberingStyle 1]]
new_document appendParagraph ", but with bold addition" [list CharWeight [itcluno::OfficeUtilities::constant com.sun.star.awt.FontWeight BOLD]]
new_document appendText "\tThis is level 2 of numbering" [format $numberingStyle 1]
new_document appendParagraph ", but with red wavelike underlining" \
[list \
CharUnderlineHasColor True \
CharUnderlineColor 0xff0000 \
CharUnderline [itcluno::OfficeUtilities::constant com.sun.star.awt.FontUnderline WAVE] \
CharWeight [itcluno::OfficeUtilities::constant com.sun.star.awt.FontWeight BOLD] \
]
new_document appendParagraph "\tThis is level 2 of numbering" [format $numberingStyle 1]
new_document appendParagraph "\tThis is level 3 of numbering" [eval list [format $numberingStyle 2] NumberingStartValue 1]
new_document appendParagraph "\tThis is level 3 of numbering" [format $numberingStyle 2]
new_document appendParagraph "\tThis is again level 1 of numbering" [format $numberingStyle 0]
new_document appendParagraph "\tThis is again level 1 of numbering" [format $numberingStyle 0]
new_document appendParagraph "\tdecimal alignment\t3,1\tright aligned" [format $numberingStyle 0]
new_document appendParagraph "\tdecimal alignment\t123,1\talso right aligned" [format $numberingStyle 0]
Simple Numbering
This example shows the numbering capabilities of a writer document
package require itcluno
catch {itcl::delete object new_document}
itcluno::Writer new_document
set numberingStyleName "Numbering 1"
set paraStyle "Text body"
new_document setStyleProperties ParagraphStyles $paraStyle [list NumberingStyleName "Numbering 1"]
set docHandle [new_document document]
set paraTabStops [itcluno::OfficeUtilities::makeSequence [list \
[list 6000 0 [$docHandle ::tcluno::getTclunoChar [list CharClass "."]] [$docHandle ::tcluno::getTclunoChar [list CharClass "."]]] \
[list 10000 3 [$docHandle ::tcluno::getTclunoChar [list CharClass ","]] [$docHandle ::tcluno::getTclunoChar [list CharClass "-"]]] \
[list 15000 2 [$docHandle ::tcluno::getTclunoChar [list CharClass ","]] [$docHandle ::tcluno::getTclunoChar [list CharClass "-"]]] \
] com.sun.star.style.TabStop]
new_document setStyleProperties ParagraphStyles $paraStyle [list ParaTabStops $paraTabStops]
set numberingStyle [list ParaStyleName $paraStyle NumberingStyleName "Numbering 1" NumberingLevel %d]
new_document appendParagraph "\tThis is a numbering level 1" [eval list [format $numberingStyle 0]]
new_document appendParagraph "\tThis is level 2 of numbering\t3,1" [eval list [format $numberingStyle 1]]
new_document appendText "\tThis is level 2 of numbering" [eval list [format $numberingStyle 1]]
new_document appendParagraph ", but with bold addition" \
[list CharWeight [itcluno::OfficeUtilities::constant com.sun.star.awt.FontWeight BOLD]]
new_document appendText "\tThis is level 2 of numbering"
new_document appendParagraph ", but with red wavelike underlining" \
[list \
CharUnderlineHasColor True \
CharUnderlineColor 0xff0000 \
CharUnderline [itcluno::OfficeUtilities::constant com.sun.star.awt.FontUnderline WAVE] \
CharWeight [itcluno::OfficeUtilities::constant com.sun.star.awt.FontWeight BOLD] \
]
new_document appendParagraph "\tThis is level 2 of numbering" [format $numberingStyle 2]
new_document appendParagraph "\tThis is level 3 of numbering"
new_document appendParagraph "\tThis is level 3 of numbering"
new_document appendParagraph "\tThis is again level 2 of numbering" [eval list [format $numberingStyle 1]]
new_document appendParagraph "\tThis is again level 3 of numbering" [eval list [format $numberingStyle 2]]
new_document appendParagraph "\tdecimal alignment\t3,1\tright aligned"
set handle [new_document appendParagraph "\tdecimal alignment\t123,1\talso right aligned"]
new_document appendParagraph "\tThis is again numbering level 1" [eval list [format $numberingStyle 0]]
new_document setNumberingStyleProperties $numberingStyleName [list 0 1 2] [list ParentNumbering 3]
TextTable in Writer
This example creates a text table within a Writer document with "normal" text above and below
package require itcluno
catch {itcl::delete object new_document}
itcluno::Writer new_document
new_document appendText "This text will be followed by a TextTable"
set textTable [new_document appendTable 5 3]
$textTable setPropertyValues [itcluno::OfficeUtilities::tkColor2ooColor BackColor "light blue"]
$textTable setCellValue [list 0 0] \
[list \
[list "Cell 0.0" "Cell 0.1" "Cell 0.2"] \
[list "Cell 1.0" "Cell 1.1" "Cell 1.2"] \
[list "Cell 2.0" "Cell 2.1" "Cell 2.2"] \
[list "Cell 3.0" "Cell 3.1" "Cell 3.2"] \
[list "Cell 4.0" "Cell 4.1" "Cell 4.2"] \
]
new_document appendText "Here we go with more text"
Bugs
no bugs known, but of course no software is bug free. If found one, file them to the bug section on our sourceforge page.
ToDo
a lot of new features which I find useful. If you find that anything useful is missing, please let me know via the bug report
Top