Word combination Files

Post Reply
User avatar
Adolfo
Posts: 815
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile
Contact:

Word combination Files

Post by Adolfo »

Hi fivewinners

I do a search and replace in word documents without problem at all.

Now I need to change some 'combination fields' , there's no posibilitty to create a new ones, I must use some given by my client, which they use in another proceses.
The problem is , I can't replace <<FIELD>>.
In some way, my routine doesn't find it, nor change it.

Code: Select all

...
      oDoc = oWord:Documents:Open(MODELO)
      oDoc:Select()
      oSel = oWord:Selection

    WordReplace( oSel, "«fecha»"         , Alltrim(oDbSel:DATA01))
....



FUNCTION WORDREPLACE( oSel, cSrc, cRpl )
LOCAL oRepla:= oSel:Document:Content

    IF AT( cSrc, oRepla:Text ) = 0
       RETURN .F.
    ENDIF

    WHILE oRepla:Find:Execute( cSrc )
        oRepla:Text = cRpl
        oRepla:Collapse( 0 )
    ENDDO

RETURN .T.
 

Any help will be appreciated.
From Chile
Adolfo
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Lenovo Legion Y520, 16GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1050
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Word combination Files

Post by Otto »

Hello,
I rename docx to zip and then replace inside document.xml.
Best regards
Otto

http://forums.fivetechsupport.com/viewt ... zip#p69231
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Word combination Files

Post by anserkk »

Adolfo wrote:Hi fivewinners

I do a search and replace in word documents without problem at all.

Now I need to change some 'combination fields' , there's no posibilitty to create a new ones, I must use some given by my client, which they use in another proceses.
The problem is , I can't replace <<FIELD>>.
In some way, my routine doesn't find it, nor change it.

Code: Select all

...
      oDoc = oWord:Documents:Open(MODELO)
      oDoc:Select()
      oSel = oWord:Selection

    WordReplace( oSel, "«fecha»"         , Alltrim(oDbSel:DATA01))
....



FUNCTION WORDREPLACE( oSel, cSrc, cRpl )
LOCAL oRepla:= oSel:Document:Content

    IF AT( cSrc, oRepla:Text ) = 0
       RETURN .F.
    ENDIF

    WHILE oRepla:Find:Execute( cSrc )
        oRepla:Text = cRpl
        oRepla:Collapse( 0 )
    ENDDO

RETURN .T.
 

Any help will be appreciated.
From Chile
Adolfo
Can you try the following code ?

Code: Select all

   aData:={}
   aadd( aData, { '<<Name>>'  , "Mr.John" } )
   aadd( aData, { '<<Amount>>',  "550.00" } ) 

   oWord:Visible := .F. //Do not display Word
   oDoc := oWord:Documents:Open(cDoc_Temp)  //Open the word document
   for i=1 to len( aData )
       oTexto := oDoc:Range()
       oFind  := oTexto:Get( "Find" )

       oFind:Set( "Text", aData[i,1] )
       oFind:Set( "Forward", .T. )
       oFind:Set( "Wrap", INT(1) )
       oFind:Set( "Format", .f.            )
       oFind:Set( "MatchCase", .f.         )
       oFind:Set( "MatchWholeWord", .f.    )
       oFind:Set( "MatchWildcards", .f.    )
       oFind:Set( "MatchSoundsLike", .f.   )
       oFind:Set( "MatchAllWordForms", .f. )

       oFind:Invoke( "Execute")

       DO WHILE oFind:Get( "Found" )    // Replace all occurances that match

          oTexto:Set( "Text", aData[i,2] )
          oFind:Invoke( "Execute")
       Enddo
   next
User avatar
Adolfo
Posts: 815
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile
Contact:

Re: Word combination Files

Post by Adolfo »

Hi...thanks for your answers.

Today Im going to try both solutions.

Greetings, from Chile Adolfo
;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Lenovo Legion Y520, 16GB Ram, 1 TB NVME M.2, 1 TB SSD, GTX 1050
Post Reply