-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExportData.pas
91 lines (76 loc) · 1.8 KB
/
ExportData.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
unit ExportData;
interface
uses Oracle, OracleData, Classes, ComObj;
type TExport = class
private
fFullPath: string;
fDataSet: TOracleDataSet;
function CorrectData: Boolean;
public
constructor Create(aFullPath: String; aOraSataSet: TOracleDataSet); overload;
property FullPath: string read fFullPath write fFullPath;
property OraDataSet: TOracleDataSet read fDataSet write fDataSet;
function ExportOraToCSV: Boolean;
function ExportOraToXLS(aShowTitle: Boolean): Boolean;
//function ExportOraToXLSX: Boolean;
end;
implementation
constructor TExport.Create(aFullPath: String; aOraSataSet: TOracleDataSet);
begin
fFullPath := aFullPath;
fDataSet := aOraSataSet;
end;
function TExport.CorrectData: Boolean;
begin
//
end;
function TExport.ExportOraToCSV: Boolean;
var
f: TextFile;
i: Integer;
begin
try
AssignFile(f, fFullPath);
//Rewrite(f);
Reset(f);
fDataSet.First;
while not fDataSet.Eof do
begin
for i := 0 to fDataSet.FieldCount - 1 do
begin
Writeln(f, fDataSet.Fields.FieldByNumber(i).Value + ';');
end;
fDataSet.Next;
end;
finally
CloseFile(f);
end;
end;
function TExport.ExportOraToXLS(aShowTitle: Boolean): Boolean;
var
x: Variant;
i, j: Integer;
begin
x := CreateOleObject('Excel.Application');
x.Workbooks.Add;
j := 1;
if aShowTitle then
begin
for i := 0 to fDataSet.FieldCount - 1 do
x.ActiveWorkBook.WorkSheets[1].Cells[j, i + 1] :=
fDataSet.Fields.Fields[i].DisplayLabel;
j := 2;
end;
while not fDataSet.Eof do
begin
for i := 0 to fDataSet.FieldCount - 1 do
begin
x.ActiveWorkBook.WorkSheets[1].Cells[j, i + 1] :=
fDataSet.Fields.Fields[i].AsString;
end;
fDataSet.Next;
inc(j);
end;
x.Visible := true;
end;
end.