forked from QtExcel/QXlsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumberformat.cpp
60 lines (51 loc) · 1.22 KB
/
numberformat.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
// numberformat.cpp
#include <QtGlobal>
#include <QtGui>
#include "xlsxdocument.h"
#include "xlsxformat.h"
using namespace QXlsx;
int numberformat()
{
QXlsx::Document xlsx;
xlsx.setColumnWidth(1, 4, 20.0);
QXlsx::Format header;
header.setFontBold(true);
header.setFontSize(20);
//Custom number formats
QStringList numFormats;
numFormats
<< "Qt #"
<< "yyyy-mmm-dd"
<< "$ #,##0.00"
<< "[red]0.00";
xlsx.write(1, 1, "Raw data", header);
xlsx.write(1, 2, "Format", header);
xlsx.write(1, 3, "Shown value", header);
for (int i=0; i<numFormats.size(); ++i)
{
int row = i+2;
xlsx.write(row, 1, 100.0);
xlsx.write(row, 2, numFormats[i]);
QXlsx::Format format;
format.setNumberFormat(numFormats[i]);
xlsx.write(row, 3, 100.0, format);
}
//Builtin number formats
xlsx.addSheet();
xlsx.setColumnWidth(1, 4, 20.0);
xlsx.write(1, 1, "Raw data", header);
xlsx.write(1, 2, "Builtin Format", header);
xlsx.write(1, 3, "Shown value", header);
for (int i=0; i<50; ++i)
{
int row = i+2;
int numFmt = i;
xlsx.write(row, 1, 100.0);
xlsx.write(row, 2, numFmt);
QXlsx::Format format;
format.setNumberFormatIndex(numFmt);
xlsx.write(row, 3, 100.0, format);
}
xlsx.saveAs("numberformat.xlsx");
return 0;
}