linux - OpenOffice Macro to Access Contents of a Table -
i wrote macro, should take 2 dates (dd.mm.yyyy) string table in openoffice document (writer, not calc). these 2 dates should merged this: ddmmyyyy-ddmmyyyy. should used filename then.
the table has 1 row , 6 columns, first date being in table2:d1:d1 , second 1 in table2:f1:f1. "translated" table2(1, 4) , table2(1, 6)
this german site doing want do, spreadsheets in oocalc document , not oowriter.
enough talk, here code:
sub save odoc=thiscomponent sstartdate = odoc.table2(1, 4) senddate = odoc.table2(1, 6)) sfilename = sstartdate.string & senddate.string surl = converttourl("file:///home/cp/documents/" & sfilename & ".odt") msgbox surl ' odoc.storeasurl(surl, array()) end sub
yes, run linux, path should correct. when try run script says:
property or method not found table2
i of course tried google somehow not find solution. hint in right direction enough, guessed have write "more":
sstartdate = odoc.getstring(table2(1, 4))
or similar. didnt work either. thing tried using (0, 3) instead of (1, 4).
well appreciate it, if me bit! :) , hope have done right how posted here.
vaelor
edit: have modified script this, according pdf found here in chapter 14.9.
it looks this,
sub save odoc=thiscomponent dim otable dim stablename string stablename = "table2" otable = odoc.gettexttables().getbyname(stablename) ' otable = otables.getbyname(stablename) sstartdate = otable.getcellbyposition(0, 3) senddate = otable.getcellbyposition(0, 5) sfilename = sstartdate.string & senddate.string surl = converttourl("file:///home/cp/documents/" & sfilename & ".odt") msgbox surl ' odoc.storeasurl(surl, array()) end sub
but, still not working. exception indexoutofboundsexception. (i wanted link it, says, cant post more 2 links :-( )
my first thought had change cels 0, 3 , 0, 5. after changing that, error still occurs. :-(
edit2: since got no response, think try in python, maybe yields better results.
this code demonstrates how locate text table given name , how access individual cells.
function get_table_by_name(name string) object dim oenum object dim oelem object oenum = thiscomponent.text.createenumeration while oenum.hasmoreelements oelem = oenum.nextelement if oelem.supportsservice("com.sun.star.text.texttable") if oelem.name = name get_table_by_name = oelem exit function end if end if wend end function sub main dim table object table = get_table_by_name("table1") if not isnull(table) msgbox "got " & table.name & " " & table.getrows().getcount() & "x" & table.getcolumns().getcount() msgbox "cell[0,0] " & table.getcellbyposition(0, 0).getstring() end if end sub
Comments
Post a Comment