OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Reading contents of paragraphs

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
fns
Newbie
Newbie


Joined: 28 Dec 2005
Posts: 4

PostPosted: Fri Jan 20, 2006 11:04 am    Post subject: Reading contents of paragraphs Reply with quote

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
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 8976
Location: Lexinton, Kentucky, USA

PostPosted: Fri Jan 20, 2006 12:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Mon Jan 23, 2006 9:17 am    Post subject: Reply with quote

fns,
your code begins with a curentcontroler which means you are working on selected text and not on all the document. How do you check your code ?
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group