将QXlsx文件夹复制到目标工程文件夹中
在XXX.pro中添加下面代码:
include(./QXlsx/QXlsx.pri)
点运行
工程目录中自动出现“QXlsx”文件夹
注意:如果没有自动出现,则点菜单栏->构建->重新构建
将excelopera.h和excelopera.c添加到工程
在mainwindow.h中添加
#include "excelopera.h"
……
ExcelOpera m_excelopera;
在工程文件夹中新建test1.xlsx文件,并写入以下内容
在mainwindow.c中添加下面代码
#include <QDebug>
//打开
qDebug()<<m_excelopera.OpenFile("test1.xlsx");
//读取
QStringList list1 = m_excelopera.ReadColumn(0,3);
qDebug()<<list1;
//写入
QStringList list2;
list2<<"你好"<<"Hello";
m_excelopera.WriteRow(3,list2);//第4行
m_excelopera.WriteColumn(3,list2);//第4列
然后点运行
可以看到,已经成功读取xlsx中的内容。
打开test1.xlsx可以看到,写入功能也正常。
下载示例代码
https://download.youkuaiyun.com/download/jiangnanan/89894200