Make use of clang-format
Change-Id: I71bbf133223931eddb0c7e568cc0b99ecf807fa1
This commit is contained in:
+49
-44
@@ -6,53 +6,58 @@
|
||||
|
||||
QTXLSX_USE_NAMESPACE
|
||||
|
||||
void writeHorizontalAlignCell(Document &xlsx, const QString &cell, const QString &text, Format::HorizontalAlignment align)
|
||||
void writeHorizontalAlignCell(Document &xlsx, const QString &cell, const QString &text,
|
||||
Format::HorizontalAlignment align)
|
||||
{
|
||||
Format format;
|
||||
format.setHorizontalAlignment(align);
|
||||
format.setBorderStyle(Format::BorderThin);
|
||||
xlsx.write(cell, text, format);
|
||||
Format format;
|
||||
format.setHorizontalAlignment(align);
|
||||
format.setBorderStyle(Format::BorderThin);
|
||||
xlsx.write(cell, text, format);
|
||||
}
|
||||
|
||||
void writeVerticalAlignCell(Document &xlsx, const QString &range, const QString &text, Format::VerticalAlignment align)
|
||||
void writeVerticalAlignCell(Document &xlsx, const QString &range, const QString &text,
|
||||
Format::VerticalAlignment align)
|
||||
{
|
||||
Format format;
|
||||
format.setVerticalAlignment(align);
|
||||
format.setBorderStyle(Format::BorderThin);
|
||||
CellRange r(range);
|
||||
xlsx.write(r.firstRow(), r.firstColumn(), text);
|
||||
xlsx.mergeCells(r, format);
|
||||
Format format;
|
||||
format.setVerticalAlignment(align);
|
||||
format.setBorderStyle(Format::BorderThin);
|
||||
CellRange r(range);
|
||||
xlsx.write(r.firstRow(), r.firstColumn(), text);
|
||||
xlsx.mergeCells(r, format);
|
||||
}
|
||||
|
||||
void writeBorderStyleCell(Document &xlsx, const QString &cell, const QString &text, Format::BorderStyle bs)
|
||||
void writeBorderStyleCell(Document &xlsx, const QString &cell, const QString &text,
|
||||
Format::BorderStyle bs)
|
||||
{
|
||||
Format format;
|
||||
format.setBorderStyle(bs);
|
||||
xlsx.write(cell, text, format);
|
||||
Format format;
|
||||
format.setBorderStyle(bs);
|
||||
xlsx.write(cell, text, format);
|
||||
}
|
||||
|
||||
void writeSolidFillCell(Document &xlsx, const QString &cell, const QColor &color)
|
||||
{
|
||||
Format format;
|
||||
format.setPatternBackgroundColor(color);
|
||||
xlsx.write(cell, QVariant(), format);
|
||||
Format format;
|
||||
format.setPatternBackgroundColor(color);
|
||||
xlsx.write(cell, QVariant(), format);
|
||||
}
|
||||
|
||||
void writePatternFillCell(Document &xlsx, const QString &cell, Format::FillPattern pattern, const QColor &color)
|
||||
void writePatternFillCell(Document &xlsx, const QString &cell, Format::FillPattern pattern,
|
||||
const QColor &color)
|
||||
{
|
||||
Format format;
|
||||
format.setPatternForegroundColor(color);
|
||||
format.setFillPattern(pattern);
|
||||
xlsx.write(cell, QVariant(), format);
|
||||
Format format;
|
||||
format.setPatternForegroundColor(color);
|
||||
format.setFillPattern(pattern);
|
||||
xlsx.write(cell, QVariant(), format);
|
||||
}
|
||||
|
||||
void writeBorderAndFontColorCell(Document &xlsx, const QString &cell, const QString &text, const QColor &color)
|
||||
void writeBorderAndFontColorCell(Document &xlsx, const QString &cell, const QString &text,
|
||||
const QColor &color)
|
||||
{
|
||||
Format format;
|
||||
format.setBorderStyle(Format::BorderThin);
|
||||
format.setBorderColor(color);
|
||||
format.setFontColor(color);
|
||||
xlsx.write(cell, text, format);
|
||||
Format format;
|
||||
format.setBorderStyle(Format::BorderThin);
|
||||
format.setBorderColor(color);
|
||||
format.setFontColor(color);
|
||||
xlsx.write(cell, text, format);
|
||||
}
|
||||
|
||||
void writeFontNameCell(Document &xlsx, const QString &cell, const QString &text)
|
||||
@@ -93,13 +98,13 @@ int main()
|
||||
Document xlsx;
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//Create the first sheet (Otherwise, default "Sheet1" will be created)
|
||||
// Create the first sheet (Otherwise, default "Sheet1" will be created)
|
||||
xlsx.addSheet("Aligns & Borders");
|
||||
xlsx.setColumnWidth(2, 20); //Column B
|
||||
xlsx.setColumnWidth(8, 12); //Column H
|
||||
xlsx.setColumnWidth(2, 20); // Column B
|
||||
xlsx.setColumnWidth(8, 12); // Column H
|
||||
xlsx.currentWorksheet()->setGridLinesVisible(false);
|
||||
|
||||
//Alignment
|
||||
// Alignment
|
||||
writeHorizontalAlignCell(xlsx, "B3", "AlignLeft", Format::AlignLeft);
|
||||
writeHorizontalAlignCell(xlsx, "B5", "AlignHCenter", Format::AlignHCenter);
|
||||
writeHorizontalAlignCell(xlsx, "B7", "AlignRight", Format::AlignRight);
|
||||
@@ -107,7 +112,7 @@ int main()
|
||||
writeVerticalAlignCell(xlsx, "F3:F7", "AlignVCenter", Format::AlignVCenter);
|
||||
writeVerticalAlignCell(xlsx, "H3:H7", "AlignBottom", Format::AlignBottom);
|
||||
|
||||
//Border
|
||||
// Border
|
||||
writeBorderStyleCell(xlsx, "B13", "BorderMedium", Format::BorderMedium);
|
||||
writeBorderStyleCell(xlsx, "B15", "BorderDashed", Format::BorderDashed);
|
||||
writeBorderStyleCell(xlsx, "B17", "BorderDotted", Format::BorderDotted);
|
||||
@@ -115,7 +120,7 @@ int main()
|
||||
writeBorderStyleCell(xlsx, "B21", "BorderDouble", Format::BorderDouble);
|
||||
writeBorderStyleCell(xlsx, "B23", "BorderDashDot", Format::BorderDashDot);
|
||||
|
||||
//Fill
|
||||
// Fill
|
||||
writeSolidFillCell(xlsx, "D13", Qt::red);
|
||||
writeSolidFillCell(xlsx, "D15", Qt::blue);
|
||||
writeSolidFillCell(xlsx, "D17", Qt::yellow);
|
||||
@@ -137,7 +142,7 @@ int main()
|
||||
writeBorderAndFontColorCell(xlsx, "H23", "Qt::gray", Qt::gray);
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//Create the second sheet.
|
||||
// Create the second sheet.
|
||||
xlsx.addSheet("Fonts");
|
||||
|
||||
xlsx.write("B3", "Normal");
|
||||
@@ -177,7 +182,7 @@ int main()
|
||||
xlsx.mergeCells("J3:J9");
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//Create the third sheet.
|
||||
// Create the third sheet.
|
||||
xlsx.addSheet("Formulas");
|
||||
xlsx.setColumnWidth(1, 2, 40);
|
||||
Format rAlign;
|
||||
@@ -240,7 +245,7 @@ int main()
|
||||
xlsx.write("B33", "=HYPERLINK(\"http://qt-project.org\")", lAlign);
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//Create the fourth sheet.
|
||||
// Create the fourth sheet.
|
||||
xlsx.addSheet("NumFormats");
|
||||
xlsx.setColumnWidth(2, 40);
|
||||
writeInternalNumFormatsCell(xlsx, 4, 2.5681, 2);
|
||||
@@ -258,7 +263,7 @@ int main()
|
||||
writeCustomNumFormatsCell(xlsx, 16, 60, "[Red][<=100];[Green][>100]");
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//Create the fifth sheet.
|
||||
// Create the fifth sheet.
|
||||
xlsx.addSheet("Merging");
|
||||
Format centerAlign;
|
||||
centerAlign.setHorizontalAlignment(Format::AlignHCenter);
|
||||
@@ -271,11 +276,11 @@ int main()
|
||||
xlsx.mergeCells("E8:F21", centerAlign);
|
||||
|
||||
//---------------------------------------------------------------
|
||||
//Create the fifth sheet.
|
||||
// Create the fifth sheet.
|
||||
xlsx.addSheet("Grouping");
|
||||
qsrand(QDateTime::currentMSecsSinceEpoch());
|
||||
for (int row=2; row<31; ++row) {
|
||||
for (int col=1; col<=10; ++col)
|
||||
for (int row = 2; row < 31; ++row) {
|
||||
for (int col = 1; col <= 10; ++col)
|
||||
xlsx.write(row, col, qrand() % 100);
|
||||
}
|
||||
xlsx.groupRows(4, 7);
|
||||
@@ -288,7 +293,7 @@ int main()
|
||||
|
||||
xlsx.saveAs("Book1.xlsx");
|
||||
|
||||
//Make sure that read/write works well.
|
||||
// Make sure that read/write works well.
|
||||
Document xlsx2("Book1.xlsx");
|
||||
xlsx2.saveAs("Book2.xlsx");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user