unit TestSpäteBindung;
interface
uses Variants, ComObj,Excel2010,Dialogs,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms;
procedure ExcelFuellen;
implementation
procedure ExcelFuellen;
var
Excel : Variant;
row, column,I: Integer;
WBk, WS, SheetName: OleVariant;
Diagramm1: OleVariant;
serie : OleVariant;
begin
try
Excel := GetActiveOleObject('
Excel.Application');
except
Excel := CreateOleObject('
Excel.Application');
end;
excel.Application.SheetsInNewWorkBook := 8;
//Die 8 is die Anzahl der Sheets
Excel.Workbooks.Add;
Excel.Sheets[1].
Name := '
DP Sheet';
//Hierbei ist 1 das erste Sheet 2 das zweite usw.
//von nun an können wir unser Sheet auch über den gegebenen Namen ansprechen! zB:
Excel.Sheets['
DP Sheet'];
row := 1;
column := 2;
Excel.Sheets['
DP Sheet'].Cells[row,column].Value := '
Hallo';
Excel.Sheets['
DP Sheet'].Cells[1,3].value := 5.23;
//Da Value vom Typ Variant is können wir hier fast alles reinschreiben
for I := 1
to 20
do begin
Excel.Sheets['
DP Sheet'].Cells[I,3].value := I;
end;
for I := 1
to 20
do begin
Excel.Sheets['
DP Sheet'].Cells[I,4].value := I+30;
end;
for I := 1
to 20
do begin
Excel.Sheets['
DP Sheet'].Cells[I,5].value := I+50;
end;
for I := 1
to 20
do begin
Excel.Sheets['
DP Sheet'].Cells[I,6].value := I+80;
end;
Excel.Range['
A1:B4'].Select;
//Den Bereich A1 bis B4 makieren
Excel.Selection.Font.Bold := true;
//und im Makierten Bereich die Schriftdicke ändern
Excel.Cells[row,column].select;
Excel.ActiveCell.FormulaR1C1 := '
=R2C1+R3C1';
// Rechnet A2 + A3
//Excel.Sheets['DP Sheet'].Range['A5', 'A5'].Value := 'The meaning of life, the universe, and everything, is';
//Excel.Sheets['DP Sheet'].Range['B5', 'B5'].Value := 42;
Excel.Charts.Add;
Excel.ActiveChart.ChartType:= xlColumnClustered;
Excel.ActiveChart.Location (Where:= xlLocationAsObject,
Name:= '
DP Sheet');
Excel.ActiveChart.HasTitle := True;
Excel.ActiveChart.ChartTitle.Characters.Text := '
Reisezeiten';
Excel.ActiveChart.Axes(xlCategory, xlPrimary).HasTitle := True;
Excel.ActiveChart.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text := '
Uhrzeit';
Excel.ActiveChart.Axes(xlValue, xlPrimary).HasTitle := True;
Excel.ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text := '
Dauer in sec';
serie := Excel.ActiveChart.SeriesCollection.NewSeries;
//serie.XValues := '=''Sued_Ost''!Z3S10:Z3'+'S10';
//serie.Values := '=''Sued_Ost''!Z4S10:Z4'+'S10';
serie.XValues := '
=''
Sued_Ost''
!C3:C10';
serie.Values := '
=''
Sued_Ost''
!D3:D10';
Excel.Visible := true;
Excel := unassigned;
end;
end.