Page 1 of 1

Word combination Files

Posted: Mon Dec 02, 2019 2:25 pm
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

Re: Word combination Files

Posted: Tue Dec 03, 2019 7:04 am
by Otto
Hello,
I rename docx to zip and then replace inside document.xml.
Best regards
Otto

http://forums.fivetechsupport.com/viewt ... zip#p69231

Re: Word combination Files

Posted: Wed Dec 04, 2019 4:17 am
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

Re: Word combination Files

Posted: Wed Dec 04, 2019 11:43 am
by Adolfo
Hi...thanks for your answers.

Today Im going to try both solutions.

Greetings, from Chile Adolfo