Issue 101039 - [JAVA] Cannot extract text portion from table
Summary: [JAVA] Cannot extract text portion from table
Status: CLOSED NOT_AN_OOO_ISSUE
Alias: None
Product: App Dev
Classification: Unclassified
Component: api (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: Unknown Windows XP
: P3 Trivial
Target Milestone: ---
Assignee: jsc
QA Contact: issues@api
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-13 11:15 UTC by tysonite
Modified: 2013-02-24 21:07 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description tysonite 2009-04-13 11:15:21 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>".
Comment 1 tysonite 2009-04-13 11:17:09 UTC
Discussion is here: http://www.oooforum.org/forum/viewtopic.phtml?t=82110
But nobody help me. :(
Comment 2 jsc 2009-04-14 13:52:42 UTC
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
Comment 3 jsc 2009-04-14 13:53:10 UTC
close
Comment 4 jsc 2009-04-14 14:21:12 UTC
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.
Comment 5 tysonite 2009-04-15 11:11:28 UTC
Thank you, it works fine now!