Dinesh Chothe wrote:
              Hello,
                       I am developing writer based application using
java,oo sdk and netbeans.
                 In this application object has to travels from starting of
document up to end  of document.
                 While moving it may come across different txt
contents,images,tables,graphs etc...
                 Now this object has to access only text contents  its
properties(like font,bold,size etc),it may
                   from tables or graphs etc.
                 After getting I am replacing it with some other text then
it should be replace with at exact positions with
                    as per its previous properties.
                Can anybody guide me for how to do this?
This is a very "big" question.

Download my free macro document and then start reading from section 7.16 Traverse paragraphs (text cursor behavior). My expectation is that this is not of much use to you, but, if you skim a few sub-sections, you will eventually come to 7.16.3 What does it mean to enumerate text content? This section gets you started on enumerating paragraphs. Consider the following macro:

Sub EnumerateContent
 REM Author: Andrew Pitonyak
 Dim oParEnum     'Enumerator used to enumerate the paragraphs
 Dim oPar         'The enumerated paragraph
 Dim oSectionEnum 'Enumerator used to enumerate the text sections
 Dim oSection     'The enumerated text section
 Dim s As String  'Contains the enumeration
 Dim i As Integer 'Count the paragraphs

 REM Enumerate the paragraphs.
 REM Tables are enumerated along with paragraphs
 oParEnum = ThisComponent.getText().createEnumeration()
 Do While oParEnum.hasMoreElements()
   oPar = oParEnum.nextElement()

   REM This avoids the tables. Add an else statement if you want to
   REM process the tables.
   If oPar.supportsService("com.sun.star.text.Paragraph") Then

     i = i + 1 : s = ""
     REM Now, enumerate the text sections and look for graphics that
     REM are anchored to a character, or as a character.
     oSectionEnum = oPar.createEnumeration()
     Do While oSectionEnum.hasMoreElements()
       oSection = oSectionEnum.nextElement()

       If oSection.TextPortionType = "Text" Then
         REM This is a simply text object!
         s = s & oSection.TextPortionType & " : "
         s = s & oSection.getString() & CHR$(10)
       Else
         s = s & oSection.TextPortionType & " : " & CHR$(10)
       End If
     Loop
     MsgBox s, 0, "Paragraph " & i
   End If
 Loop
End Sub

This enumerates sections based on common formatting. The problem, however, is that you can not do something simple like oSection.setString("I am replacement text") and have it use the same properties. What happens, is that properties are "messed up". I created a simple test, and then set every text section to some simple text like "XyzzyX", and I watched the effects ripple through. It was horrifying..

Perhaps you can do something similar to the following:

         Dim oStart : oStart = oSection.getStart()
         Dim oEnd   : oEnd = oSection.getEnd()
         Dim oText  : oText  = oStart.getText()
         Dim oCurs
         oText.insertString ( oEnd, "XyzzyX", False)

Now, remove text from oStart to oEnd.

I was going to finish the solution, but my daughter needs attention.


--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to