Agregar fila a Excel TOleAuto. (Solucionado)

Agregar fila a Excel TOleAuto. (Solucionado)

Postby jrestojeda » Tue Aug 09, 2016 12:26 pm

Hola a todos,
Estoy queriendo formatear una dbf con tOleAuto para luego guardarla en un archivo Excel. Funciona bien, pero estoy teniendo un inconveniente. Basicamente no se cual es el método para agregar una fila.
Lo que quiero hacer, es agregar una fila al principio de todo para ahí poner un título, si lo hago de la manera que estoy haciendo funciona, pero no estoy agregando una fila, sino reemplazando la primer y segunda fila. Eso me trae el problema que pierdo el contenido del primer registro de la dbf ya que lo estoy pisando.
Alguien sabe como hacer lo que necesito?

Estoy haciendo lo siguiente:

Code: Select all  Expand view

Function Ejemplo()
Local oExcel,oBook,oHoja

oExcel:= TOleAuto():New("Excel.Application")
oBook := oExcel:Workbooks:Open(REP_LOC+"INFOSAL.dbf")
oHoja := oExcel:Get( "ActiveSheet" )

oHoja:Range("A1:D1"):Font:bold := .T.

oHoja:Cells:Font:Name     := "Arial"
oHoja:Cells:Font:Size     := 10

oHoja:Cells( 1, 1 ):Value :="INFORME DE SALDOS"

oHoja:Range("B1:D1"):VALUE     :=""
oHoja:Range("A1:D1"):Font:bold := .T.
oHoja:Range("A1:D1"):MergeCells:= .T.
oHoja:Columns("A:D"):AutoFit()

oHoja:Range("A1:D1"):Font:Color         := RGB(255,255,255)
oHoja:Range("A1:D1"):Interior:Color     := RGB(0,0,0)
oHoja:Range("A1:D1"):HorizontalAlignment:= -4108
oHoja:Range("A1:D1"):VerticalAlignment  := -4108
oHoja:Range("A1:D1"):Font:Bold:= .T.

oHoja:Cells( 2, 1 ):Value :="Empresa"
oHoja:Cells( 2, 2 ):Value :="Cliente"
oHoja:Cells( 2, 3 ):Value :="Razón Social"
oHoja:Cells( 2, 4 ):Value :="Saldo"

oHoja:Range("A2:D2"):Font:Color         := RGB(255,255,255)
oHoja:Range("A2:D2"):Interior:Color     := RGB(0,0,0)
oHoja:Range("A2:D2"):Font:bold          := .T.
oHoja:Range("A2:D2"):HorizontalAlignment:= -4108
oHoja:Range("A2:D2"):VerticalAlignment  := -4108

oHoja:Columns("A:D"):AutoFit()

oHoja:Saveas(REP_LOC+"INFOSAL.XLSX")
oBook:= oExcel:Get( "WorkBooks" )
oBook:Open(REP_LOC+"INFOSAL.XLSX")
oHoja:= oExcel:Get( "ActiveSheet" )

oHoja:Cells( 1, 1 ):Select()
oExcel:Visible          := .T.
oExcel:DisplayStatusBar := .T.
oExcel:DisplayFormulaBar:= .T.
oBook:End()

oExcel:DisplayAlerts :=.F.

oHoja :End()
oExcel:End()
RELEASE oHoja
RELEASE oExcel

Return nil
//
 


Desde ya muchas gracias.
Saludos,
Last edited by jrestojeda on Thu Aug 11, 2016 10:38 am, edited 2 times in total.
Ojeda Esteban Eduardo.
Buenos Aires - Argentina.
FWH - PellesC - DBF/CDX - ADS - Gloriosos .Bat - MySql - C# .net - FastReport
Skype: jreduojeda
User avatar
jrestojeda
 
Posts: 601
Joined: Wed Jul 04, 2007 3:51 pm
Location: Buenos Aires - Argentina

Re: Agregar fila a Excel TOleAuto

Postby jrestojeda » Tue Aug 09, 2016 12:28 pm

Por ahora la solución que estoy aplicando es agregar un registro vacio en la dbf. Lo cual no me agrada demasiado, ya que me gustaría hacerlo bien!! jeje
Ojeda Esteban Eduardo.
Buenos Aires - Argentina.
FWH - PellesC - DBF/CDX - ADS - Gloriosos .Bat - MySql - C# .net - FastReport
Skype: jreduojeda
User avatar
jrestojeda
 
Posts: 601
Joined: Wed Jul 04, 2007 3:51 pm
Location: Buenos Aires - Argentina

Re: Agregar fila a Excel TOleAuto

Postby alerchster » Tue Aug 09, 2016 3:02 pm

oHoja:Rows("1:1"):Insert()
Regards

Ing. Anton Lerchster
User avatar
alerchster
 
Posts: 81
Joined: Mon Oct 22, 2012 4:43 pm

Re: Agregar fila a Excel TOleAuto

Postby jrestojeda » Tue Aug 09, 2016 3:09 pm

Perfecto amigo, funciona!!
Muchas gracias!!
Ojeda Esteban Eduardo.
Buenos Aires - Argentina.
FWH - PellesC - DBF/CDX - ADS - Gloriosos .Bat - MySql - C# .net - FastReport
Skype: jreduojeda
User avatar
jrestojeda
 
Posts: 601
Joined: Wed Jul 04, 2007 3:51 pm
Location: Buenos Aires - Argentina


Return to FiveWin para Harbour/xHarbour

Who is online

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