unit ExcStat;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, VisiButton, Grids, DBGrids, VisiDbGrid,
DB, vddDataSource,
vddDataSet, vddReferenceDataSet, vddCustomQuery, vddQuery, l_treiberinit,
comctrls, DBClient, ComObj, OleServer, ExcelXP, VisiOpenDialog, Menus, u_ExportEXCEL;
type
TForm1 =
class(TForm)
VddQuery1: TVddQuery;
VddDataSource1: TVddDataSource;
VisiDbGrid1: TVisiDbGrid;
VisiButton1: TVisiButton;
ExcelApplication1: TExcelApplication;
ExcelWorksheet1: TExcelWorksheet;
ExcelWorkbook1: TExcelWorkbook;
SaveDialog1: TSaveDialog;
PopupMenu1: TPopupMenu;
ExportierenExcel1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure VisiButton1Click(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure ExportierenExcel1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ExportierenExcel1Click(Sender: TObject);
var
xf: TXLSExport;
iCol, iRow: integer;
Fields : TstringList;
TempVal :
String;
begin
VddQuery1.First;
if not SaveDialog1.Execute
then Exit;
if FileExists(Savedialog1.Filename)
then
DeleteFile(SaveDialog1.Filename);
xf := TXLSExport.Create(savedialog1.filename);
Fields := TStringList.Create;
VddQuery1.GetFieldNames(Fields);
for iRow := 0
to VddQuery1.RecordCount - 1
do
begin
for iCol := 0
to Fields.Count - 1
do
begin
TempVal := VddQuery1.FieldByName(Fields[iCol]).AsString;
xf.
Write(iCol, iRow, TempVal);
end;
VddQuery1.Next;
end;
xf.Free;
Fields.Free;
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
//ExcelApplication1.Quit;
//ExcelApplication1.Disconnect;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Treibermodule.LogInDialog.Execute;
end;
procedure TForm1.VisiButton1Click(Sender: TObject);
var SQL :
String;
begin
VddQuery1.Close;
VddQuery1.SQL.Clear;
SQL := '
delete from K_staadr; insert into K_staadr(adrNr) select adrNr from adress where adress.adrgr = '+quotedStr('
K')+'
;';
SQL :=
SQL + '
update K_STAADR set k_staadr.vk_vj=staadr.vk,k_staadr.roh_vj=staadr.roh from K_staadr inner join staadr on k_staadr.adrnr = staadr.adrnr where staadr.jahr=2007 and staadr.monat=13;';
SQL :=
SQL + '
update K_STAADR set k_staadr.vk_lj=staadr.vk,k_staadr.roh_lj=staadr.roh from K_staadr inner join staadr on k_staadr.adrnr = staadr.adrnr where staadr.jahr=2008 and staadr.monat=13;';
SQL :=
SQL + '
select adress.adrnr,adress.adrgr,adress.name1,adress.name2, adress.plz, adress.ort, adress.strasse, K_staadr.vk_vj,K_staadr.roh_vj,K_staadr.vk_lj, K_staadr.roh_lj from adress left outer join K_staadr on adress.adrnr = K_staadr.adrnr';
VddQuery1.SQL.Add(
SQL);
VddQuery1.Open;
end;
end.