-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.hpp
193 lines (181 loc) · 7.81 KB
/
export.hpp
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#pragma once
static char *tmplFile[112] =
{
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\r\n",
"<?mso-application progid=\"Excel.Sheet\"?>\r\n",
"<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n",
" xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\n",
" xmlns:x=\"urn:schemas-microsoft-com:office:excel\"\r\n",
" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\"\r\n",
" xmlns:html=\"http://www.w3.org/TR/REC-html40\">\r\n",
" <DocumentProperties xmlns=\"urn:schemas-microsoft-com:office:office\">\r\n",
" <LastAuthor>UURClone 1.2</LastAuthor>\r\n",
" <Created>2000-00-00T12:00:00Z</Created>\r\n",
" <Version>11.6360</Version>\r\n",
" </DocumentProperties>\r\n",
" <ExcelWorkbook xmlns=\"urn:schemas-microsoft-com:office:excel\">\r\n",
" <WindowHeight>12015</WindowHeight>\r\n",
" <WindowWidth>21675</WindowWidth>\r\n",
" <WindowTopX>360</WindowTopX>\r\n",
" <WindowTopY>300</WindowTopY>\r\n",
" <ProtectStructure>False</ProtectStructure>\r\n",
" <ProtectWindows>False</ProtectWindows>\r\n",
" </ExcelWorkbook>\r\n",
" <Styles>\r\n",
" <Style ss:ID=\"Default\" ss:Name=\"Normal\">\r\n",
" <Alignment ss:Vertical=\"Bottom\"/>\r\n",
" <Borders/>\r\n",
" <Font/>\r\n",
" <Interior/>\r\n",
" <NumberFormat/>\r\n",
" <Protection/>\r\n",
" </Style>\r\n",
" <Style ss:ID=\"s21\">\r\n",
" <Borders>\r\n",
" <Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" <Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" <Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" <Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" </Borders>\r\n",
" <Font x:Family=\"Swiss\" ss:Bold=\"1\"/>\r\n",
" <Interior ss:Color=\"#FFCC00\" ss:Pattern=\"Solid\"/>\r\n",
" </Style>\r\n",
" <Style ss:ID=\"s22\">\r\n",
" <Borders>\r\n",
" <Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" <Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" <Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" <Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" </Borders>\r\n",
" <NumberFormat ss:Format=\"Short Date\"/>\r\n",
" </Style>\r\n",
" <Style ss:ID=\"s23\">\r\n",
" <Borders>\r\n",
" <Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" <Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" <Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" <Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" </Borders>\r\n",
" <NumberFormat ss:Format=\"Short Time\"/>\r\n",
" </Style>\r\n",
" <Style ss:ID=\"s24\">\r\n",
" <Borders>\r\n",
" <Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" <Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" <Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" <Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\r\n",
" </Borders>\r\n",
" </Style>\r\n",
" </Styles>\r\n",
" <Worksheet ss:Name=\"uur2\">\r\n",
" <Names>\r\n",
" <NamedRange ss:Name=\"_FilterDatabase\" ss:RefersTo=\"=uur2!R1C1:R5000C5\"\r\n",
" ss:Hidden=\"1\"/>\r\n",
" </Names>\r\n",
" <Table ss:ExpandedColumnCount=\"5\" ss:ExpandedRowCount=\"5000\" x:FullColumns=\"1\"\r\n",
" x:FullRows=\"1\">\r\n",
" <Column ss:AutoFitWidth=\"0\" ss:Width=\"75\"/>\r\n",
" <Column ss:AutoFitWidth=\"0\" ss:Width=\"60\" ss:Span=\"1\"/>\r\n",
" <Column ss:Index=\"4\" ss:AutoFitWidth=\"0\" ss:Width=\"150\"/>\r\n",
" <Column ss:AutoFitWidth=\"0\" ss:Width=\"60\"/>\r\n",
" <Row>\r\n",
" <Cell ss:StyleID=\"s21\"><Data ss:Type=\"String\">Date</Data><NamedCell\r\n",
" ss:Name=\"_FilterDatabase\"/></Cell>\r\n",
" <Cell ss:StyleID=\"s21\"><Data ss:Type=\"String\">Time</Data><NamedCell\r\n",
" ss:Name=\"_FilterDatabase\"/></Cell>\r\n",
" <Cell ss:StyleID=\"s21\"><Data ss:Type=\"String\">Activity</Data><NamedCell\r\n",
" ss:Name=\"_FilterDatabase\"/></Cell>\r\n",
" <Cell ss:StyleID=\"s21\"><Data ss:Type=\"String\">Comment</Data><NamedCell\r\n",
" ss:Name=\"_FilterDatabase\"/></Cell>\r\n",
" <Cell ss:StyleID=\"s21\"><Data ss:Type=\"String\">Duration</Data><NamedCell\r\n",
" ss:Name=\"_FilterDatabase\"/></Cell>\r\n",
" </Row>\r\n",
" </Table>\r\n",
" <WorksheetOptions xmlns=\"urn:schemas-microsoft-com:office:excel\">\r\n",
" <Print>\r\n",
" <ValidPrinterInfo/>\r\n",
" <PaperSizeIndex>9</PaperSizeIndex>\r\n",
" <HorizontalResolution>600</HorizontalResolution>\r\n",
" <VerticalResolution>600</VerticalResolution>\r\n",
" </Print>\r\n",
" <Selected/>\r\n",
" <Panes>\r\n",
" <Pane>\r\n",
" <Number>3</Number>\r\n",
" <ActiveRow>1</ActiveRow>\r\n",
" </Pane>\r\n",
" </Panes>\r\n",
" <ProtectObjects>False</ProtectObjects>\r\n",
" <ProtectScenarios>False</ProtectScenarios>\r\n",
" </WorksheetOptions>\r\n",
" <AutoFilter x:Range=\"R1C1:R27C5\"\r\n",
" xmlns=\"urn:schemas-microsoft-com:office:excel\">\r\n",
" </AutoFilter>\r\n",
" </Worksheet>\r\n",
"</Workbook>\r\n"
};
struct ExcelExport
{
static void Write(HANDLE file, char *str)
{
DWORD written;
::WriteFile(file, str, (DWORD) strlen(str), &written, 0);
}
static char * getToken(char* &ptr, char *EOF)
{
char *start = ptr;
for (;*ptr!='\t' && *ptr!='\n' && ptr<EOF; ptr++) if (*ptr=='\r') *ptr=0;
if (ptr == EOF) return 0;
*ptr++ = 0;
return start;
}
static void Export(LPCSTR fname, LPCSTR log)
{
File f;
if (!f.Read(log)) return;
if (f.GetFileSize() == 0) return;
char *logfile = f;
char *EOF = (char*)f + f.GetFileSize();
HANDLE file = ::CreateFile(fname, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0,0);
if (INVALID_HANDLE_VALUE != file)
{
for (int i=0; i<89; i++)
Write(file, tmplFile[i]);
char *tok = 0;
while (true) {
Write(file, " <Row>\r\n");
Write(file, " <Cell ss:StyleID=\"s22\"><Data ss:Type=\"DateTime\">");
if (!(tok = getToken(logfile, EOF))) break;
Write(file, tok);
Write(file, "T00:00:00.000</Data><NamedCell\r\n");
Write(file, " ss:Name=\"_FilterDatabase\"/></Cell>\r\n");
Write(file, " <Cell ss:StyleID=\"s23\"><Data ss:Type=\"DateTime\">1899-12-31T");
if (!(tok = getToken(logfile, EOF))) break;
Write(file, tok);
Write(file, ":00.000</Data><NamedCell\r\n");
Write(file, " ss:Name=\"_FilterDatabase\"/></Cell>\r\n");
Write(file, " <Cell ss:StyleID=\"s24\"><Data ss:Type=\"String\">");
if (!(tok = getToken(logfile, EOF))) break;
Write(file, tok);
Write(file, "</Data><NamedCell\r\n");
Write(file, " ss:Name=\"_FilterDatabase\"/></Cell>\r\n");
Write(file, " <Cell ss:StyleID=\"s24\"><Data ss:Type=\"String\">");
if (!(tok = getToken(logfile, EOF))) break;
Write(file, tok);
Write(file, "</Data><NamedCell\r\n");
Write(file, " ss:Name=\"_FilterDatabase\"/></Cell>\r\n");
Write(file, " <Cell ss:StyleID=\"s24\"><Data ss:Type=\"Number\">");
if (!(tok = getToken(logfile, EOF))) break;
for (int i=0; i<strlen(tok); i++) if (tok[i]==',') tok[i] = '.';
Write(file, tok);
Write(file, "</Data><NamedCell\r\n");
Write(file, " ss:Name=\"_FilterDatabase\"/></Cell>\r\n");
Write(file, " </Row>\r\n");
if (logfile == EOF) break;
}
for (int i=89; i<112; i++)
Write(file, tmplFile[i]);
::CloseHandle(file);
}
}
};