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

42 lines
800 B
C++

// chartsheet.cpp
#include <QtGlobal>
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
QXLSX_USE_NAMESPACE
int chartsheet()
{
//![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();
barChart->setChartType(Chart::CT_BarChart);
barChart->addSeries(CellRange("A1:A9"), xlsx.sheet("Sheet1"));
//![1]
//![2]
xlsx.saveAs("chartsheet1.xlsx");
//![2]
Document xlsx2("chartsheet1.xlsx");
if ( xlsx2.load() )
{
xlsx2.saveAs("chartsheet2.xlsx");
}
return 0;
}