Word combination Files

Word combination Files

Postby Adolfo » Mon Dec 02, 2019 2: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: Select all  Expand view  RUN

...
      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
User avatar
Adolfo
 
Posts: 860
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile

Re: Word combination Files

Postby Otto » Tue Dec 03, 2019 7:04 am

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

viewtopic.php?f=3&t=13495&p=69231&hilit=word+zip#p69231
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6345
Joined: Fri Oct 07, 2005 7:07 pm

Re: Word combination Files

Postby anserkk » Wed Dec 04, 2019 4: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: Select all  Expand view  RUN

...
      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  Expand view  RUN
  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
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Word combination Files

Postby Adolfo » 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
User avatar
Adolfo
 
Posts: 860
Joined: Tue Oct 11, 2005 11:57 am
Location: Chile


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 91 guests