alt126
09-03-2005, 12:49:43
A ver si sabe alguien si es posible desde una aplicacion builder c++, ademas de generar un documento excel (que si se puede), generar una grafica en ese documento excel....
Gracias,
Antonio
/*Este es el fuente, al final esta el dfm*/
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
}
void __fastcall TForm1::ComboBox1Select(TObject *Sender)
{
try
{ Variant Excel = Variant::CreateObject("Excel.Application");
Excel.OlePropertySet("Visible",true);
Variant MiColeccionLibros=Excel.OlePropertyGet("Workbooks");
MiColeccionLibros.OleProcedure("Add");
Variant MiLibro=MiColeccionLibros.OlePropertyGet("Item",1);
Variant MIColeccionHojas=MiLibro.OlePropertyGet("Worksheets") ;
MIColeccionHojas.OlePropertyGet("Item",1).OlePropertySet("Name","Hoja Uno");
Variant MiHoja=MIColeccionHojas.OlePropertyGet("Item",1);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertyGet("Font").OlePropertySet("Italic",true);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertyGet("Font").OlePropertySet("Bold",true);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertyGet("Font").OlePropertySet("Size",13);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertyGet("Font").OlePropertySet("Color",clNavy);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertySet("Value","Celdas:");
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertyGet("Interior").OlePropertySet("ColorIndex",ExcelAzulOscuro);
for (int indice=1;indice<=12;indice++)
{ MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1+indice,1).OlePropertyGet("Font").OlePropertySet("Bold",true);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1+indice,1).OlePropertyGet("Font").OlePropertySet("Size",10);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1+indice,1).OlePropertyGet("Font").OlePropertySet("Color",clAqua);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1+indice,1).OlePropertyGet("Interior").OlePropertySet("ColorIndex",ExcelAzulOscuro);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1+indice,1).OlePropertySet("Value",indice*rand());
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1+indice,1).OlePropertySet("NumberFormat","#.##0");
}
/*
RANGO DE CELDAS PARA LA GRAFICA
*/
Variant MiRango=MiHoja.OlePropertyGet("Range","A2:A13");
/*
GRAFICAS
*/
Variant MiColeccionGraficos=MiHoja.OlePropertyGet("ChartObjects");
MiColeccionGraficos.OleProcedure("Add",5,300,430,250);
Variant MiGrafico=MiColeccionGraficos.OlePropertyGet("Item",1);
AnsiString TituloPrincipal="TITULO";
AnsiString TituloEjeY="Eje Y";
AnsiString TituloEjeX="Eje X";
int Leyenda=1;
/*
1 con leyenda
0 sin leyenda
*/
int SeriesLabels=0;
/*
The number of rows or columns containing series labels
?????????
*/
int CategoryLabels=0;
/*
The number of rows or columns containing category labels
??????????
*/
int ContruccionGrafica=6;
/*
7-> barras con valores
6-> barras sin valores
5-> barras complementarias
*/
int TipoGrafico=ComboBox1->Text.SubString(0,(ComboBox1->Text.AnsiPos("-")-2)).ToInt();
/*
2 por barras horizontales
3 por barras verticales
5 tarta
11 por barras 3d
13 por tarta 3d
*/
MiGrafico.OlePropertyGet("Chart").OleProcedure("ChartWizard",
MiRango,
TipoGrafico,
ContruccionGrafica,
2,
CategoryLabels,
SeriesLabels,
Leyenda,
TituloPrincipal.c_str(),
TituloEjeX.c_str(),
TituloEjeY.c_str());
/*
CODIGO PARA CREAR UN GRAFICO
INDEPENDIENTE DE LA HOJA
COMO OBJETO AUTONOMO
Variant MiColeccionGraficos=MiLibro.OlePropertyGet("Charts");
MiColeccionGraficos.OlePropertyGet("Add");
Variant MiGrafico=MiColeccionGraficos.OlePropertyGet("Item",1);
Variant MiColeccionSeries= MiGrafico.OlePropertyGet("SeriesCollection");
MiColeccionSeries.OleProcedure("Add",MiRango);
MiRango=SegundaHoja.OlePropertyGet("Range","C5:C16");
MiColeccionSeries.OleProcedure("Add",MiRango);
MiRango=SegundaHoja.OlePropertyGet("Range","D5:D16");
MiColeccionSeries.OleProcedure("Add",MiRango);
*/
Excel=Unassigned;
}
catch(...)
{
ShowMessage("FALLO EN APLICACION 'EXCEL'.");
}
}
/* EL DFM*/
object Form1: TForm1
Left = 317
Top = 169
Width = 388
Height = 127
Caption = 'GRAFICAS EXCEL'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 40
Top = 43
Width = 79
Height = 13
Caption = 'Tipo de Gr'#225'fica :'
end
object ComboBox1: TComboBox
Left = 128
Top = 40
Width = 209
Height = 21
AutoDropDown = True
ItemHeight = 13
TabOrder = 0
OnSelect = ComboBox1Select
Items.Strings = (
'2 - por barras horizontales'
'3 - por barras verticales'
'5 - tarta'
'11 - por barras 3d'
'13 - por tarta 3d')
end
end
alt126
10-03-2005, 09:45:27
Me ha sido de gran ayuda!!!
Gracias,
Antonio
alt126
10-03-2005, 10:41:37
Para poner las labels de las categorias? En el codigo que pusiste solo pone, la grafica, pero pone titulos de categorias por defecto. HAy algunamanera de indicarle tu que titulos quieres que aparezcan?
Solo he visto la propiedad "CategoryLabels", y no se muy bien para que se utiliza, porque se supone que habria que poner un rango de celdas igual que para las series de datos.
Gracias,
Antonio
vBulletin v3.6.8, Derechos ©2000-2024, Jelsoft Enterprises Ltd.