1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-30 05:02:52 +08:00
QXlsx/TestExcel/definename.cpp

48 lines
1.0 KiB
C++
Raw Normal View History

2017-09-16 16:34:45 +09:00
// definename.cpp
2019-01-02 20:56:00 +09:00
#include <QtGlobal>
2017-09-16 12:21:23 +09:00
#include <QtCore>
2019-01-02 20:56:00 +09:00
#include <QDebug>
2017-09-16 12:21:23 +09:00
#include "xlsxdocument.h"
2017-10-05 14:59:46 +09:00
using namespace QXlsx;
2017-09-16 12:21:23 +09:00
2017-09-16 16:34:45 +09:00
int definename()
2017-09-16 12:21:23 +09:00
{
//![0]
Document xlsx;
for (int i=1; i<=10; ++i) {
xlsx.write(i, 1, i);
xlsx.write(i, 2, i*i);
xlsx.write(i, 3, i*i*i);
}
//![0]
2017-09-23 11:43:18 +09:00
2017-09-16 12:21:23 +09:00
//![1]
xlsx.defineName("MyCol_1", "=Sheet1!$A$1:$A$10");
xlsx.defineName("MyCol_2", "=Sheet1!$B$1:$B$10", "This is comments");
xlsx.defineName("MyCol_3", "=Sheet1!$C$1:$C$10", "", "Sheet1");
xlsx.defineName("Factor", "=0.5");
//![1]
2017-09-23 11:43:18 +09:00
2017-09-16 12:21:23 +09:00
//![2]
xlsx.write(11, 1, "=SUM(MyCol_1)");
xlsx.write(11, 2, "=SUM(MyCol_2)");
xlsx.write(11, 3, "=SUM(MyCol_3)");
xlsx.write(12, 1, "=SUM(MyCol_1)*Factor");
xlsx.write(12, 2, "=SUM(MyCol_2)*Factor");
xlsx.write(12, 3, "=SUM(MyCol_3)*Factor");
//![2]
xlsx.saveAs("definename1.xlsx");
Document xlsx2("definename1.xlsx");
if ( xlsx2.load() )
{
xlsx2.saveAs("definename2.xlsx");
}
2017-09-16 12:21:23 +09:00
return 0;
}