int main() { QXlsx::Document xlsx; xlsx.write(0, 2, "Row:0, Col:2 ==> (C1)"); //Set the height of the first row to 50.0(points) xlsx.setRow(0, 50.0); //Set the width of the third column to 40.0(chars) xlsx.setColumn(2, 3, 40.0); //Set style for the row 11th. QXlsx::Format *format1 = xlsx.createFormat(); format1->setFontBold(true); format1->setFontColor(QColor(Qt::blue)); format1->setFontSize(20); xlsx.write(10, 0, "Hello Row Style"); xlsx.write(10, 5, "Blue Color"); xlsx.setRow(10, 40, format1); //Set style for the col [9th, 16th) QXlsx::Format *format2 = xlsx.createFormat(); format2->setFontBold(true); format2->setFontColor(QColor(Qt::magenta)); for (int row=11; row<30; row++) for (int col=8; col<15; col++) xlsx.write(row, col, row+col); xlsx.setColumn(8, 15, 5.0, format2); xlsx.save(); return 0; }
int main(int argc, char** argv) { QGuiApplication(argc, argv); QXlsx::Document xlsx; xlsx.setColumn(1, 4, 20.0); QXlsx::Format *header = xlsx.createFormat(); 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 = xlsx.createFormat(); format->setNumberFormat(numFormats[i]); xlsx.write(row, 3, 100.0, format); } //Builtin number formats xlsx.addWorksheet(); xlsx.setColumn(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 = xlsx.createFormat(); format->setNumberFormatIndex(numFmt); xlsx.write(row, 3, 100.0, format); } xlsx.save(); return 0; }
int main() { QXlsx::Document xlsx; QXlsx::Format *format1 = xlsx.createFormat(); format1->setFontColor(QColor(Qt::red)); format1->setFontSize(15); format1->setHorizontalAlignment(QXlsx::Format::AlignHCenter); format1->setBorderStyle(QXlsx::Format::BorderDashDotDot); xlsx.write("A1", "Hello Qt!", format1); xlsx.write("B3", 12345, format1); QXlsx::Format *format2 = xlsx.createFormat(); format2->setFontBold(true); format2->setFontUnderline(QXlsx::Format::FontUnderlineDouble); format2->setFillPattern(QXlsx::Format::PatternLightUp); xlsx.write("C5", "=44+33", format2); xlsx.write("D7", true, format2); QXlsx::Format *format3 = xlsx.createFormat(); format3->setFontBold(true); format3->setFontColor(QColor(Qt::blue)); format3->setFontSize(20); xlsx.write(10, 0, "Hello Row Style"); xlsx.write(10, 5, "Blue Color"); xlsx.setRow(10, 40, format3); QXlsx::Format *format4 = xlsx.createFormat(); format4->setFontBold(true); format4->setFontColor(QColor(Qt::magenta)); for (int row=20; row<40; row++) for (int col=8; col<15; col++) xlsx.write(row, col, row+col); xlsx.setColumn(8, 15, 5.0, format4); xlsx.write("A5", QDate(2013, 8, 29)); QXlsx::Format *format6 = xlsx.createFormat(); format6->setPatternBackgroundColor(QColor(Qt::green)); xlsx.write("A6", "Background color: green", format6); xlsx.saveAs("book1.xlsx"); return 0; }