FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour TGRAPH, enviar el grafico a Excel..
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM

TGRAPH, enviar el grafico a Excel..

Posted: Sun Feb 22, 2015 04:44 PM

Hola Amigos.
Estoy utilizando la clase tGraph, hay alguna manera de enviar directamente el grafico a Excel??
Salu2
Willi

Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM

Re: TGRAPH, enviar el grafico a Excel..

Posted: Mon Feb 23, 2015 04: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 (fw): Select all Collapse
#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

Continue the discussion