2017-09-16 16:34:45 +09:00
|
|
|
// numberformat.cpp
|
|
|
|
|
2019-01-02 20:56:00 +09:00
|
|
|
#include <QtGlobal>
|
2017-09-16 12:21:23 +09:00
|
|
|
#include <QtGui>
|
2019-01-02 20:56:00 +09:00
|
|
|
|
2017-09-16 12:21:23 +09:00
|
|
|
#include "xlsxdocument.h"
|
|
|
|
#include "xlsxformat.h"
|
|
|
|
|
2017-10-10 16:46:08 +09:00
|
|
|
using namespace QXlsx;
|
|
|
|
|
2017-09-16 16:34:45 +09:00
|
|
|
int numberformat()
|
2017-09-16 12:21:23 +09:00
|
|
|
{
|
2017-10-10 16:46:08 +09:00
|
|
|
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);
|
|
|
|
}
|
2017-09-16 12:21:23 +09:00
|
|
|
|
2017-09-23 11:12:59 +09:00
|
|
|
xlsx.saveAs("numberformat.xlsx");
|
|
|
|
|
2017-10-10 16:46:08 +09:00
|
|
|
return 0;
|
2017-09-16 12:21:23 +09:00
|
|
|
}
|