Using QXlsx::Document instead of QXlsx::Workbook
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include <QtCore>
|
||||
#include "xlsxworkbook.h"
|
||||
#include "xlsxdocument.h"
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
# define DATA_PATH "../../../"
|
||||
@@ -9,20 +9,20 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
QXlsx::Workbook workbook;
|
||||
QXlsx::Document xlsx;
|
||||
/*
|
||||
These properties are visible when you use the
|
||||
Office Button -> Prepare -> Properties option in Excel and are also
|
||||
available to external applications that read or index windows files
|
||||
*/
|
||||
workbook.setProperty("title", "This is an example spreadsheet");
|
||||
workbook.setProperty("subject", "With document properties");
|
||||
workbook.setProperty("creator", "Debao Zhang");
|
||||
workbook.setProperty("company", "HMICN");
|
||||
workbook.setProperty("category", "Example spreadsheets");
|
||||
workbook.setProperty("keywords", "Sample, Example, Properties");
|
||||
workbook.setProperty("description", "Created with Qt Xlsx");
|
||||
xlsx.setDocumentProperty("title", "This is an example spreadsheet");
|
||||
xlsx.setDocumentProperty("subject", "With document properties");
|
||||
xlsx.setDocumentProperty("creator", "Debao Zhang");
|
||||
xlsx.setDocumentProperty("company", "HMICN");
|
||||
xlsx.setDocumentProperty("category", "Example spreadsheets");
|
||||
xlsx.setDocumentProperty("keywords", "Sample, Example, Properties");
|
||||
xlsx.setDocumentProperty("description", "Created with Qt Xlsx");
|
||||
|
||||
workbook.save(DATA_PATH"Test.xlsx");
|
||||
xlsx.saveAs(DATA_PATH"Test.xlsx");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <QtCore>
|
||||
#include "xlsxworkbook.h"
|
||||
#include "xlsxworksheet.h"
|
||||
#include "xlsxdocument.h"
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
# define DATA_PATH "../../../"
|
||||
@@ -10,31 +9,30 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
QXlsx::Workbook workbook;
|
||||
QXlsx::Worksheet *sheet = workbook.addWorksheet();
|
||||
sheet->write("A1", "Hello Qt!");
|
||||
sheet->write("B3", 12345);
|
||||
sheet->write("C5", "=44+33");
|
||||
sheet->write("D7", true);
|
||||
sheet->write("E1", "http://qt-project.org");
|
||||
QXlsx::Document xlsx;
|
||||
|
||||
QXlsx::Worksheet *sheet2 = workbook.addWorksheet();
|
||||
//Write to first worksheet.
|
||||
xlsx.write("A1", "Hello Qt!");
|
||||
xlsx.write("B3", 12345);
|
||||
xlsx.write("C5", "=44+33");
|
||||
xlsx.write("D7", true);
|
||||
xlsx.write("E1", "http://qt-project.org");
|
||||
|
||||
//Create another worksheet.
|
||||
xlsx.addWorksheet();
|
||||
//Rows and columns are zero indexed.
|
||||
//The first cell in a worksheet, "A1", is (0, 0).
|
||||
sheet2->write(0, 0, "First");
|
||||
sheet2->write(1, 0, "Second");
|
||||
sheet2->write(2, 0, "Third");
|
||||
sheet2->write(3, 0, "Fourth");
|
||||
sheet2->write(4, 0, "Total");
|
||||
sheet2->write(0, 1, 100);
|
||||
sheet2->write(1, 1, 200);
|
||||
sheet2->write(2, 1, 300);
|
||||
sheet2->write(3, 1, 400);
|
||||
sheet2->write(4, 1, "=SUM(B1:B4)");
|
||||
xlsx.write(0, 0, "First");
|
||||
xlsx.write(1, 0, "Second");
|
||||
xlsx.write(2, 0, "Third");
|
||||
xlsx.write(3, 0, "Fourth");
|
||||
xlsx.write(4, 0, "Total");
|
||||
xlsx.write(0, 1, 100);
|
||||
xlsx.write(1, 1, 200);
|
||||
xlsx.write(2, 1, 300);
|
||||
xlsx.write(3, 1, 400);
|
||||
xlsx.write(4, 1, "=SUM(B1:B4)");
|
||||
|
||||
workbook.setActivedWorksheet(1);
|
||||
|
||||
workbook.save(DATA_PATH"Test.xlsx");
|
||||
workbook.save(DATA_PATH"Test.zip");
|
||||
xlsx.saveAs(DATA_PATH"Test.xlsx");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <QtGui>
|
||||
#include "xlsxworkbook.h"
|
||||
#include "xlsxworksheet.h"
|
||||
#include "xlsxdocument.h"
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
# define DATA_PATH "../../../"
|
||||
@@ -12,14 +11,13 @@ int main(int argc, char** argv)
|
||||
{
|
||||
QGuiApplication(argc, argv);
|
||||
|
||||
QXlsx::Workbook workbook;
|
||||
QXlsx::Worksheet *sheet = workbook.addWorksheet();
|
||||
QXlsx::Document xlsx;
|
||||
|
||||
QImage image(400, 300, QImage::Format_RGB32);
|
||||
image.fill(Qt::green);
|
||||
sheet->insertImage(5, 5, image);
|
||||
xlsx.insertImage(5, 5, image);
|
||||
|
||||
workbook.save(DATA_PATH"Test.xlsx");
|
||||
// workbook.save(DATA_PATH"Test2.zip");
|
||||
xlsx.saveAs(DATA_PATH"Test.xlsx");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <QtGui>
|
||||
#include "xlsxworkbook.h"
|
||||
#include "xlsxworksheet.h"
|
||||
#include "xlsxdocument.h"
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
# define DATA_PATH "../../../"
|
||||
@@ -12,16 +11,15 @@ int main(int argc, char** argv)
|
||||
{
|
||||
QGuiApplication(argc, argv);
|
||||
|
||||
QXlsx::Workbook workbook;
|
||||
QXlsx::Worksheet *sheet = workbook.addWorksheet();
|
||||
QXlsx::Document xlsx;
|
||||
|
||||
sheet->write("B1", "Merge Cells");
|
||||
sheet->mergeCells("B1:B5");
|
||||
xlsx.write("B1", "Merge Cells");
|
||||
xlsx.mergeCells("B1:B5");
|
||||
|
||||
sheet->write("E2", "Merge Cells 2");
|
||||
sheet->mergeCells("E2:G4");
|
||||
xlsx.write("E2", "Merge Cells 2");
|
||||
xlsx.mergeCells("E2:G4");
|
||||
|
||||
workbook.save(DATA_PATH"Test.xlsx");
|
||||
xlsx.saveAs(DATA_PATH"Test.xlsx");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <QtCore>
|
||||
#include "xlsxworkbook.h"
|
||||
#include "xlsxworksheet.h"
|
||||
#include "xlsxdocument.h"
|
||||
#include "xlsxformat.h"
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
@@ -11,44 +10,42 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
QXlsx::Workbook workbook;
|
||||
QXlsx::Worksheet *sheet = workbook.addWorksheet();
|
||||
|
||||
QXlsx::Format *format1 = workbook.addFormat();
|
||||
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);
|
||||
sheet->write("A1", "Hello Qt!", format1);
|
||||
sheet->write("B3", 12345, format1);
|
||||
xlsx.write("A1", "Hello Qt!", format1);
|
||||
xlsx.write("B3", 12345, format1);
|
||||
|
||||
QXlsx::Format *format2 = workbook.addFormat();
|
||||
QXlsx::Format *format2 = xlsx.createFormat();
|
||||
format2->setFontBold(true);
|
||||
format2->setFontUnderline(QXlsx::Format::FontUnderlineDouble);
|
||||
format2->setFillPattern(QXlsx::Format::PatternLightUp);
|
||||
sheet->write("C5", "=44+33", format2);
|
||||
sheet->write("D7", true, format2);
|
||||
xlsx.write("C5", "=44+33", format2);
|
||||
xlsx.write("D7", true, format2);
|
||||
|
||||
QXlsx::Format *format3 = workbook.addFormat();
|
||||
QXlsx::Format *format3 = xlsx.createFormat();
|
||||
format3->setFontBold(true);
|
||||
format3->setFontColor(QColor(Qt::blue));
|
||||
format3->setFontSize(20);
|
||||
sheet->write(10, 0, "Hello Row Style");
|
||||
sheet->write(10, 5, "Blue Color");
|
||||
sheet->setRow(10, 40, format3);
|
||||
xlsx.write(10, 0, "Hello Row Style");
|
||||
xlsx.write(10, 5, "Blue Color");
|
||||
xlsx.setRow(10, 40, format3);
|
||||
|
||||
QXlsx::Format *format4 = workbook.addFormat();
|
||||
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++)
|
||||
sheet->write(row, col, row+col);
|
||||
sheet->setColumn(8, 15, 5.0, format4);
|
||||
xlsx.write(row, col, row+col);
|
||||
xlsx.setColumn(8, 15, 5.0, format4);
|
||||
|
||||
QXlsx::Format *format5 = workbook.addFormat();
|
||||
QXlsx::Format *format5 = xlsx.createFormat();
|
||||
format5->setNumberFormat(22);
|
||||
sheet->write("A5", QDate(2013, 8, 29), format5);
|
||||
xlsx.write("A5", QDate(2013, 8, 29), format5);
|
||||
|
||||
workbook.save(DATA_PATH"TestStyle.xlsx");
|
||||
xlsx.saveAs(DATA_PATH"TestStyle.xlsx");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user