FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Word combination Files
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM
Word combination Files
Posted: Mon Dec 02, 2019 02:25 PM
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 (fw): Select all Collapse
...
      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
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Word combination Files
Posted: Tue Dec 03, 2019 07:04 AM

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

viewtopic.php?f=3t=13495p=69231hilit=word+zip#p69231

&&&

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Word combination Files
Posted: Wed Dec 04, 2019 04:17 AM
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 (fw): Select all Collapse
...
      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 (fw): Select all Collapse
   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
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM
Re: Word combination Files
Posted: Wed Dec 04, 2019 11:43 AM

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
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650

Continue the discussion