1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-16 04:42:53 +08:00
QXlsx/TestExcel/chartsheet.cpp

36 lines
748 B
C++
Raw Normal View History

2017-09-16 16:34:45 +09:00
// chartsheet.cpp
2017-09-16 12:21:23 +09:00
#include <QtCore>
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
using namespace QXlsx;
2017-09-16 16:34:45 +09:00
int chartsheet()
2017-09-16 12:21:23 +09:00
{
//![0]
Document xlsx;
for (int i=1; i<10; ++i)
xlsx.write(i, 1, i*i);
//![0]
//![1]
xlsx.addSheet("Chart1", AbstractSheet::ST_ChartSheet);
Chartsheet *sheet = static_cast<Chartsheet*>(xlsx.currentSheet());
Chart *barChart = sheet->chart();
2019-02-26 16:59:31 +09:00
barChart->setChartType(Chart::CT_BarChart);
2017-09-16 12:21:23 +09:00
barChart->addSeries(CellRange("A1:A9"), xlsx.sheet("Sheet1"));
//![1]
//![2]
2017-09-23 11:43:18 +09:00
xlsx.saveAs("chartsheet1.xlsx");
2017-09-16 12:21:23 +09:00
//![2]
2017-09-23 11:43:18 +09:00
Document xlsx2("chartsheet1.xlsx");
xlsx2.saveAs("chartsheet2.xlsx");
2017-09-24 00:09:33 +09:00
2017-09-16 12:21:23 +09:00
return 0;
}