Word and labels

Word and labels

Postby lucasdebeltran » Thu Jul 11, 2013 12:29 pm

Hello,

I wish to generate a new Word document (ALL.DOC) with all my customer´s labels.

So I have a template, LABELS.DOC, and I have to add it to the Word document and next replace the fields for each Customer.

But I only get a page with the template loaded.


This is the code:

Code: Select all  Expand view
#include "FiveWin.ch"
#include "xbrowse.ch"

#DEFINE wdCollapseEnd 0
//----------------------------------------------------------------------------//


FUNCTION MAIN()

   LOCAL oWord := CREATEOBJECT( "Word.Application" )

   LOCAL oSel

   oWord:Documents:Open( HB_DIRBASE()+"NEWDOC.DOC" ):Select()


   // First customer
   oSel = oWord:Selection

   oSel:InsertFile(HB_DIRBASE()+"LABEL-TEMPLATE.DOC")

   WORDREPLACE( oSel, "<MyField>", "Replaced Cusomer 1" )



   // Second customer
   oSel:InsertFile(HB_DIRBASE()+"LABEL-TEMPLATE.DOC")
   WORDREPLACE( oSel, "<MyField>", "Replaced Cusomer 2" )


   // etc, I will put a do while !eof()



   oWord:Visible = .T.






   oWord:Documents:Close(0)
   oWord:Quit()


RETURN NIL





// Those functions are from (c) Enrico .it

FUNCTION WORDREPLACE( oSel, cSrc, cRpl )

   LOCAL oRng := oSel:Document:Content

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

   oRng:Find:Execute( cSrc )

   oRng:Text = cRpl

   RETURN .T.


FUNCTION WORDREPLACEALL( oSel, cSrc, cRpl )

   LOCAL oRng := oSel:Document:Content

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

   WHILE oRng:Find:Execute( cSrc )
       oRng:Text = cRpl
       oRng:Collapse( wdCollapseEnd )
   ENDDO

   RETURN .T.

//----------------------------------------------------------------------------//



Thank you very much for your help.

Kind regards
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: Word and labels

Postby Enrico Maria Giordano » Thu Jul 11, 2013 1:12 pm

Lucas,

lucasdebeltran wrote:But I only get a page with the template loaded.


Can you send me the two docs, please?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Word and labels

Postby lucasdebeltran » Thu Jul 11, 2013 2:53 pm

Enrico,

Of course:

http://ul.to/ulnshy3r

Thank you very much,

Best regards
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: Word and labels

Postby Enrico Maria Giordano » Thu Jul 11, 2013 5:17 pm

Lucas,

lucasdebeltran wrote:oSel:InsertFile(HB_DIRBASE()+"LABEL-TEMPLATE.DOC")


oSel:InsertFile(HB_DIRBASE()+"LABELS-TEMPLATE.DOC")

:-)

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Word and labels

Postby lucasdebeltran » Fri Jul 12, 2013 7:08 am

Hello,

Thank you so much !!.

It is working now.

Two more questions please?.

The way I close Word, is it correct?.

How to replace a field with a Image/Photo?.

Thanks a lot.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: Word and labels

Postby lucasdebeltran » Mon Jul 15, 2013 6:25 pm

Hello,


Two more questions please.

The way I close Word, is it correct?.

How to replace a field with a Image/Photo?.

Thanks.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: Word and labels

Postby Enrico Maria Giordano » Mon Jul 15, 2013 6:34 pm

Lucas,

lucasdebeltran wrote:Hello,


Two more questions please.

The way I close Word, is it correct?.


No. You don't have to Quit() if you want to show the document. You have to choose: Visible = .T. or Quit(), not both.

lucasdebeltran wrote:How to replace a field with a Image/Photo?.

Thanks.


I use a text frame and the function below:

Code: Select all  Expand view
FUNCTION WORDREPLACEIMG( oDoc, cSrc, cImg )

    LOCAL lOk := .F.

    LOCAL oRng

    LOCAL i

    IF AT( cSrc, oDoc:Content:Text ) = 0; RETURN .F.; ENDIF

    TRY
        FOR i = 1 TO oDoc:StoryRanges[ wdMainTextStory ]:ShapeRange:Count
            IF oDoc:StoryRanges[ wdMainTextStory ]:ShapeRange[ i ]:TextFrame:HasText != 0
                oRng = oDoc:StoryRanges[ wdMainTextStory ]:ShapeRange[ i ]:TextFrame:TextRange

                IF oRng:Text = cSrc
                    oRng:Text = ""

                    IF !EMPTY( cImg )
                        oDoc:InlineShapes:AddPicture( cImg, .F., .T., oRng )
                    ENDIF

                    lOk = .T.

                    EXIT
                ENDIF
            ENDIF
        NEXT
    CATCH
    END

    RETURN lOk


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Word and labels

Postby Enrico Maria Giordano » Tue Jul 16, 2013 11:27 am

Sorry, remove this:

Code: Select all  Expand view
IF AT( cSrc, oDoc:Content:Text ) = 0; RETURN .F.; ENDIF


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Word and labels

Postby lucasdebeltran » Tue Jul 16, 2013 7:28 pm

Mr. Enrico,

In the Word file, I will have a string, for example, <Picture>, and I need to replace it with a particular picture.

Could be posible please?.

Thanks.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: Word and labels

Postby Enrico Maria Giordano » Tue Jul 16, 2013 8:47 pm

Lucas,

lucasdebeltran wrote:Mr. Enrico,

In the Word file, I will have a string, for example, <Picture>, and I need to replace it with a particular picture.

Could be posible please?.

Thanks.


Yes, that's exactly what my function does. You have to create a text frame with the size of the image and put your string inside it.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Word and labels

Postby lucasdebeltran » Thu Jul 18, 2013 4:27 pm

Mr. Enrico,

Can you please indicate me wdMainTextStory ?

Also, I need please a .doc test, as I can´t get it working.

Thank you very much.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: Word and labels

Postby Enrico Maria Giordano » Thu Jul 18, 2013 5:30 pm

Lucas,

lucasdebeltran wrote:Mr. Enrico,

Can you please indicate me wdMainTextStory ?

Also, I need please a .doc test, as I can´t get it working.

Thank you very much.


Please send me your sample and your DOC so I can test it here and fix it.

#define wdMainTextStory 1

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Word and labels

Postby lucasdebeltran » Fri Jul 19, 2013 8:57 am

Enrico,

Here is the Word:
http://uploaded.net/file/kkibvanc

Thank yuy very much.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: Word and labels

Postby Enrico Maria Giordano » Fri Jul 19, 2013 9:52 am

Lucas,

lucasdebeltran wrote:Enrico,

Here is the Word:
http://uploaded.net/file/kkibvanc

Thank yuy very much.


The link is not accessible from here. Please, send the file to my email.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8713
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 40 guests