Move a Table into a Word Document

Move a Table into a Word Document

Postby Silvio.Falconi » Thu Feb 21, 2013 10:52 am

I have a Word document

oWord:=CREATEOBJECT("Word.Application")
oWord:Documents:Add()
oRange:=oWord:ActiveDocument:Range()

and I insert a small table

oTable_Cliente:=oWord:ActiveDocument:Tables:Add(oRange,1,1)

WITH OBJECT oTable_Cliente
:Cells[1]:Range:InsertAfter( Trim("cliente:" ) )
:Cells[1]:Range:InsertAfter( CR )
:Cells[1]:Range:InsertAfter( "INDIRIZZO" )
:Columns:Autofit()
END

oWord:Visible := .t.

Return nil


and I wish move this table on the Right of the document , howI must make to show it ?

the test.prg
Code: Select all  Expand view
#Include "FiveWin.ch"

#DEFINE wdAlignParagraphLeft    0
#DEFINE wdAlignParagraphCentre  1
#DEFINE wdAlignParagraphRight   2


#DEFINE wdCollapseEnd           0


#DEFINE wdStory                       6


#DEFINE wdBorderTop            -1
#DEFINE wdLineStyleDouble       7

#DEFINE CR                     CHR(13)

Function Main()
Local oTable_Cliente
Local oWord,oRange,nRecCount,nRow,nTotSalary:=0

oWord:=CREATEOBJECT("Word.Application")
oWord:Documents:Add()

WITH OBJECT  oTable_Cliente
                  :Cell(1,1):Range:ParagraphFormat:Alignment:=wdAlignParagraphRight
             :Cells[1]:Range:InsertAfter( Trim("cliente:" ) )
             :Cells[1]:Range:InsertAfter( CR  )
             :Cells[1]:Range:InsertAfter( "INDIRIZZO" )

               :Columns:Autofit()


          END


oWord:Visible := .t.

Return nil
 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Move a Table into a Word Document

Postby Silvio.Falconi » Fri Feb 22, 2013 11:04 am

Any Help please
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Move a Table into a Word Document

Postby Silvio.Falconi » Fri Feb 22, 2013 11:18 am

Image
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Move a Table into a Word Document

Postby anserkk » Sat Feb 23, 2013 5:11 am

Silvio.Falconi wrote: I wish move this table on the Right of the document , howI must make to show it ?


Code: Select all  Expand view
#DEFINE wdTableRight           -999996
oTable:Rows:HorizontalPosition = wdTableRight
 


Regards
Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Move a Table into a Word Document

Postby Silvio.Falconi » Sat Feb 23, 2013 10:10 am

Thanks Anserkk

For add a picture Emg tell me to insert

oWord:ActiveDocument:Shapes:AddPicture( "c:\logoditta.bmp", .T., .T., 1, 1, 150, 80)

but this is not transparent , how I can make to insert a big picture transparent ?



I'm trying to create a order with Ms Word

Image



and I tried to insert a picture at left and a table on RIght and I cannot make it

oTable_Cust=oWord:ActiveDocument:Tables:Add(oRange,1,2)
WITH OBJECT oTable_Cust
:Rows:HorizontalPosition = wdTableRight
:Cell(1,1):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
:Cell(1,1):Range:InsertAfter("Customer")
END
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Move a Table into a Word Document

Postby Silvio.Falconi » Sat Feb 23, 2013 12:12 pm

Anserkk,
I Tried this morning and I made this test

Image

but I have some problem
the column are not good and I not Know why


Code: Select all  Expand view
   

#Include "FiveWin.ch"

REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO





    * Author: Mr. Anser K.K.
    * Export table from DBF to MSWord Document
    * Demonstrates how to create tables in MS-Word, align word table and text side by side

    #DEFINE wdAlignParagraphLeft    0
    #DEFINE wdAlignParagraphCentre  1
    #DEFINE wdAlignParagraphRight   2
    #DEFINE wdAlignParagraphJustify 3
    #DEFINE wdAlignRowRight         2
    #DEFINE wdParagraph             4
    #DEFINE wdStory                 6
    #DEFINE wdCollapseEnd           0
    #DEFINE wdCollapseStart         1
    #DEFINE wdBorderTop            -1
    #DEFINE wdLineStyleDouble       7
    #DEFINE wdHeaderFooterPrimary   1
    #DEFINE wdTableRight           -999996


    #DEFINE CR                     CHR(13)












    //--------------------------//
    Function Order()

        Local oWord
        Local oRange
        Local nRecCount
        Local nRow
        Local nTotSalary:=0



      Local oTable_Header
      Local oTable_Body
      Local oTable_Ive
      Local oTable_Footer
      Local oTable_Cliente



//DATI FATTURA

nDocFat:="23"
nOrdNum:="R32"
dData:=date()

       RddSetDefault( "DBFCDX" )

   SetHandleCount( 100 )

  if ! Db_OpenNoIndex("CUSTOMER","CU")
        return nil
     endif

   SELECT CU







        oWord:=CREATEOBJECT("Word.Application")
        oWord:Documents:Add()
        oWord:ActiveDocument:Shapes:AddPicture( "c:\logoditta.bmp", .T., .T., 1, 1, 150, 80)
        oRange:=oWord:ActiveDocument:Range()

oRange:MoveEnd( wdStory )
oRange:Collapse( wdCollapseEnd )
oRange:InsertAfter( CR + CR )
oRange:Collapse( wdCollapseEnd )




  oTable_Cliente:=oWord:ActiveDocument:Tables:Add(oRange,2,1)

   WITH OBJECT oTable_Cliente
        :Borders:InsideLineStyle:=.T.
        :Borders:OutsideLineStyle:=.T.


          // Shade first row for headings
        #ifdef __XHARBOUR__
           :Rows[1]:Shading:Texture = 100
        #else
           :Rows(1):Shading:Texture = 100
        #endif







        :MoveEnd( wdStory )
                       :Rows:HorizontalPosition = wdTableRight
                       :Cell(1,1):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
                       :Cell(1,1):Range:InsertAfter("Customer")
                       :Cells[2]:Range:InsertAfter( CR  )
                       :Cells[2]:Range:InsertAfter(  Trim( CU->FIRST)+" "+Trim( CU->LAST))
                       :Cells[2]:Range:InsertAfter( CR  )
                       :Cells[2]:Range:InsertAfter(  Trim( CU->STREET))
                       :Cells[2]:Range:InsertAfter( CR  )
                       :Cells[2]:Range:InsertAfter(  Trim( CU->CITY )  )
                       :Cells[2]:Range:InsertAfter( CR  )
                       :Cells[2]:Range:InsertAfter(  Trim( CU->STATE )  )
                       :Cells[2]:Range:InsertAfter( CR  )
                       :Cells[2]:Range:InsertAfter(  Trim( CU->ZIP )  )
                       :Cells[2]:Range:InsertAfter( CR  )
                       :Cells[2]:Range:InsertAfter(  space(60)  )
                       :Columns:Autofit()
    END




// Move to the end of the document, leave 2 empty lines
oRange:MoveEnd( wdStory )
oRange:Collapse( wdCollapseEnd )
oRange:InsertAfter( CR + CR )
oRange:InsertAfter( CR + CR )
oRange:InsertAfter( CR + CR )
oRange:InsertAfter( CR + CR )
oRange:InsertAfter( CR + CR )
oRange:InsertAfter( CR + CR )
oRange:Collapse( wdCollapseEnd )




oTable_Header:=oWord:ActiveDocument:Tables:Add(oRange,1,3)

 WITH OBJECT  oTable_Header
        :Borders:InsideLineStyle:=.T.
        :Borders:OutsideLineStyle:=.T.
        // Shade first row for headings
        #ifdef __XHARBOUR__
           :Rows[1]:Shading:Texture = 100
        #else
           :Rows(1):Shading:Texture = 100
        #endif
         :MoveEnd( wdStory )

   :Cell(1,1):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
   :Cell(1,1):Range:InsertAfter("Numero Fattura")
   :Cell(1,2):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
   :Cell(1,2):Range:InsertAfter("Data Fattura")
   :Cell(1,3):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
   :Cell(1,3):Range:InsertAfter("Numero Ordine")

     :Rows:Add()
        nRow:=1
     WITH OBJECT :Rows[nRow + 1]
      :Shading:Texture = 0
      :Cells[1]:Range:InsertAfter( Trim( nDocFat ) )
     END

     WITH OBJECT :Rows[nRow + 1]
      :Shading:Texture = 0
      :Cells[2]:Range:InsertAfter( dData )
     END

     WITH OBJECT :Rows[nRow + 1]
      :Shading:Texture = 0
      :Cells[3]:Range:InsertAfter( Trim(nOrdNum ) )
     END

     :Rows:Add()
     :Rows[3]:Shading:Texture = 40

   :Cell(3,1):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
   :Cell(3,1):Range:InsertAfter("Regolamento")
   :Cell(3,2):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
   :Cell(3,2):Range:InsertAfter("Estremi Bancari")
   :Cell(3,3):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
   :Cell(3,3):Range:InsertAfter("Pagamento")

    :Rows:Add()
   * :Columns:Autofit()

END






    oRange:MoveEnd( wdStory )
oRange:Collapse( wdCollapseEnd )
oRange:InsertAfter( CR + CR )
oRange:Collapse( wdCollapseEnd )




 if ! Db_OpenNoIndex("ORDER","PA")
        return nil
     endif




oTable_Body:=oWord:ActiveDocument:Tables:Add(oRange,1,8)

WITH OBJECT oTable_Body
  :Borders:InsideLineStyle:=.T.
  :Borders:OutsideLineStyle:=.T.

   :Rows[1]:Shading:Texture = 100

   :Cell(1,1):Range:ParagraphFormat:Alignment:=wdAlignParagraphCentre
   :Cell(1,1):Range:InsertAfter("Item")

   :Cell(1,2):Range:ParagraphFormat:Alignment:=wdAlignParagraphCentre
   :Cell(1,2):Range:InsertAfter("Description")



   :Cell(1,3):Range:ParagraphFormat:Alignment:=wdAlignParagraphCentre
   :Cell(1,3):Range:InsertAfter("Quantity")

   :Cell(1,4):Range:ParagraphFormat:Alignment:=wdAlignParagraphCentre
   :Cell(1,4):Range:InsertAfter("Measure")


   :Cell(1,5):Range:ParagraphFormat:Alignment:=wdAlignParagraphCentre
   :Cell(1,5):Range:InsertAfter("Unit Price")

   :Cell(1,6):Range:ParagraphFormat:Alignment:=wdAlignParagraphCentre
   :Cell(1,6):Range:InsertAfter("Iva")

   :Cell(1,7):Range:ParagraphFormat:Alignment:=wdAlignParagraphCentre
   :Cell(1,7):Range:InsertAfter("Descount")

   :Cell(1,8):Range:ParagraphFormat:Alignment:=wdAlignParagraphCentre
   :Cell(1,8):Range:InsertAfter("Total")





    *  :Columns:Autofit()
         nRow:=2
          :Rows:Add()

    DO WHILE !Pa->(Eof())


       WITH OBJECT :Rows[nRow]
              :Shading:Texture = 0
              :Cells[1]:Range:InsertAfter( Trim( Pa->Codice ) )
              :Cells[2]:Range:InsertAfter( Trim( Pa->Voce ) )
              :Cells[3]:Range:InsertAfter( ( Pa->Quantita ) )
              :Cells[4]:Range:InsertAfter( Trim( Pa->unita ) )
              :Cells[5]:Range:InsertAfter( ( Pa->prezzo ) )
              :Cells[6]:Range:InsertAfter( Trim( Pa->Sconti) )
              :Cells[7]:Range:InsertAfter( Trim( Pa->Iva ) )
              :Cells[8]:Range:InsertAfter( Pa->Importo  )


             END
             :Rows:Add()
        Pa->(DbSkip())
          nRow++
    ENDDO




  :Columns:Autofit()



 END


        // Setting Header
        WITH OBJECT oWord:ActiveDocument:Sections[1]:Headers[ wdHeaderFooterPrimary ]
            oRange = :Range()
            WITH OBJECT oRange
                :Text = "Order Test"
                :ParagraphFormat:Alignment:= wdAlignParagraphCentre

            END
        END




        // Setting Footer
        WITH OBJECT oWord:ActiveDocument:Sections[1]:Footers[ wdHeaderFooterPrimary ]
            oRange = :Range()
            WITH OBJECT oRange
                :Text = "FivetechSoft 2013"
                :ParagraphFormat:Alignment:= wdAlignParagraphCentre
            END
        END

        oWord:Visible := .t.

    Return nil


function Db_OpenNoIndex(cDbf,cAlias)
   if file( cDbf + ".dbf" )
      USE &(cDbf+".dbf")      ;
         ALIAS &(cAlias) NEW
   else
     MsgStop( i18n( "Non si è trovato l'archivio dei dati." ) + CRLF + ;
               i18N( "Per favore  controlla la configurazone") + CRLF + ;
                i18N( "e indicizza gli archivi dell'applicazione." ) )
      return .f.
      return .f.
   END if
   if NetErr()
     msgStop( i18n( "Errore nell'aprire un archivio" ) + CRLF + ;
              i18n( "Per favore caricare di nuovo l'applicazione." ) )
      DbCloseAll()
      return .f.
   endif
return .t.


 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Move a Table into a Word Document

Postby anserkk » Sat Feb 23, 2013 3:14 pm

Dear Silvio,

What do u mean by saying that the column is not good. Did you mean that the row height is not same for all the rows ?

Try to set auto column width to .f.
Regards
Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Move a Table into a Word Document

Postby Silvio.Falconi » Sat Feb 23, 2013 4:28 pm

yes.. and on each page I must insert only 20 rows
then I must create anoter tables on footer

How I can make to set Font, size of each tables or text ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Move a Table into a Word Document

Postby ukoenig » Sat Feb 23, 2013 4:42 pm

Silvio,

font-samples defined in different sections, You can find at

viewtopic.php?f=3&t=25705

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Move a Table into a Word Document

Postby Silvio.Falconi » Sat Feb 23, 2013 4:54 pm

and size of width and Height of each rows/column ?

please if you see the first table I insert to size the table this command : :Cells[2]:Range:InsertAfter( space(60) )
becasue the table was small

But I understood it is wrong
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: Move a Table into a Word Document

Postby ukoenig » Sat Feb 23, 2013 5:47 pm

Silvio,

for long tables You can define a PAGEBREAK like :

To insert a page break after the 46th line of the document:
#define wdGoToAbsolute 1
#define wdGoToLine 3
#define wdPageBreak 7

// go to line number 47
oword:selection:goto(wdGoToLine, wdGoToAbsolute, 47)
// inseting the page break
oword:selection:InsertBreak(wdPageBreak)


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 103 guests