Delphi + Excel + Chart +range’s variáveis
Estou tentando gerar um gráfico no Excel a partir do Delphi, já consegui criar o gráfico e formatá-lo.
Mas no gráfico de pizza quando preciso selecionar range’s variáveis não dá certo, só funciona se forem consecutivas.
Por exemplo as coluna A1:A8 e G1:G8, já tentei pelo endereço da range, mas dá um erro.
Segue abaixo
Variaveis:
Lcid : integer;
ChObj : ChartObject;
xrange2 : Variant; // já tentei tipo range
xrange1 : Variant; // já tentei tipo range
Objetos :
ExcelApplication1
ExcelWorksheet1
ExcelChart1
Após gerar a planilha as linhas abaixo tentam gerar o gráfico,
Se as range’s forem consecutivas funciona bem direitinho, veja abaixo:
lcid := GetUserDefaultLCID; //LOCALE_USER_DEFAULT ;
ChObj:=(frmprincipal.ExcelWorksheet1.ChartObjects(EmptyParam, lcid) as chartObjects).add(100,200,300,300);
frmprincipal.ExcelChart1.ConnectTo(ChObj.Chart as ExcelChart);
frmprincipal.ExcelChart1.SetSourceData(frmprincipal.ExcelWorkSheet1.Range['A8', 'B17'],xlColumns);
frmprincipal.ExcelChart1.ChartType:=xl3DPie;
frmprincipal.ExcelChart1.ApplyDataLabels(xlDataLabelsShowPercent, False, EmptyParam, True);
mas quando as range’s são variáveis coluna A8:A17 e Coluna G8:G17, não dá certo :
XRange1 := frmprincipal.ExcelWorkSheet1.Range['A8', 'A17'].Address[1, 1, 1, 1, 1];
XRange2 := frmprincipal.ExcelWorkSheet1.Range['G8', 'G17'].Address[1, 1, 1, 1, 1];
lcid := GetUserDefaultLCID; //LOCALE_USER_DEFAULT ;
ChObj:=(frmprincipal.ExcelWorksheet1.ChartObjects(EmptyParam, lcid) as chartObjects).add(100,200,300,300);
frmprincipal.ExcelChart1.ConnectTo(ChObj.Chart as ExcelChart);
frmprincipal.ExcelChart1.SetSourceData(frmprincipal.ExcelWorkSheet1.Range[xrange1, xrange2], xlColumns);
frmprincipal.ExcelChart1.ChartType:=xl3DPie;
frmprincipal.ExcelChart1.ApplyDataLabels(xlDataLabelsShowPercent, False, EmptyParam, True);
segue abaixo ex da planuilha.
Coluna A Col B Col C Col D Col E Col F Col G
Dado1
7652
792
854
2.184,31
2. 860,34
2.890,52
Dado2
2649
2495
2243
2.249.,56
2. 529,53
2.592,67
Dado3
2187
2271
2050
5.062,57
5. 461,48
4.916,50
Obrigado desde já
Unimed Médico.
Curtidas 0