Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Exporting Data To Excel...
Message
 
To
30/09/2005 18:17:42
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01055133
Message ID:
01055245
Views:
11
Debes usar Excel Automation. Aqui te pongo parte del código que utilizo para esto. Si deseas experimentar con las propiedades y métodos de excel basta con ejecutar el comando Objeto = CREATEOBJECT("Excel.Application") desde la línea de comando y luego al utilizar Objeto. el intellisense te dará una lista de las propiedades, métodos y eventos que puedes accesar.

HTH,

Enmanuel
cDeleted = SET("Deleted")
SET DELETED ON 
cSele = [SELECT ]+This.Tabla 

This.Unidad=[]

IF EMPTY(This.Archivo)
	This.Archivo="*.xls"
ENDIF 

This.Unidad=GETDIR("c:\",ALLTRIM(This.Archivo),"Guardar Como Hoja De Excel",64) 
IF EMPTY(This.Unidad)
	RETURN 0
ENDIF

        *--- Aqui debes manejar si Excel existe o no
        *--- Preferiblemente con una rutina try/cath
	This.Objeto  = CREATEOBJECT("Excel.Application")
	This.Objeto.Visible=.f.
	This.Objeto.WorkBooks.Add

	nFields=FCOUNT(This.Tabla)-1
	nReg=1


	&cSele
	AFIELDS(arrFields)
	*--- Encabezados
	This.Objeto.Cells(1,1).Value=[CODIGO]
	This.Objeto.Cells(1,2).Value=[NOMBRE DEL CLIENTE]
	This.Objeto.Cells(1,3).Value=[CEDULA O RNC]
	This.Objeto.Cells(1,4).Value=[DIRECCION]
	This.Objeto.Cells(1,5).Value=[TELEFONO]
	This.Objeto.Cells(1,6).Value=[LIMITE DE CREDITO]
	This.Objeto.Cells(1,7).Value=[0 A 30 DÍAS]
	This.Objeto.Cells(1,8).Value=[31 A 60 DÍAS]
	This.Objeto.Cells(1,9).Value=[61 A 90 DÍAS]
	This.Objeto.Cells(1,10).Value=[91 A 120 DÍAS]
	This.Objeto.Cells(1,11).Value=[121 A 150 DÍAS]
	This.Objeto.Cells(1,12).Value=[151 A 180 DÍAS]
	This.Objeto.Cells(1,13).Value=[181 O MÁS DÍAS]
	This.Objeto.Cells(1,14).Value=[TOTAL DE ATRASO]
	This.Objeto.Cells(1,15).Value=[FECHA ULTIMO PAGO]
	This.Objeto.Cells(1,16).Value=[MONTO ULTIMO PAGO]
	This.Objeto.Cells(1,17).Value=[ESTATUS]
	This.Objeto.Cells(1,18).Value=[DESCRIPCION ESTATUS]
	
	*--- Ancho de las columnas
	This.Objeto.Columns(1).ColumnWidth=12  && Codigo
	This.Objeto.Columns(2).ColumnWidth=40  && Nombre
	This.Objeto.Columns(3).ColumnWidth=25  && Cedula
	This.Objeto.Columns(4).ColumnWidth=60  && Direccion
	This.Objeto.Columns(5).ColumnWidth=25  && Telefono
	This.Objeto.Columns(6).ColumnWidth=20  && Limite de credito
	This.Objeto.Columns(7).ColumnWidth=17  && 0-30
	This.Objeto.Columns(8).ColumnWidth=17  && 31-60
	This.Objeto.Columns(9).ColumnWidth=17  && 61-90
	This.Objeto.Columns(10).ColumnWidth=17  && 91-120
	This.Objeto.Columns(11).ColumnWidth=17  && 121-150
	This.Objeto.Columns(12).ColumnWidth=17  &&151-180
	This.Objeto.Columns(13).ColumnWidth=17  && 181 o mas
	This.Objeto.Columns(14).ColumnWidth=20  && Atraso
	This.Objeto.Columns(15).ColumnWidth=25  && Fecha ult pago
	This.Objeto.Columns(16).ColumnWidth=25  && monto ult pago
	This.Objeto.Columns(17).ColumnWidth=10  && Estatus
	This.Objeto.Columns(18).ColumnWidth=25  && Descripcion estatus
	
	*--- Pongo encabezado en negrita,encierro la celda entre lineas y cambio el color de fondo
	FOR x=1 TO 18
		This.Objeto.Cells(1,x).Font.Bold=.t.
		This.Objeto.Cells(1,x).Borders.LineStyle=1
		This.Objeto.Cells(1,x).Select
		This.Objeto.Selection.Interior.ColorIndex=36
		
		IF x>=6 AND x<=14
			This.Objeto.Selection.VerticalAlignment=3
		ENDIF 
		
	NEXT 
	
		nReg=nReg+1
	SCAN 
		
		FOR x=1 TO nFields  &&& Asigno los valores de las celdas
			cCampo=This.Tabla+[.]+arrFields(x,1)

			IF TYPE(cCampo)='T'
				cCampo=[TTOD(]+This.Tabla+[.]+arrFields(x,1)+[)]
			ENDIF

			cObj = [This.Objeto.Cells(nReg,x).Value=]+cCampo				
			&cObj
			
			*-- Formatos de celda
			IF INLIST(TYPE(cCampo),[N],[Y])
			   This.Objeto.Cells(nReg,x).NumberFormat=[###,###,###,##0.00]
			ENDIF 

		NEXT 
		nReg=nReg+1
	ENDSCAN 

	*--- Si no voy a hacer ningun proceso despues de salvar todos los datos
	IF This.SalvaAlTerminar 
		This.Salvar 
	ENDIF

oPr=Null 
SET DELETED &cDeleted	

Thisform.Mensaje("Archivo Exportado Con Éxito!",4)

Thisform.CtnOpciones.OleFecha.Object.Enabled=.t.
Thisform.Width=nWidth 
Thisform.Refresh 
>Hello There...
>
> Don't know if this is the place to ask about my doubt/problem, but there it goes...
>
> I want to export my data into a Excel file, but I want the result file to be formatted so I can open it and send it to the printer. How can I give the format to a file via coding so the result excel file will be like I wish?
>
> Thanks in advance...!!!
>
>Onelio
I'm a mixture of Albert Einstein and Arnold Schwarzenegger. The only trouble is that I got Einstein's body and Schwarzenegger's brain
Previous
Reply
Map
View

Click here to load this message in the networking platform