Page 1 of 1

Abrir EXCEL

Posted: Thu Jun 02, 2016 8:28 am
by Loren
Compañeros, buenos días:

Genero un EXCEL a través de la clase TEXCEL, pero una vez generado exitosamente NO soy capaz de que se abra automáticamente. Se "esconde" detrás de la windows de mi aplicación.
Obligatoriamente tengo que pulsar en el teclado la tecla "windows" para que se abra la barra de herramientas de windows y pueda seleccionar el EXCEL.

¿ Cómo puedo hacerlo para que se abra automáticamente?

Adjunto Mi código:

Code: Select all

funct exporgas()
  Local oSheet,oBook, x, ttotal:=0
  oExcel:=CreateObject( "excel.application" )
  oExcel:DisplayAlerts=.F.
  oBook :=oExcel:Workbooks:Add()
  oSheet:=oExcel:ActiveSheet
  oSheet:Cells( 1,01):Font:Size := 15
  oSheet:Cells( 1,01):Value =alltrim(nempresa)
  oSheet:Cells( 2,01):Value ='Listado / Informe de Gastos'
  oSheet:Cells( 3,01):Value =tit
  oSheet:Cells( 4,01):Value ='Fecha listado: '+dtoc(date())
  oSheet:range( "A5","J5"):Interior:Color := RGB(195,195,195)
  oSheet:Cells( 5,01):Value ='Centro de trabajo'      ; oSheet:Columns( 1 ):ColumnWidth := 20
  oSheet:Cells( 5,02):Value ='Nombre del proveedor'   ; oSheet:Columns( 2 ):ColumnWidth := 30
  oSheet:Cells( 5,03):Value ='Nº doc'
  oSheet:Cells( 5,04):Value ='Fecha'
  oSheet:Cells( 5,05):Value ='Importe'
  if lfpago=.t.
   oSheet:Cells( 5,06):Value ='Estado'   ; oSheet:Columns( 6 ):ColumnWidth := 30
  endif
  if obs=.t.
   oSheet:Cells( 5,07):Value ='Observaciones' ; oSheet:Columns( 7 ):ColumnWidth := 30
  endif
  select 14 ; gastos->(dbgotop())
  x=6
  do while .not. eof()
   if &condicion
    oSheet:Cells(x,01):Value=bcentro(gastos->centro,'14')
    oSheet:Cells(x,02):Value=nombre
    oSheet:Cells(x,03):Value=factura
    oSheet:Cells(x,04):Value=fecha
    oSheet:Cells(x,05):Value=gastos->total   ; oSheet:Cells( x,05):NumberFormat := "0,00 €"
    ttotal+=gastos->total
    if lfpago=.t.
     oSheet:Cells(x,06):Value=alltrim(pagado)+iif(!empty(fpago),' ('+alltrim(fpago)+')','')
    endif
    if obs=.t.
     oSheet:Cells(x,07):Value=observa1 ; x++
     oSheet:Cells(x,07):Value=observa2 ; x++
     oSheet:Cells(x,07):Value=observa3
    endif
    x++
   endif
   skip
  enddo
  x++
  oSheet:Cells(x,04):Value='Total:'
  oSheet:Cells(x,05):Value=ttotal   ; oSheet:Cells( x,05):NumberFormat := "0,00 €"
  oExcel:Visible = .T.
Return Nil
Gracias.
LORENZO.

Re: Abrir EXCEL

Posted: Thu Jun 02, 2016 8:44 am
by AngelSalom

Re: Abrir EXCEL

Posted: Thu Jun 02, 2016 11:42 am
by Loren
Funcionó perfecto!!
Mil gracias.

LORENZO.

PD.: Para aquellos que tengan curiosidad, solo tuve que añadir al final de mi código lo siguiente:

hWnd:=oExcel:hWnd
ShowWindow(hWnd, 3) //SW_MAXIMIZE=3 SW_NORMAL=1 SW_MINIMIZE=6
BringWindowToTop(hWnd)

... y listo!!

Re: Abrir EXCEL

Posted: Thu Jun 02, 2016 1:07 pm
by AngelSalom
:lol: :lol: :lol: