Hola amigos, últimamente vengo usando TGraph con asiduidad. Hace ya un tiempo publiqué una función para generar una gráfica en Excel a partir de unos valores dados. Ahora la he adaptado para incluirla en la clases TGraph de modo que se puede exportar cualquier gráfica ya generada. Queda pulir el tipo de gráfico que se generará (ahora son lineas).
Saludos,
METHOD Save2XLS () CLASS TGraph
Local oExcel, oLibro, oHoja, oChart, oSourceData, 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 eje
For nCol:=1 To Len (::aYVals)
oHoja:Cells( nCol+1,1 ):Value := ::aYVals[nCol]; oHoja:Cells ( nCol+1, 1 ):Font:Bold:=.T.
Next
For nSerie:=1 To Len (::aSeries)
// Series
oHoja:Cells ( 1,1+nSerie):Value :=::aSeries[nSerie,1]
// Importes
For nCol:=1 To len(::aYVals)
oHoja:Cells( nCol+1,nSerie+1 ):Value := ::aData[nSerie,nCol]
Next
Next
// Grafico
cRango:="A1:"+Chr(65+Len(::aSeries))+Alltrim(Str(Len(::aYVals)+1))
oChart := oExcel:Charts:Add()
oChart:ChartType := 4 // Gráfica de Líneas
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 := ::cTitle
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)Saludos,
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4