Cita:
Empezado por elorza
Kaixo, he creado un gráfico con Chart apartir de uja StringGrid y sabes cómo puedo exportar ahora a excel? me sería de gran ayuda.
Eskerrik asko
|
yo lo hago añadiendo un componente llamado ExcelApplication de la paleta server y con el siguiente código:
Código Delphi
[-]
procedure TForm1.ExportaraexcelClick(Sender: TObject);
var
Libro : _WORKBOOK;
Hoja : _WORKSHEET;
i,colora:Integer;
begin
i:=0;
colora:=1;
Libro := Excel.Workbooks.Add(Null, 0);
Hoja := Libro.Sheets[1] as _WORKSHEET;
i:=i+1;
if colora=1 then
begin
Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.Color :=$00F1E6DC ;
colora:= colora +1;
end
else
begin
Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.ColorIndex :=2 ;
colora:= colora -1;
end;
Hoja.Cells.Item[i,1]:='Totales';
Hoja.Cells.Item[i,2]:='Actividades Realizadas';
with table do
begin
first;
while not EOF Do
begin
i:=i+1;
Hoja.Cells.Item[i,1]:=DBGrid1.Fields[0].AsString;
Hoja.Cells.Item[i,2]:=DBGrid1.Fields[1].AsString;
if colora=1 then
begin
Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.Color :=$00F1E6DC ;
colora:= colora +1;
end
else
begin
Hoja.Range['A'+ inttostr(i),'B'+ inttostr(i)].Interior.ColorIndex :=2 ;
colora:= colora -1;
end;
Next;
end;end;
i:=i+1;
Hoja.Cells.Item[i,1]:= 'Total ';
Excel.Visible[0] := true;
ShowMessage('Exportado con Exito!');
end;