TGRAPH, enviar el grafico a Excel..

TGRAPH, enviar el grafico a Excel..

Postby Willi Quintana » Sun Feb 22, 2015 4:44 pm

Hola Amigos.
Estoy utilizando la clase tGraph, hay alguna manera de enviar directamente el grafico a Excel??
Salu2
Willi
User avatar
Willi Quintana
 
Posts: 1004
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú

Re: TGRAPH, enviar el grafico a Excel..

Postby AngelSalom » Mon Feb 23, 2015 4:55 pm

Willi, hace un tiempo creé una función para crear una gráfica directamente a Excel. Los valores que se le pasan son similares a los usados para tGraph. Aquí te lo dejo por si te sirve.

Code: Select all  Expand view
#include "fivewin.ch"

Function Main()
  GraficaExportaExcel ({"Ene","Feb","Mar"},{{1,1000},{2,1500},{3,1300}},{"Ventas"},3,1,"Titulo Gráfica","Subtitulo")
Return (nil)

Function GraficaExportaExcel (aDatosEtiquetas, aValores, aLeyendas, nElementos, nProfundidad, cTitulo)  
/* ===================================================================================
   Realiza la exportación a Excel de la gráfica, datos y gráfico generados
   Revisión : 11/06/2014 19:42:48
   
   (cells [y,x])
   ===================================================================================
 */

Local oExcel, oLibro, oHoja, oChart, oSourceData, oWin, nCol, nSerie, cRango

  If MsgYesNo ("¿Generar hoja de cálculo con los datos y gráfica?","Por favor confirme")
    If ( oExcel := ExcelObj() ) <> nil
      oExcel:ScreenUpdating := .f.
      oLibro := oExcel:WorkBooks:Add()
      oHoja  := oExcel:ActiveSheet
   
      // Titulos ejeX
      For nCol:=1 To Len (aDatosEtiquetas)
        oHoja:Cells( nCol+1,1 ):Value := aDatosEtiquetas[nCol]; oHoja:Cells ( nCol+1, 1 ):Font:Bold:=.T.
      Next
   
      For nSerie:=1 To nProfundidad
        // Series
        oHoja:Cells ( 1,1+nSerie):Value :=aLeyendas[nSerie]
           
        // Importes
        For nCol:=1 To Len (aValores)
          oHoja:Cells( nCol+1,nSerie+1 ):Value := aValores[nCol,nSerie]
        Next
      Next
   
      // Grafico
      cRango:="A1:"+Chr(65+nProfundidad)+Alltrim(Str(Len(aValores)+1))
      oHoja:Range(cRango):Select()
      oChart := oExcel:Charts:Add()
      oChart:ChartType := 4
   
      oSourceData := oHoja:Range(cRango)
      oChart:SetSourceData(oSourceData) //, PlotBy := 2 // xlColumns
   
      oChart:HasLegend := .T.
      oChart:Legend:Position := -4107 // xlBottom
   
      oChart:HasTitle := .T.
      oChart:ChartTitle:Characters:Text := cTitulo
   
      TRY
        oChart:ApplyDataLabels:Set("LegendKey", .T. )
        oChart:ApplyDataLabels:Set("HasLeaderLines", .T. )
        oChart:ApplyDataLabels:Set("ShowValue", .T. )
        oChart:ApplyDataLabels:Set("AutoText", .T. )
        oChart:ApplyDataLabels:Set("ShowBubbleSize", .F. )
      CATCH
      END
       
      oExcel:ScreenUpdating   := .T.
      oExcel:visible          := .T.
      ShowWindow( oExcel:hWnd, 3 )
      BringWindowToTop( oExcel:hWnd )
    Else
      MsgAlert ("Para poder exportar los datos debe tener Microsoft Excel instalado en el sistema","Atención")
    Endif
  Endif
Return (nil)  
 
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 708
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 120 guests