Question : Open Office Text and python: extract text word by word

Hi,

I  just started playing with python scripts for open office.


Currently I'd like to locate all tables in a text document and then extract the contents of each cell of these tables.
Extracting the cells is probably rather easy as soon as I solved my main problem:
extracting all tables.

 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
def mymacro_text_tables():
    info = []
    doc = XSCRIPTCONTEXT.getDocument()
    text = doc.Text
    fh = open("result.txt","a")
    #well here I'm lost.
    # how to get all tables in a document
    tables = ??????
    table_enum = tables.createEnumeration() # this line is guessed
    cnt = 0
    while table_enum.hasMoreElements():  # this line is guessed
        cnt += 1
        table = table_enum.nextElement() # this line is guessed
        for cell_name in ["A1","B1","A2"]:
            cell = table.getCellByName(cell_name)
            do_something_with_cell()
            
    fh.write( "found %d tables\n" % cnt )
    fh.close()

Answer : Open Office Text and python: extract text word by word

Here you go:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
def getWords():

    doc = XSCRIPTCONTEXT.getDocument()
    parentwin = doc.CurrentController.Frame.ContainerWindow

    text = doc.Text
    MessageBox(parentwin, text.getString(), "Document")

    wordcursor = text.createTextCursor()

    while 1:
        wordcursor.gotoStartOfWord(False);
        wordcursor.gotoEndOfWord(True);
        MessageBox(parentwin, wordcursor.getString(), "Word")
        if (wordcursor.gotoNextWord(False) == False):
	    break;
Random Solutions  
 
programming4us programming4us