Apache OpenOffice (AOO) Bugzilla – Issue 51971
Cannot create TextCursors in text frames, which were tables in MS Word
Last modified: 2013-02-24 21:08:40 UTC
The following code goes through all text frames and dumps the text on the command line. When I open a MS Word document which tables in it, OOo converts those tables into text frames and i get an exception. OOo tables are no problems. The exception i get: Exception in thread "main" com.sun.star.uno.RuntimeException: no text available The code line where i get the exception: xTextCursor = xText.createTextCursor(); This is the complete code: XTextFramesSupplier xTextFrames = (XTextFramesSupplier)UnoRuntime.queryInterface( XTextFramesSupplier.class, xTextDocument); String[] names = xTextFrames.getTextFrames().getElementNames(); XTextFrame xTextFrame = null; XText xText = null; XTextCursor xTextCursor = null; Object o=null; String text=""; for (int i=0; i<names.length; i++){ try { o= xTextFrames.getTextFrames().getByName(names[i]); xTextFrame = (XTextFrame) UnoRuntime.queryInterface( XTextFrame.class, o); } catch (NoSuchElementException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (WrappedTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } xText=xTextFrame.getText(); xTextCursor = xText.createTextCursor(); xTextCursor.gotoStart(false); xTextCursor.gotoEnd(true); text = xTextCursor.getString(); System.out.println(text); }
sw->ataraxis: do you have a sample document where tables are imported as frames ? ... I get tables with all the documents I tried.
Created attachment 27927 [details] test document with frames and tables in word. all are frames in writer.
sw->ataraxis: changing your code like this should solve the problem. xText=xTextFrame.getText(); XEnumerationAccess xEA = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, xText); XEnumeration xEnum = xEA.createEnumeration(); boolean isTable = false; try { XPropertySet props = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xEnum.nextElement()); isTable = props.getPropertySetInfo().hasPropertyByName("TextTable"); } catch (Exception e) { } if (isTable) { xTextCursor = xText.createTextCursor(); xTextCursor.gotoStart(false); xTextCursor.gotoEnd(true); text = xTextCursor.getString(); System.out.println(text); }
sw->tl: I wonder why the propery texttable is only available when no table is inside the frame.