#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)lo encontre en el foro, el autor no lo recuerdo, tampoco lo he probado pero se ve funcional.
Saludos

