2020-06-05 22:20:08 +09:00
|
|
|
// chartextended.cpp
|
2019-12-08 16:16:25 +01:00
|
|
|
|
|
|
|
#include "xlsxcellrange.h"
|
|
|
|
#include "xlsxchart.h"
|
2023-09-04 00:46:33 -03:00
|
|
|
#include "xlsxdocument.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QtGlobal>
|
2019-12-08 16:16:25 +01:00
|
|
|
|
2020-06-05 22:20:08 +09:00
|
|
|
QXLSX_USE_NAMESPACE
|
2019-12-08 16:16:25 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test Chart with title, gridlines, legends, multiple headers
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
int chartExtended()
|
|
|
|
{
|
|
|
|
Document xlsx;
|
2023-09-04 00:46:33 -03:00
|
|
|
for (int i = 1; i < 10; ++i) {
|
|
|
|
xlsx.write(1, i + 1, "Pos " + QString::number(i));
|
2019-12-08 16:16:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
xlsx.write(2, 1, "Set 1");
|
|
|
|
xlsx.write(3, 1, "Set 2");
|
|
|
|
|
2023-09-04 00:46:33 -03:00
|
|
|
for (int i = 1; i < 10; ++i) {
|
|
|
|
xlsx.write(2, i + 1, i * i * i); // A2:A10
|
|
|
|
xlsx.write(3, i + 1, i * i); // B2:B10
|
2019-12-08 16:16:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Chart *barChart1 = xlsx.insertChart(4, 3, QSize(300, 300));
|
|
|
|
barChart1->setChartType(Chart::CT_BarChart);
|
2019-12-11 21:32:40 +09:00
|
|
|
barChart1->setChartLegend(Chart::Right);
|
2019-12-08 16:16:25 +01:00
|
|
|
barChart1->setChartTitle("Test1");
|
|
|
|
// Messreihen
|
2023-09-04 00:46:33 -03:00
|
|
|
barChart1->addSeries(CellRange(1, 1, 3, 10), NULL, true, true, false);
|
2019-12-08 16:16:25 +01:00
|
|
|
|
|
|
|
Chart *barChart2 = xlsx.insertChart(4, 9, QSize(300, 300));
|
|
|
|
barChart2->setChartType(Chart::CT_BarChart);
|
2019-12-11 21:32:40 +09:00
|
|
|
barChart2->setChartLegend(Chart::Right);
|
2019-12-08 16:16:25 +01:00
|
|
|
barChart2->setChartTitle("Test2");
|
|
|
|
barChart2->setGridlinesEnable(true);
|
|
|
|
// Messreihen
|
2023-09-04 00:46:33 -03:00
|
|
|
barChart2->addSeries(CellRange(1, 1, 3, 10), NULL, true, true, true);
|
2019-12-08 16:16:25 +01:00
|
|
|
|
|
|
|
Chart *barChart3 = xlsx.insertChart(24, 3, QSize(300, 300));
|
|
|
|
barChart3->setChartType(Chart::CT_BarChart);
|
2019-12-11 21:32:40 +09:00
|
|
|
barChart3->setChartLegend(Chart::Left);
|
2019-12-08 16:16:25 +01:00
|
|
|
barChart3->setChartTitle("Test3");
|
|
|
|
// Messreihen
|
2023-09-04 00:46:33 -03:00
|
|
|
barChart3->addSeries(CellRange(1, 1, 3, 10));
|
2019-12-08 16:16:25 +01:00
|
|
|
|
|
|
|
Chart *barChart4 = xlsx.insertChart(24, 9, QSize(300, 300));
|
|
|
|
barChart4->setChartType(Chart::CT_BarChart);
|
2019-12-11 21:32:40 +09:00
|
|
|
barChart4->setChartLegend(Chart::Top);
|
2019-12-08 16:16:25 +01:00
|
|
|
barChart4->setChartTitle("Test4");
|
|
|
|
// Messreihen
|
2023-09-04 00:46:33 -03:00
|
|
|
barChart4->addSeries(CellRange(1, 1, 3, 10));
|
2019-12-08 16:16:25 +01:00
|
|
|
|
|
|
|
Chart *barChart5 = xlsx.insertChart(44, 9, QSize(300, 300));
|
|
|
|
barChart5->setChartType(Chart::CT_BarChart);
|
2019-12-11 21:32:40 +09:00
|
|
|
barChart5->setChartLegend(Chart::Bottom);
|
2019-12-08 16:16:25 +01:00
|
|
|
barChart5->setChartTitle("Test5");
|
|
|
|
// Messreihen
|
2023-09-04 00:46:33 -03:00
|
|
|
barChart5->addSeries(CellRange(1, 1, 3, 10));
|
2019-12-08 16:16:25 +01:00
|
|
|
|
|
|
|
//![2]
|
|
|
|
xlsx.saveAs("chartExtended1.xlsx");
|
|
|
|
//![2]
|
|
|
|
|
|
|
|
Document xlsx2("chartExtended1.xlsx");
|
2023-09-04 00:46:33 -03:00
|
|
|
if (xlsx2.load()) {
|
2019-12-08 16:16:25 +01:00
|
|
|
xlsx2.saveAs("chartExtended2.xlsx");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|