Thank you for the help. That was perfect. I believe this will be enough to have a start.
These were my ideas with the document manipulation, and i believe i can work on
(1) generating an index table by grabbing the the "test case titles" from each
generated table (the content in the 2nd cell of 1st row). and inserting the index
table in page 2 of the document.
- Index for testing procedures
- TP_Index.jpg (10.33 KiB) Viewed 27715 times
2) grab the contents in findings (multiple or single row) with test case id "TP-999" and
copy them into a new document with the file name "BASILBCTRes_"<assignment alias>".doc
in a table as shown below (to me this looks like insane, and i should better use a software rather than
word processor)
This was the sample python program i got from OOo pyUNO website
I was happy with the speed of the execution when conpared to my "record macro" method.
Is there any documentation for OOo source code similar to java documentation ?
After going through this program, i wanted to know
(1) how to split a sow into cells of desired width
(2) how to generate a new row and save the document
Code: Select all
import uno
# a UNO struct later needed to create a document
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
from com.sun.star.awt import Size
from com.sun.star.lang import XMain
def insertTextIntoCell( table, cellName, text, color ):
tableText = table.getCellByName( cellName )
cursor = tableText.createTextCursor()
cursor.setPropertyValue( "CharColor", color )
tableText.setString( text )
def createTable():
"""creates a new writer document and inserts a table with some data (also known as the SWriter sample)"""
ctx = uno.getComponentContext()
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
# open a writer document
doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () )
text = doc.Text
cursor = text.createTextCursor()
text.insertString( cursor, "The first line in the newly created text document.\n", 0 )
text.insertString( cursor, "Now we are in the second line\n" , 0 )
# create a text table
table = doc.createInstance( "com.sun.star.text.TextTable" )
# with 4 rows and 4 columns
table.initialize( 4,4)
text.insertTextContent( cursor, table, 0 )
rows = table.Rows
table.setPropertyValue( "BackTransparent", uno.Bool(0) )
table.setPropertyValue( "BackColor", 13421823 )
row = rows.getByIndex(0)
row.setPropertyValue( "BackTransparent", uno.Bool(0) )
row.setPropertyValue( "BackColor", 6710932 )
textColor = 16777215
insertTextIntoCell( table, "A1", "FirstColumn", textColor )
insertTextIntoCell( table, "B1", "SecondColumn", textColor )
insertTextIntoCell( table, "C1", "ThirdColumn", textColor )
insertTextIntoCell( table, "D1", "SUM", textColor )
values = ( (22.5,21.5,121.5),
(5615.3,615.3,-615.3),
(-2315.7,315.7,415.7) )
table.getCellByName("A2").setValue(22.5)
table.getCellByName("B2").setValue(5615.3)
table.getCellByName("C2").setValue(-2315.7)
table.getCellByName("D2").setFormula("sum <A2:C2>")
table.getCellByName("A3").setValue(21.5)
table.getCellByName("B3").setValue(615.3)
table.getCellByName("C3").setValue(-315.7)
table.getCellByName("D3").setFormula("sum <A3:C3>")
table.getCellByName("A4").setValue(121.5)
table.getCellByName("B4").setValue(-615.3)
table.getCellByName("C4").setValue(415.7)
table.getCellByName("D4").setFormula("sum <A4:C4>")
cursor.setPropertyValue( "CharColor", 255 )
cursor.setPropertyValue( "CharShadowed", uno.Bool(1) )
text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
text.insertString( cursor, " This is a colored Text - blue with shadow\n" , 0 )
text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
textFrame = doc.createInstance( "com.sun.star.text.TextFrame" )
textFrame.setSize( Size(15000,400))
textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER )
text.insertTextContent( cursor, textFrame, 0 )
textInTextFrame = textFrame.getText()
cursorInTextFrame = textInTextFrame.createTextCursor()
textInTextFrame.insertString( cursorInTextFrame, "The first line in the newly created text frame.", 0 )
textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the height of the rame raises.",0)
text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
cursor.setPropertyValue( "CharColor", 65536 )
cursor.setPropertyValue( "CharShadowed", uno.Bool(0) )
text.insertString( cursor, " That's all for now !!" , 0 )
g_exportedScripts = createTable,
This is the macro i am using at the moment to automate table generation which is generated with the help of "Record Macro" function.
The macro works fine with minor inconvenience such as
(1) The width of the 1st cells of row 4 & 6 has to specifed manually during its generation. i.e the time when control reaches
to 1st cell a window will popup asking for cell width. Couple of months before i left a post in another OOo forum regarding how
to write a code for allocating cell width, and no reply yet.
(2) Eventhough. i record the table generation in a proper order, in the end the macro will generate a different one. So i need to copy the
macro of some of the actions and paste it to main macro later to generate a proper table.
Code: Select all
sub My_Table5
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(3) as new com.sun.star.beans.PropertyValue
args1(0).Name = "TableName"
args1(0).Value = "TestCase"
args1(1).Name = "Columns"
args1(1).Value = 1
args1(2).Name = "Rows"
args1(2).Value = 7
args1(3).Name = "Flags"
args1(3).Value = 9
dispatcher.executeDispatch(document, ".uno:InsertTable", "", 0, args1())
rem ----------------------------------------------------------------------
dim args2(4) as new com.sun.star.beans.PropertyValue
args2(0).Name = "CharFontName.StyleName"
args2(0).Value = ""
args2(1).Name = "CharFontName.Pitch"
args2(1).Value = 2
args2(2).Name = "CharFontName.CharSet"
args2(2).Value = -1
args2(3).Name = "CharFontName.Family"
args2(3).Value = 5
args2(4).Name = "CharFontName.FamilyName"
args2(4).Value = "Tahoma"
dispatcher.executeDispatch(document, ".uno:CharFontName", "", 0, args2())
rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Text"
args3(0).Value = "Test Case"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args3())
rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "BackgroundColor"
args4(0).Value = 15132390
dispatcher.executeDispatch(document, ".uno:BackgroundColor", "", 0, args4())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
rem ----------------------------------------------------------------------
dim args6(4) as new com.sun.star.beans.PropertyValue
args6(0).Name = "CharFontName.StyleName"
args6(0).Value = ""
args6(1).Name = "CharFontName.Pitch"
args6(1).Value = 2
args6(2).Name = "CharFontName.CharSet"
args6(2).Value = -1
args6(3).Name = "CharFontName.Family"
args6(3).Value = 5
args6(4).Name = "CharFontName.FamilyName"
args6(4).Value = "Tahoma"
dispatcher.executeDispatch(document, ".uno:CharFontName", "", 0, args6())
rem ----------------------------------------------------------------------
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "Text"
args7(0).Value = "Changes"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args7())
rem ----------------------------------------------------------------------
dim args8(0) as new com.sun.star.beans.PropertyValue
args8(0).Name = "BackgroundColor"
args8(0).Value = 16777164
dispatcher.executeDispatch(document, ".uno:BackgroundColor", "", 0, args8())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
rem ----------------------------------------------------------------------
dim args10(4) as new com.sun.star.beans.PropertyValue
args10(0).Name = "CharFontName.StyleName"
args10(0).Value = ""
args10(1).Name = "CharFontName.Pitch"
args10(1).Value = 2
args10(2).Name = "CharFontName.CharSet"
args10(2).Value = -1
args10(3).Name = "CharFontName.Family"
args10(3).Value = 5
args10(4).Name = "CharFontName.FamilyName"
args10(4).Value = "Tahoma"
dispatcher.executeDispatch(document, ".uno:CharFontName", "", 0, args10())
rem ----------------------------------------------------------------------
dim args11(2) as new com.sun.star.beans.PropertyValue
args11(0).Name = "FontHeight.Height"
args11(0).Value = 8
args11(1).Name = "FontHeight.Prop"
args11(1).Value = 100
args11(2).Name = "FontHeight.Diff"
args11(2).Value = 0
dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args11())
rem ----------------------------------------------------------------------
dim args12(2) as new com.sun.star.beans.PropertyValue
args12(0).Name = "Amount"
args12(0).Value = 2
args12(1).Name = "Horizontal"
args12(1).Value = false
args12(2).Name = "Proportional"
args12(2).Value = false
dispatcher.executeDispatch(document, ".uno:SplitCell", "", 0, args12())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SetColumnWidth", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
rem ----------------------------------------------------------------------
dim args16(4) as new com.sun.star.beans.PropertyValue
args16(0).Name = "CharFontName.StyleName"
args16(0).Value = ""
args16(1).Name = "CharFontName.Pitch"
args16(1).Value = 2
args16(2).Name = "CharFontName.CharSet"
args16(2).Value = -1
args16(3).Name = "CharFontName.Family"
args16(3).Value = 5
args16(4).Name = "CharFontName.FamilyName"
args16(4).Value = "Tahoma"
dispatcher.executeDispatch(document, ".uno:CharFontName", "", 0, args16())
rem ----------------------------------------------------------------------
dim args17(0) as new com.sun.star.beans.PropertyValue
args17(0).Name = "Text"
args17(0).Value = "Procud"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args17())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SwBackspace", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SwBackspace", "", 0, Array())
rem ----------------------------------------------------------------------
dim args20(0) as new com.sun.star.beans.PropertyValue
args20(0).Name = "Text"
args20(0).Value = "edures"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args20())
rem ----------------------------------------------------------------------
dim args21(0) as new com.sun.star.beans.PropertyValue
args21(0).Name = "BackgroundColor"
args21(0).Value = 13434879
dispatcher.executeDispatch(document, ".uno:BackgroundColor", "", 0, args21())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
rem ----------------------------------------------------------------------
dim args23(4) as new com.sun.star.beans.PropertyValue
args23(0).Name = "CharFontName.StyleName"
args23(0).Value = ""
args23(1).Name = "CharFontName.Pitch"
args23(1).Value = 2
args23(2).Name = "CharFontName.CharSet"
args23(2).Value = -1
args23(3).Name = "CharFontName.Family"
args23(3).Value = 5
args23(4).Name = "CharFontName.FamilyName"
args23(4).Value = "Tahoma"
dispatcher.executeDispatch(document, ".uno:CharFontName", "", 0, args23())
rem ----------------------------------------------------------------------
dim args24(2) as new com.sun.star.beans.PropertyValue
args24(0).Name = "FontHeight.Height"
args24(0).Value = 8
args24(1).Name = "FontHeight.Prop"
args24(1).Value = 100
args24(2).Name = "FontHeight.Diff"
args24(2).Value = 0
dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args24())
rem ----------------------------------------------------------------------
dim args25(2) as new com.sun.star.beans.PropertyValue
args25(0).Name = "Amount"
args25(0).Value = 2
args25(1).Name = "Horizontal"
args25(1).Value = false
args25(2).Name = "Proportional"
args25(2).Value = false
dispatcher.executeDispatch(document, ".uno:SplitCell", "", 0, args25())
rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:RulerBorders", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
rem ----------------------------------------------------------------------
dim args29(4) as new com.sun.star.beans.PropertyValue
args29(0).Name = "CharFontName.StyleName"
args29(0).Value = ""
args29(1).Name = "CharFontName.Pitch"
args29(1).Value = 2
args29(2).Name = "CharFontName.CharSet"
args29(2).Value = -1
args29(3).Name = "CharFontName.Family"
args29(3).Value = 5
args29(4).Name = "CharFontName.FamilyName"
args29(4).Value = "Tahoma"
dispatcher.executeDispatch(document, ".uno:CharFontName", "", 0, args29())
rem ----------------------------------------------------------------------
dim args30(0) as new com.sun.star.beans.PropertyValue
args30(0).Name = "Text"
args30(0).Value = "Conclusions"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args30())
rem ----------------------------------------------------------------------
dim args31(0) as new com.sun.star.beans.PropertyValue
args31(0).Name = "BackgroundColor"
args31(0).Value = 16764057
dispatcher.executeDispatch(document, ".uno:BackgroundColor", "", 0, args31())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:JumpToNextCell", "", 0, Array())
rem ----------------------------------------------------------------------
dim args33(4) as new com.sun.star.beans.PropertyValue
args33(0).Name = "CharFontName.StyleName"
args33(0).Value = ""
args33(1).Name = "CharFontName.Pitch"
args33(1).Value = 2
args33(2).Name = "CharFontName.CharSet"
args33(2).Value = -1
args33(3).Name = "CharFontName.Family"
args33(3).Value = 5
args33(4).Name = "CharFontName.FamilyName"
args33(4).Value = "Tahoma"
dispatcher.executeDispatch(document, ".uno:CharFontName", "", 0, args33())
rem ----------------------------------------------------------------------
dim args34(2) as new com.sun.star.beans.PropertyValue
args34(0).Name = "FontHeight.Height"
args34(0).Value = 8
args34(1).Name = "FontHeight.Prop"
args34(1).Value = 100
args34(2).Name = "FontHeight.Diff"
args34(2).Value = 0
dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args34())
rem ----------------------------------------------------------------------
dim args35(2) as new com.sun.star.beans.PropertyValue
args35(0).Name = "Amount"
args35(0).Value = 2
args35(1).Name = "Horizontal"
args35(1).Value = false
args35(2).Name = "Proportional"
args35(2).Value = false
dispatcher.executeDispatch(document, ".uno:SplitCell", "", 0, args35())
rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:RulerBorders", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:Save", "", 0, Array())
end sub