-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportunit.pas
175 lines (157 loc) · 6.21 KB
/
exportunit.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
unit ExportUnit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, sqldb, db, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, Grids, ExtCtrls, Buttons, Menus, MetaUnit, ConflictsMeta, Filters, comobj;
type
T4DArray = array of array of array of array of String;
THeader = record
Name: String;
Id: Integer;
end;
TExport = class
class procedure ExportScheduleToHTML(AHeaderH, AHeaderV: String;
AHvals, AVvals: array of THeader; AScheduleTable: TTableInfo;
AScheduleItems: T4DArray; AF: TFilters; ACheckGroup: TCheckGroup;
AShowTitles: Boolean; APath: String);
class procedure ExportScheduleToExcel(AHeaderH, AHeaderV: String;
AHvals, AVvals: array of THeader; AScheduleTable: TTableInfo;
AScheduleItems: T4DArray; AF: TFilters; ACheckGroup: TCheckGroup;
AShowTitles: Boolean; APath: String);
end;
implementation
class procedure TExport.ExportScheduleToHTML(AHeaderH, AHeaderV: String;
AHvals, AVvals: array of THeader; AScheduleTable: TTableInfo;
AScheduleItems: T4DArray; AF: TFilters; ACheckGroup: TCheckGroup;
AShowTitles: Boolean; APath: String);
var
X, Y, i, j, k, l: Integer;
headerFile, fo: TextFile;
tmpStr: String;
begin
AssignFile(headerFile, 'common\header.txt');
Reset(headerFile);
AssignFile(fo, APath);
Rewrite(fo);
while not EOF(headerFile) do begin
ReadLn(headerFile, tmpStr);
WriteLn(fo, tmpStr);
end;
CloseFile(headerFile);
k := 0;
WriteLn(fo, '<fieldset><legend><strong>Активные фильтры</strong></legend><ol>');
WriteLn(fo, Format('<li><i>По горизонтали:</i> %s</li>', [AHeaderH]));
WriteLn(fo, Format('<li><i>По вертикали:</i> %s</li>', [AHeaderV]));
for i := 0 to High(AF.FilterPanels) do
with AF.FilterPanels[i] do
if FCheckBox.Checked then begin
WriteLn(fo, Format('<li> <i>%s %s</i> %s </li>', [FFieldsList.Items[FFieldsList.ItemIndex], FSignsList.Items[FSignsList.ItemIndex], FConstraint.Text]));
Inc(k);
end;
X := Length(AHvals) - 1;
Y := Length(AVvals) - 1;
WriteLn(fo, '</ol></fieldset><table border = "0" cellspacing = "0" cellpadding = "0">');
for j := 0 to Y do begin
Writeln(fo, '<tr valign = "top">');
for i := 0 to X do begin
if (i = 0) xor (j = 0) then
Write(fo, '<td class = "h">')
else
Write(fo, '<td>');
if (i = 0) and (j = 0) then begin
Writeln(fo, '</td>');
Continue;
end;
if j = 0 then begin
Writeln(fo, AHVals[i].Name + '</td>');
Continue;
end;
if i = 0 then begin
Writeln(fo, AVVals[j].Name + '</td>');
Continue;
end;
for k := 0 to High(AScheduleItems[i, j]) do begin
if ConflictsModule.IsInConflict(StrToInt(AScheduleItems[i][j][k][0])).x > -1 then
Write(fo, '<div class = "conflict">');
for l := 1 to High(AScheduleItems[i, j, k]) do begin
Write(fo, '<strong>' + AScheduleTable.FFields[l].FCaption + ':</strong> ' + AScheduleItems[i][j][k][l] + '<br />');
end;
if k <> High(AScheduleItems[i, j]) then
WriteLn(fo, '<div class = "separator"> </div>');
if ConflictsModule.IsInConflict(StrToInt(AScheduleItems[i][j][k][0])).x > -1 then
Write(fo, '</div>');
end;
WriteLn(fo, '</td>');
end;
Writeln(fo, '</tr>');
end;
WriteLn(fo, '</table></body></html>');
CloseFile(fo);
end;
class procedure TExport.ExportScheduleToExcel(AHeaderH, AHeaderV: String;
AHvals, AVvals: array of THeader; AScheduleTable: TTableInfo;
AScheduleItems: T4DArray; AF: TFilters; ACheckGroup: TCheckGroup;
AShowTitles: Boolean; APath: String);
var
ExcelApp: Variant;
i, j, X, Y, k, l: Integer;
s: String;
begin
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Application.EnableEvents := False;
ExcelApp.Workbooks.Add;
ExcelApp.Worksheets[1].Name := WideString(UTF8ToSys('Расписание'));
X := Length(AHvals) - 1;
Y := Length(AVvals) - 1;
for j := 0 to Y do begin
for i := 0 to X do begin
if (i = 0) and (j = 0) then Continue;
if (i = 0) xor (j = 0) then begin
ExcelApp.Cells[j + 1, i + 1].Font.Bold := True;
ExcelApp.Cells[j + 1, i + 1].HorizontalAlignment := 3;
end;
ExcelApp.Cells[j + 1, i + 1].VerticalAlignment := 1;
ExcelApp.Cells[j + 1, i + 1].ColumnWidth := 30;
ExcelApp.Cells[j + 1, i + 1].WrapText := True;
ExcelApp.Cells[j + 1, i + 1].Borders.LineStyle := 1;
if j = 0 then begin
ExcelApp.Cells[j + 1, i + 1] := WideString(UTF8ToSys(AHVals[i].Name));
Continue;
end;
if i = 0 then begin
ExcelApp.Cells[j + 1, i + 1] := WideString(UTF8ToSys(AVVals[j].Name));
Continue;
end;
s := '';
for k := 0 to High(AScheduleItems[i, j]) do begin
for l := 1 to High(AScheduleItems[i, j, k]) do begin
if not ACheckGroup.Checked[l] then Continue;
if AShowTitles then
s += Format('%s: %s' + PChar(#10), [AScheduleTable.FFields[l].FCaption, AScheduleItems[i][j][k][l]])
else
s += Format('%s' + PChar(#10), [AScheduleItems[i][j][k][l]]);
end;
s += '-----------------------------------------' + PChar(#10);
end;
ExcelApp.Cells[j + 1, i + 1] := WideString(UTF8ToSys(s));
end;
end;
ExcelApp.Cells[Y + 3, 1].Font.Bold := True;
ExcelApp.Cells[Y + 3, 1].WrapText := True;
ExcelApp.Cells[Y + 3, 1].HorizontalAlignment := 3;
ExcelApp.Cells[Y + 3, 1] := WideString(UTF8ToSys('Активные фильтры'));
ExcelApp.Cells[Y + 4, 1] := WideString(UTF8ToSys(Format('1. По горизонтали: %s', [AHeaderH])));
ExcelApp.Cells[Y + 5, 1] := WideString(UTF8ToSys(Format('2. По вертикали: %s', [AHeaderV])));
k := 3;
for i := 0 to High(AF.FilterPanels) do
with AF.FilterPanels[i] do
if FCheckBox.Checked then begin
ExcelApp.Cells[Y + 6 + i, 1] := WideString(UTF8ToSys(Format('%d. %s %s %s', [k, FFieldsList.Items[FFieldsList.ItemIndex], FSignsList.Items[FSignsList.ItemIndex], FConstraint.Text])));
Inc(k);
end;
ExcelApp.DisplayAlerts := False;
ExcelApp.Worksheets[1].SaveAs(WideString(UTF8ToSys(APath)));
ExcelApp.Application.Quit;
end;
end.