Mi experiencia con Exc el

Mi experiencia con Exc el

Postby D.Fernandez » Fri Nov 03, 2017 4:46 pm

Amigos pos si a alguien le sirve, algunos tips para Excel.
LAs saque del foro y hay más.
Saludos
Ruben Dario Fernandez

Code: Select all  Expand view

#define xlContinuous 1
#define xlDash -4115
#define xlDashDot 4
#define xlDashDotDot 5
#define xlDot -4118
#define xlDouble -4119
#define xlSlantDashDot 13
#define xlLineStyleNone -4142


// Border positions
#define xlEdgeLeft 7
#define xlEdgeTop 8
#define xlEdgeBottom 9
#define xlEdgeRight 10
#define xlCenter -4108



FUNCTION PASARAEXCEL()  
    LOCAL oExcel,oBook, oSheet,xl:=0, oHoja
    Local oXLS,  nFormat, nFormat2, nFont, nLen, nCol, nFila, x, cText,cNom,cSal1:= 0 ,cSal2:=0 ,nFont1
    Local xlCuenta, xlNombre, xlDDolar:=0 ,xlHDolar:=0,xlPDebe:=0, xlPHaber:=0, cFile, cFileAGuardar

    cFileAGuardar:= "Nombre")
    cFile :=   xTrim(cFileAGuardar)+ "-SaldosTotales.xls"
// xTrim() es una función que junta ltrim() y rtrim().
    cFile:= xTrim(cFile)
    oExcel := ExcelObj()
//  Inicio
    If oExcel == nil
       MsgInfo("Excel no está instalado", "Informe")    
       RETURN(.F.)
    Endif
 
    oExcel := TOleAuto():New("Excel.Application")
    oExcel:WorkBooks:Add()
    oExcel:oHoja("Hoja1") ; oHoja:=oExcel:ActiveSheet()
    oHoja:Cells:Font:Name := "Arial"       // nombre fuente
    oHoja:Cells:Font:Size:= 8             // tamaño fuente        
    oHoja:PageSetup:Orientation := 1        // vertical
    oExcel:DisplayAlerts := .F.        // no da mensajes

    // rango para combinar celdas 2 o mas para el título centrado
    oRange:= oHoja:Range("B2:E2")
    oRange:MergeCells:= .T.
    oRange:HorizontalAlignment:=xlCenter


    // otro rango para centrar a la derecha  
    oRange:= oHoja:Range("C6:F6")
    oRange:MergeCells:= .F.
    oRange:HorizontalAlignment:= -4152               //xlRight

    // fuente y recuadro  
    oHoja:Range("A6:F6"):Font:Name:= "Verdana"  
    oHoja:Range("A6:F6"):Font:Size := 10  
    oHoja:Range("A6:F6"):Font:Bold := .T.  

///Aquí hace los bodes top, left,right y bottom
    oHoja:Range("A6:F6"):Borders(7):LineStyle := 1  
    oHoja:Range("A6:F6"):Borders(8):LineStyle := 1  
    oHoja:Range("A6:F6"):Borders(9):LineStyle := 1  
    oHoja:Range("A6:F6"):Borders(10):LineStyle := 1  
 
    // agrego imagen, título
    oHoja:Shapes:AddPicture("C:\AlfaInmo\logocolor.jpg",.t.,.t.,5,5,80,60)
    oHoja:Cells(2,2):Font:Name := "Verdana"  
    oHoja:Cells(2,2):Font:Size := 12  
    oHoja:Cells(2,2):Font:Bold := .T.
    oHoja:Cells(2,2):Value:= "INMOBILIARIA..."
    oHoja:Cells(2,2):Font:Bold := .T.
    oHoja:Cells(3,2):Value:= "Reporte de todos los saldos realizado el : "+DtoC(Date())
    oHoja:Cells(4,2):Value:= "Saldos al mes : " + dMesaVer
    oHoja:Range("A6:D6"):Interior:Color:= RGB(180,180,180)
    // aqui color interior del rango


    // declaro el ancho de las columnas    
    oHoja:Columns(2):ColumnWidth:= 34
    oHoja:Columns(3):ColumnWidth:= 12
    oHoja:Columns(4):ColumnWidth:= 12
    oHoja:Columns(5):ColumnWidth:= 12
    oHoja:Columns(6):ColumnWidth:= 12
 

nFila:=7 ; nCol:=1
DBPLANI:GOTOP()
Do While !DBPLANI:Eof()
       
     oHoja:Cells(nFila,nCol):Value := DBPLANI:CODCLI
     nCol+=1
     oHoja:Cells(nFila,nCol):Value := DBPLANI:codnom
     nCol+=1
     xoHoja:Cells(nfila,ncol):NumberFormat := " ###,##0.00"    
     oHoja:Cells(nFila,nCol):Value := DBPLANI:saldo1
     nCol+=1
     oHoja:Cells(nFila,nCol):Value := DBPLANI:saldo2
     nCol+=1
     oHoja:Cells(nFila,nCol):Value := DBPLANI:saldo3
     nCol+=1
     oHoja:Cells(nFila,nCol):Value := DBPLANI:saldo4
     nCol:=1
     nFila+=1
     DBPLANI:Skip()
Enddo
DBPLANI:GOTOP()


    oHoja := oExcel:ActiveSheet()
    oExcel:Visible := .T.
    //oHoja:SaveAs("c:\alfainmo\"+cFile )    // si la quiero salvar descomento
    Hb_GCall(.T.)
 

    Return(.F.)
Dario Fernandez
FWH 22.12, Harbour, MVS2022 Community, BCC, MySql & MariaDB, Dbf/Cdx VSCode.
Maldonado - Uruguay
D.Fernandez
 
Posts: 455
Joined: Wed Jul 31, 2013 1:14 pm
Location: Maldonado - Uruguay

Return to FiveWin para Harbour/xHarbour

Who is online

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