Apache OpenOffice (AOO) Bugzilla – Issue 101039
[JAVA] Cannot extract text portion from table
Last modified: 2013-02-24 21:07:39 UTC
I want to traverse text in the table cell by means of XEnumeration interface. But, nextElement() function always returns full content of the cell. If similar code is used for traversing of the paragraph, it works fine. For example: Cell value: "text1 <bold>text2</bold>". <bold> tag means that text2 has bold decorator. I use the following code to extract different text portions: XTextTable table = (XTextTable) UnoRuntime.queryInterface( XTextTable.class, xTextElement); String cellNames[] = table.getCellNames(); for (String cellName : cellNames) { TraceLog.out.info("cell name : " + cellName); XCell cell = table.getCellByName(cellName); XText text = (XText) UnoRuntime.queryInterface( XText.class, cell); XEnumerationAccess textEnum = (XEnumerationAccess) UnoRuntime.queryInterface( XEnumerationAccess.class, text); XEnumeration xTableParEnum = textEnum.createEnumeration(); while (xTableParEnum.hasMoreElements()) { XTextRange xTextPortion = (XTextRange) UnoRuntime.queryInterface( XTextRange.class, xTableParEnum.nextElement()); System.out.println("table text portion : " + xTextPortion.getString()); } } xTextProtion.getString() will always returns full content of cell, but should return firstly "text1" and secondly "<bold>text2</bold>".
Discussion is here: http://www.oooforum.org/forum/viewtopic.phtml?t=82110 But nobody help me. :(
i think it's invalid. The XEnumarationAccess of your XText from the cell gives you an enumeration over the paragraphs in the cell. Each paragraph supports a further enumeration for the text portions. You have to retrieve first the paragraphs and then retrieve the enumeration access from the paragraph to retrieve the text portions. You simply miss one indirection. See the small Basic snippet Sub Main doc = ThisComponent table = doc.getTextTables().getByName("Table1") cell = table.getCellByName("A1") paraenum = cell.createEnumeration() do para = paraenum.nextElement() print para.getString() portionenum = para.createEnumeration() do portion = portionenum.nextElement() print portion.getString() loop until not portionenum.hasMoreElements() loop until not paraenum.hasMoreElements() End Sub
close
by the way www.oooforum.org is a page that i don't read. Too much to do and there is already an official user forum http://user.services.openoffice.org. But i don't read it very often for the same reason. If you want really fast response to your question i would recommend the dev@api.openoffice.org mailing list.
Thank you, it works fine now!