| View previous topic :: View next topic |
| Author |
Message |
fns Newbie

Joined: 28 Dec 2005 Posts: 4
|
Posted: Fri Jan 20, 2006 11:04 am Post subject: Reading contents of paragraphs |
|
|
Hello all,
sometimes ago I posted a thread asking how I could get the content of paragraphs in a open office document using its API.
Ok. To do this I'm using the following code:
| Code: |
List<String> paragraphs = new ArrayList<String>();
String paragraph= "";
XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, component);
XController xController = xModel.getCurrentController();
XTextViewCursorSupplier xViewCursorSupplier = (XTextViewCursorSupplier)UnoRuntime.queryInterface(
XTextViewCursorSupplier.class, xController);
XTextViewCursor xViewCursor = xViewCursorSupplier.getViewCursor();
XText xDocumentText = xViewCursor.getText();
XTextCursor xModelCursor = xDocumentText.createTextCursorByRange(xViewCursor.getStart());
XParagraphCursor xParagraphCursor = (XParagraphCursor)UnoRuntime.queryInterface(XParagraphCursor.class, xModelCursor);
xParagraphCursor.gotoStart(false);
while (xParagraphCursor.gotoNextParagraph(false)){
xParagraphCursor.gotoEndOfParagraph(true);
paragraph = xParagraphCursor.getString();
if (!paragraph.equals(""))
paragraphs.add(paragraph);
xParagraphCursor.gotoNextParagraph(false);
}
|
But the problem is that I'm not getting all paragraphs. There are many of then that are simply not found. If I have a document with many contents I'm getting just a few of them.
Is it ok that implementation? If anyone could help me I would be so grateful. Thanks in advance!! |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8976 Location: Lexinton, Kentucky, USA
|
Posted: Fri Jan 20, 2006 12:03 pm Post subject: |
|
|
If it helps here is Basic code that will get the content of paragraphs. As you will see it skips tables and blank paragraphs. It will also not get any text that is in a frame. I am surprised you did not get a least this much help previously. | Code: | Sub Main
oDoc = thisComponent
enum = oDoc.getText.createEnumeration
While enum.hasMoreElements
Para = enum.nextElement
If Para.SupportsService("com.sun.star.text.Paragraph") then 'Skip tables
If Len(Para.getString) > 0 then 'Skip blank paragraphs
Print Para.getString
EndIf
EndIf
Wend
End Sub |
|
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
|