La Web del Programador: Comunidad de Programadores
 
    Pregunta:  60902 - ABRIR EXCEL 2007 DESDE VFP9
Autor:  Elsy Pitillo
Como se abre un libro u hoja de Excel 2007 desde VFP9?
con Excel 2003 o inferiores no he tenido problemas con el siguiente codigo:

loExcel=CREATEOBJECT("Excel.application")

WITH loExcel
.application.workbooks.open("c:alance.xls")
....
.application.visible = .t.
ENDWITH
WAIT "Presione Enter para Salir"
loexcel.quit()
STORE .null. to loexcel,lolibro

Pero con Excel 2007 no furula..!!

  Respuesta:  Mario Rodriguez
**** te mando una rutina con la que esporto mis bases de datos y le da formato a mi informaicón

**** este es el codigo:

*** variables a crear

*xc_basexlf = "vact" && nombre de la base
*xc_fxlf = "vacaciones"
*xc_nhoja = "reporte"
*xc_title = "Reporte de vacaciones"
*xc_datf1 = "Empleado: " + "RODRIGUEZ VAZQUEZ MARIO"
*xc_datf2 = "Fecha de ingreso: " + DTOC({^2002-09-11})
*xc_foot1 = "Reporte de vacaciones por empleado"

xc_datf3 = "Reporte al dia: " + DTOC(DATE())
xc_foot2 = "Creado desde "+ ccredit

#DEFINE xlAutomatic -4105
#DEFINE xlCenter -4108
#DEFINE xlLeft -4131
#DEFINE xlMedium -4138
#DEFINE xlNone -4142
#DEFINE xlPrintNoComments -4142
#DEFINE xlContinuous 1
#DEFINE xlDownThenOver 1
#DEFINE xlPaperLetter 1
#DEFINE xlLandscape 2
#DEFINE xlThin 2
#DEFINE xlThick 4
#DEFINE xlDiagonalDown 5
#DEFINE xlPaperLegal 5
#DEFINE xlDiagonalUp 6
#DEFINE xlEdgeLeft 7
#DEFINE xlEdgeTop 8
#DEFINE xlEdgeBottom 9
#DEFINE xlEdgeRight 10
#DEFINE xlInsideVertical 11
#DEFINE xlColorRojo 3
#DEFINE xlColorAzul

LOCAL num_fil

SELECT &xc_basexlf
GOTO top
num_fil = RECCOUNT()+7
num_col = fcount()

DO CASE && PARA DETERMINAR COLUMNAS COMBINADAS si hay muchos campos

CASE FCOUNT() < 27
cColu = ALLTRIM(CHR(64+FCOUNT()))
CASE BETWEEN(FCOUNT(),27,52)
cColu = CHR(65)+ALLTRIM(CHR(64+(FCOUNT()-26)))
CASE BETWEEN(FCOUNT(),53,78)
cColu = CHR(66)+ALLTRIM(CHR(64+(FCOUNT()-52)))
CASE BETWEEN(FCOUNT(),79,104)
cColu = CHR(67)+ALLTRIM(CHR(64+(FCOUNT()-78)))

OTHERWISE
cColu = "AZ"

ENDCASE

cFile = '"'+xc_fxlf + '.xls"'
cFilr = xc_fxlf + '.xls'
cFilo = '"'+xc_fxlf +'"'

IF FILE(&cFile ) = .t.
answer = MESSAGEBOX("El archivo "+ cFilr + " ya existe" + CHR(13)+;
"Pulse reintentar para eliminar el archivo actual," + CHR(13)+;
" o cancelar el proceso",21,ccredit + " Archvo existente")

DO case
CASE answer = 2
RETURN

CASE answer = 4
ERASE &cFilr
COPY TO &cFilr TYPE xl5
otherwise
RETURN

ENDCASE
else
COPY TO &cFilr TYPE xl5
ENDIF

***Ahora vamos a trabajar con una planilla ya creada. Creamos nuevamente el objeto Excel:
loExcel=CREATEOBJECT("Excel.application")
loExcel.APPLICATION.VISIBLE=.T.

**Abrimos el libro Excel que ya existe:
loExcel.APPLICATION.workbooks.OPEN(&cFilo)

**Cambiamos el nombre de la hoja activa:
loExcel.APPLICATION.activesheet.NAME = "Reporte"

**Hacemos referencia directamente a "Reporte", y ponemos valores en una celda y le damos formato:
loExcel.APPLICATION.Sheets("Reporte").Rows("1:5").Insert

**loExcel.APPLICATION.Sheets("Reporte").cells(1,1).NumberFormat = "0.00%"

XLSheet = loExcel.APPLICATION.ActiveSheet

* .LineStyle = xlContinuous
* .Weight = xlThin
* .ColorIndex = xlAutomatic


lcRango= "A1:"+ccolu+ALLTRIM(STR(num_fil))

range_s2 = "A7:"+ccolu++ALLTRIM(STR(num_fil))
range_s2r = '"'+range_s2+'"'

*range_s3 = "F7:S"+ALLTRIM(STR(num_fil))
*range_s3r = '"'+range_s3+'"'

WITH XLSheet.Range(&range_s2r)
.Font.Size= 9
.Interior.ColorIndex = 2 && 19 amarillo
.borders(4).LineStyle= 2
.borders(4).Weight = 1
.borders(4).Colorindex= 1
ENDWITH


loExcel.APPLICATION.Sheets("Reporte").cells(1,3).VALUE = xc_title
* .HorizontalAlignment=xlCenter &&Aliniar al centro *
* .VerticalAlignment=xlCenter
**** formato del encabezado principal
xc_titrg = '"c1:'+ccolu+'1"'
WITH XLSheet.Range(&xc_titrg )
.Merge
.Font.Bold=.t.
.Font.Size=16
.HorizontalAlignment=xlCenter
.Interior.ColorIndex = 20

ENDWITH

*** configurando encabezado **
xc_rhead = '"a6:'+ccolu+'6"'

WITH XLSheet.Range(&xc_rhead)
.borders(9).LineStyle= 3
.borders(9).Weight = 3
.borders(9).Colorindex= 1
.Font.Bold=.t.
.Font.Size= 9
.HorizontalAlignment=xlCenter
.Interior.ColorIndex = 15
ENDWITH

For i = 1 TO num_col
xc_headv = loExcel.APPLICATION.Sheets("Reporte").cells(6,i).VALUE
loExcel.APPLICATION.Sheets("Reporte").cells(6,i).VALUE = UPPER(ALLTRIM(xc_headv))
ENDFOR


range_sq = "A6:"+ccolu+ALLTRIM(STR(num_fil))
range_sqr = '"'+range_sq+'"'

WITH XLSheet.Range(&range_sqr).Borders(3)&&xlEdgeLeft
XLSheet.Columns().AutoFit
ENDWITH


*** .Interior.ColorIndex = 15 GRIS 10 VERDE 1 NEGRO 2 BLANCO 3 ROJO 4 VERDE CLARO
** 5 AZUL INTENSO 6 AMARILLO 7 FUISHA 8 CYAN 9 MARRON 11 AZUL FUERTE12 AMARILLO OBSCURO
** 13 MORADO 14 VERDE AZUL 16 GRIS 17 LILA 19 AMARILLO CLARO 20 AZUL

loExcel.APPLICATION.Sheets("Reporte").cells(2,4).VALUE = xc_datf1
**loExcel.APPLICATION.Sheets("Reporte").cells(1,1).NumberFormat = "#,##0.00"
loExcel.APPLICATION.Sheets("Reporte").cells(3,4).VALUE = xc_datf2
loExcel.APPLICATION.Sheets("Reporte").cells(4,4).VALUE = xc_datf3

LOCAL lcImagen, lcPlanilla, lo
*-- Selecciono imagen y nombre de planilla (xls)
lcImagen = MYPATH+"SALIDAGRAFICA.BMP" &&&GETPICT() obvio debes tener el archivo salidagrafica.bmp
*-- Selecciono la celda donde estará la posición de la imagen

loExcel.Cells(1,1).Select
loExcel.ActiveSheet.Pictures.Insert(lcImagen).Select
loExcel.Selection.ShapeRange.LockAspectRatio = 0
loExcel.Selection.ShapeRange.Height = 58 && pixeles
loExcel.Selection.ShapeRange.Width = 90 && pixeles

*** configurar area de impresion

with loExcel.APPLICATION.ActiveSheet.PageSetup
.TopMargin = 60
.BottomMargin = 80
.RightMargin = 30
.LeftMargin = 30
.LeftFooter = cempresa + " " + xc_foot1 + " - " + xc_foot2
.PrintHeadings = .f.
IF xc_land = .t. && esta variable la asigno cuando tengo muchos campos
.Orientation = xlLandscape
ENDIF
***.Orientation = xlLandscape
.PaperSize = xlPaperLetter
.PrintArea = lcRango

ENDWITH

loExcel.Cells(6,1).Select

loExcel.APPLICATION.activeworkbook.SAVE
**loExcel.APPLICATION.QUIT && las desactive para que el usuairo pueda ver archivo
**RELEASE loExcel

espero te sirva de algo
saludos : -

  Respuesta:  erick teran
select cliente
go bottom
declare INTEGER ShellExecute in shell32 INTEGER handle, STRING @ oper, ;
STRING @ ifile, STRING @ iparam, STRING @ ipath, INTEGER showcmd
lcFileName = cliente.imagen
=shellexecute(0,"open",lcFileName,"","c:",1)

con ese codigo abro imagenes
solo reemplaza el nombre del archivo por el que tu quieras
te abre cualquier archivo bueno ami me lo hace
sea de excel de word de acrobat etc etc
espero te sirva
suerte