/*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("Ita lic",true);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertyGet("Font").OlePropertySet("Bol d",true);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertyGet("Font").OlePropertySet("Siz e",13);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertyGet("Font").OlePropertySet("Col or",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").OlePropertyS et("Bold",true);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1+indice,1).OlePropertyGet("Font").OlePropertyS et("Size",10);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1+indice,1).OlePropertyGet("Font").OlePropertyS et("Color",clAqua);
MiHoja.OlePropertyGet("Cells").OlePropertyGet("Item",1+indice,1).OlePropertyGet("Interior").OlePrope rtySet("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 16");
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
|