FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Tablas en Office
Posts: 498
Joined: Thu May 10, 2007 08:30 PM
Tablas en Office
Posted: Fri Feb 11, 2011 11:42 AM

Buenas a todos.

Hace un tiempo hice algunos pinitos creando documentos Office (Word y Excel) desde FiveWin, con TOLEAUTO, todo muy bien, los textos ten铆an comodines que se sustitu铆an con campos de mis base de datos en tiempo de ejecuci贸n. Pero ahora me surge un problemilla, necesito crear, y rellenar tablas con Office (Word). 驴Alguien sabe que comandos hay que utilizar para:

  • Crear una tabla
  • Insertar/borrar filas en esa tabla
  • Escribir/Borrar texto en una celda
  • Cambiar el color de una fila/Celda
  • Cambiar las propiedades de una fila/Celda

Una punctualizaci贸n, entonces trabajaba con Ofiice 2003. 驴Se trabaja igual con el 2007?

Gracias de antemano.

Peaaaaaso de foro...

FWH 2007 - xHarbour - BCC55
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Tablas en Office
Posted: Sat Feb 12, 2011 05:36 AM
This program reads the Customer.DBF available in \FWH\Samples folder and dumps the data onto a table on a word document

Code (fw): Select all Collapse
Include "FiveWin.ch"

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

#DEFINE wdStory 聽 聽 聽 聽 聽 聽 聽 聽 6
#DEFINE wdCollapseEnd 聽 聽 聽 聽 聽 0

#DEFINE wdBorderTop 聽 聽 聽 聽 聽 聽-1
#DEFINE wdLineStyleDouble 聽 聽 聽 7

#DEFINE CR 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 CHR(13)

//--------------------------//
Function Main()

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

USE \FWH\Samples\CUSTOMER
nRecCount:=RecCount()

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

oRange:=oWord:ActiveDocument:Range()

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

// Add a table with 2 rows and 3 columns
oTable:=oWord:ActiveDocument:Tables:Add(oRange,2,3)

WITH OBJECT oTable
聽 聽// Set up borders and shading
聽 聽// If u dont want borders then set the below lines 2 lines to .F.
聽 聽:Borders:InsideLineStyle:=.T.
聽 聽:Borders:OutsideLineStyle:=.T.

聽 聽// Shade first row for headings
聽 聽:Rows[1]:Shading:Texture = 100


聽 聽// Put heading text in and set alignment
聽 聽:Cell(1,1):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
聽 聽:Cell(1,1):Range:InsertAfter("Last Name") 聽 
聽 聽
聽 聽
聽 聽:Cell(1,2):Range:ParagraphFormat:Alignment:=wdAlignParagraphRight
聽 聽:Cell(1,2):Range:InsertAfter("Salary")

聽 聽:Cell(1,3):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
聽 聽:Cell(1,3):Range:InsertAfter("Hire Date")

聽 聽// Format data cells
聽 聽:Cell(2,1):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft
聽 聽:Cell(2,2):Range:ParagraphFormat:Alignment:=wdAlignParagraphRight
聽 聽:Cell(2,3):Range:ParagraphFormat:Alignment:=wdAlignParagraphLeft

聽 聽// Add data and format
聽 聽nTotSalary:=0 聽 
聽 聽For nRow:=1 to 20 // nRecCount

聽 聽 聽 聽WITH OBJECT :Rows[nRow + 1] 聽 聽 
聽 聽 聽 聽 聽 聽:Cells[1]:Range:InsertAfter( Customer->LAST 聽)
聽 聽 聽 聽 聽 聽:Cells[2]:Range:InsertAfter( Customer->SALARY 聽) 聽 聽 聽 
聽 聽 聽 聽 聽 聽:Cells[3]:Range:InsertAfter( Customer->HIREDATE 聽)

聽 聽 聽 聽END
聽 聽 聽 聽
聽 聽 聽 聽// Add a new Row
聽 聽 聽 聽:Rows:Add()
聽 聽 聽 聽
聽 聽 聽 聽// Calculating total
聽 聽 聽 聽nTotSalary+=Customer->SALARY

聽 聽 聽 聽Skip

聽 聽Next
聽 聽
聽 聽// Total row shade and place total 
聽 聽:Rows[ nRow + 1 ]:Shading:Texture = 100
聽 聽WITH OBJECT :Rows[ nRow + 1 ]
聽 聽 聽 聽:Cells[1]:Range:InsertAfter("Total Salary")
聽 聽 聽 聽:Cells[2]:Range:InsertAfter(nTotSalary)
聽 聽
聽 聽END
聽 聽
聽 聽// Size columns, for simplicity, let word do the work
聽 聽:Columns:Autofit()
END
oWord:ActiveDocument:SaveAs("D:\Anser")
oWord:ActiveDocument:Close()
oWord:Quit()
MsgInfo("Finished")
Return


Screen Snapshot


Regards
Anser
Posts: 498
Joined: Thu May 10, 2007 08:30 PM
Re: Tablas en Office
Posted: Mon Feb 14, 2011 06:56 AM

Muchas gracias anserkk, es exactamente lo que estaba buscando. Una maravilla.

Peaaaaaso de foro...

FWH 2007 - xHarbour - BCC55
Posts: 498
Joined: Thu May 10, 2007 08:30 PM
Re: Tablas en Office
Posted: Mon Feb 14, 2011 07:52 AM

S贸lo una cosa m谩s, si no es mucha molestia.

Mi intenci贸n, es modificar/completar una archivo modelo, entonces:

1- C贸mo a帽ado texto al final de, por ejemplo, la 3陋 l铆nea.
2- C贸mo selecciono una tabla ya existente para modificarlla.

Gracias

Peaaaaaso de foro...

FWH 2007 - xHarbour - BCC55
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Tablas en Office
Posted: Mon Feb 14, 2011 10:01 AM
antolin wrote:S贸lo una cosa m谩s, si no es mucha molestia.

Mi intenci贸n, es modificar/completar una archivo modelo, entonces:

1- C贸mo a帽ado texto al final de, por ejemplo, la 3陋 l铆nea.
2- C贸mo selecciono una tabla ya existente para modificarlla.

Gracias


The following code will read data from an existing table available in a word file and will modify the contents of the table. You may first create the word file using my sample code posted above.
Code (fw): Select all Collapse
#Include "FiveWin.ch"

//--------------------------//
Function Main()

Local oWord,oDoc,oTable,nRow,nCol,nColor

oWord:=CREATEOBJECT("Word.Application")
oDoc = oWord:Documents:Open("D:\Anser.docx")

oTable = oDoc:Tables:Item(1) // 1 means, First table on the document

WITH OBJECT oTable
聽 聽 nColor:=1
聽 聽 For nRow = 2 To oTable:Rows:Count
聽 聽 聽 聽 For nCol = 1 To oTable:Columns:Count
聽 聽 聽 聽 
聽 聽 聽 聽 聽 聽 // Changing the text color of the cell
聽 聽 聽 聽 聽 聽 :Cell(nRow, nCol):Range:Font:ColorIndex = nColor
聽 聽 聽 聽 聽 聽 
聽 聽 聽 聽 聽 聽 // Write to the table cell
聽 聽 聽 聽 聽 聽 :Cell(nRow, nCol):Range:Text = "Replaced with " + Str(nRow - 1)
聽 聽 聽 聽 聽 聽 
聽 聽 聽 聽 聽 聽 // If you want to read the contents then
聽 聽 聽 聽 聽 聽 // MsgInfo( :Cell(nRow, nCol):Text )
聽 聽 聽 聽 聽 聽 
聽 聽 聽 聽 聽 聽 iif(nColor == 16,nColor:=1,nColor++)
聽 聽 聽 聽 Next
聽 聽 Next 
聽 聽 
聽 聽 // Size columns, for simplicity, let word do the work
聽 聽 :Columns:Autofit()
END

oWord:Visible := .T.
Return


Screen Snapshot



Regards
Anser
Posts: 498
Joined: Thu May 10, 2007 08:30 PM
Re: Tablas en Office
Posted: Tue Feb 15, 2011 11:42 AM

Muchas Gracias Anser, con esto me sobra para empezar.

Saludos

Peaaaaaso de foro...

FWH 2007 - xHarbour - BCC55
Posts: 133
Joined: Fri Nov 30, 2007 11:34 AM
Re: Tablas en Office
Posted: Thu Mar 10, 2011 07:20 PM

Buenas tardes.

Intento enlazar el ejemplo de ANSERKK pero tengo el siguiente error "Unresolved external HB_FUN_CREATEOBJECT"

Creo que se trata de una liber铆a de Hb que me falta. Enlazo con HbOLE y OLE2.

Un saludo

Saludos. Fernando
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Tablas en Office
Posted: Fri Mar 11, 2011 02:47 AM

Saludos

que version de [x]Harbour usas?

Posts: 133
Joined: Fri Nov 30, 2007 11:34 AM
Re: Tablas en Office
Posted: Fri Mar 11, 2011 08:16 AM

Buenos d铆as Daniel.

La versi贸n que utilizo creo que es la 1.4, que es la que descargu茅 de Five Tech al adquirir FWH 7.07

Un saludo. Fernando

Saludos. Fernando

Continue the discussion