unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleServer, Excel2000, StdCtrls, ExtCtrls;
type
TForm1 =
class(TForm)
ExcelWorksheet1: TExcelWorksheet;
Button1: TButton;
ExcelApplication1: TExcelApplication;
ExcelWorkbook1: TExcelWorkbook;
Button2: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure ExcelWorkbook1BeforeClose(Sender: TObject;
var Cancel: OleVariant);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
Counter: Integer;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
// Excel Application starten und Exceldokument oeffnen
ExcelApplication1.Connect;
ExcelApplication1.Visible[GetUserDefaultLCID] := true;
ExcelApplication1.UserControl := True;
ExcelApplication1.Workbooks.Open('
C:\Mappe1.xls', False, False, EmptyParam, '
', False, False, EmptyParam, EmptyParam, false, false, EmptyParam, false, 0);
// Workbook verbinden
ExcelWorkbook1.ConnectTo(ExcelApplication1.ActiveWorkBook);
// Workbookeigenschaften einstellen
ExcelWorkbook1.Title[1] := '
Programm vom ' + datetimetostr(now);
ExcelWorkbook1.Author[1] := '
Specialwork';
ExcelWorkbook1.Comments[1] := '
Dies ist eine Demonstration des Ansprechens von EXCEL Mappen';
ExcelWorkbook1.Save;
// Woorksheet verbinden und aktivieren
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets.Item[1]
as _Worksheet);
ExcelWorksheet1.Activate;
// Counter zuruecksetzen
Counter := 0;
Timer1.Enabled := True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled := false;
ExcelApplication1.Quit;
ExcelApplication1.Disconnect;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// Randomize einschalten
randomize;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
aRange: Range;
Value: real;
begin
if counter = 0
then
begin
aRange := IDispatch(ExcelWorksheet1.Cells.Item[Counter + 1, 1])
as Range;
aRange.Value := timetostr(now);
aRange.Show;
inc(counter, 1);
end else
if counter = 1000
then
begin
aRange := IDispatch(ExcelWorksheet1.Cells.Item[Counter + 1, 1])
as Range;
aRange.Value := timetostr(now);
aRange.Show;
Button2Click(self);
exit;
end else
// Increase Counter
inc(Counter, 1);
// Get Random Value;
Value := random(9999999999999999);
Value := Value/1000000;
// Insert Random Value
aRange := IDispatch(ExcelWorksheet1.Cells.Item[Counter, 1])
as Range;
aRange.Value := Value;
aRange.Show;
end;
procedure TForm1.ExcelWorkbook1BeforeClose(Sender: TObject;
var Cancel: OleVariant);
begin
Timer1.Enabled := False;
end;
end.