unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, Grids, ExtDlgs,comobj;
type
{ TForm1 }
TForm1 = class(TForm)
btnDate: TButton;
Button1: TButton;
Button2: TButton;
CalendarDialog1: TCalendarDialog;
lbledtPath: TLabeledEdit;
lbledtName: TLabeledEdit;
lbledtAddress: TLabeledEdit;
lbledtphonenumber: TLabeledEdit;
lbledtmoneyowing: TLabeledEdit;
lbledtDate: TLabeledEdit;
StringGrid1: TStringGrid;
procedure btnDateClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
type
TData = record
Name,Address,PhoneNumber : String;
MoneyOwing : integer;
Interest,rate : real;
end;
var
Data : TData;
count,datediff,count1,count2 : integer;
Added : tdatetime;
numdays : double;
{$R *.lfm}
{ TForm1 }
procedure TForm1.btnDateClick(Sender: TObject);
begin
if calendardialog1.execute then
lbledtDate.text := datetostr(calendardialog1.date);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
data.name := lbledtname.text;
data.address := lbledtaddress.text;
data.phonenumber := lbledtphonenumber.text;
data.moneyowing := strtoint(lbledtmoneyowing.text);
added := strtodate(lbledtdate.text);
stringgrid1.cells [0,count] := data.name;
stringgrid1.cells [1,count] := data.address;
stringgrid1.cells [2,count] := data.phonenumber;
stringgrid1.cells [3,count] := inttostr(data.moneyowing);
stringgrid1.cells [5,count] := datetostr(added);
numdays := date - added;
datediff := trunc(numdays);
data.rate := 1.0025;
for count1 := 1 to datediff -1 do
data.rate := data.rate * 1.0025;
data.interest := (data.moneyowing * data.rate) - data.moneyowing;
stringgrid1.cells [4,count] := floattostr(data.interest);
inc(count);
stringgrid1.rowCount := count + 1;
end;
procedure TForm1.Button2Click(Sender: TObject);
Var XLApp: OLEVariant;
x,y: byte;
path: variant;
begin
XLApp := CreateOleObject('Excel.Application'); // comobj
try
XLApp.Visible := False; // Hide Excel
XLApp.DisplayAlerts := False;
path := lbledtPath.Text;
XLApp.Workbooks.Open(Path); // Open the Workbook
for x := 1 to count do
begin
for y := 0 to 5 do
begin
XLApp.Cells[x,y].Value := stringgrid1.Cells[y,x];
end;
end;
finally
XLApp.Quit;
XLAPP := Unassigned;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
count := 1;
stringgrid1.rowcount := 2;
end;
end.