-
Notifications
You must be signed in to change notification settings - Fork 4
/
excelexport.cpp
63 lines (56 loc) · 1.62 KB
/
excelexport.cpp
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
/***************************************************/
/* Magic Light Assistant */
/* Copyright (c) 2017-2021 by bytecho.net */
/* Written by Henry */
/* Function: */
/* Communication, activity, management and approval*/
/***************************************************/
#include "excelexport.h"
ExcelExport::ExcelExport()
{
}
ExcelExport::~ExcelExport()
{
}
bool ExcelExport::WriteExcel(const QString &filepath, QStack<QSqlRecord>& dataStack)
{
if (filepath.isEmpty())
return false;
QFile csvfile(filepath);
csvfile.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream out(&csvfile);
QStringList headData;
headData << "考勤编号"
<< "用户账号"
<< "签到时间"
<< "签退时间"
<< "考勤日期"
<< "是否补签"
<< "签到来源";
curDateTime = QDateTime::currentDateTime();
//写入表头
int headcnt = 0;
foreach(auto headTitle, headData)
{
if (++headcnt < headData.count())
out << headTitle << ",";
else
out << headTitle << "\n";
}
//写入考勤数据
while(!dataStack.isEmpty())
{
QSqlRecord lineData = dataStack.pop();
for(int cnt = 0; cnt < lineData.count(); cnt++)
{
QString data = lineData.value(cnt).toString();
if (cnt + 1 < lineData.count())
out << data << ",";
else
out << data << "\n";
}
}
csvfile.flush();
csvfile.close();
return true;
}