当前位置:网站首页>Qt利用QtXlsx操作excel文件
Qt利用QtXlsx操作excel文件
2022-04-23 07:15:00 【欧特_Glodon】
一、入门示例
代码来自QtXlsx提供的示例文件项目 F:\QtProject\QtXlsxWriter-master\examples\xlsx\hello
1、生成一个excel文件

2、代码如下
QtXlsxTest1.pro
QT += core
QT -= gui
QT += xlsx
CONFIG += c++11
TARGET = QtXlsxTest1
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
main.cpp
#include <QCoreApplication>
#include <QtCore>
#include "xlsxdocument.h"
int main()
{
QXlsx::Document xlsx("excel01.xlsx");
//![1]
xlsx.write("A1", "Hello Qt!");
xlsx.write("A2", 12345);
xlsx.write("A3", "=44+33");
xlsx.write("A4", true);
xlsx.write("A5", "http://qt-project.org");
xlsx.write("A6", QDate(2013, 12, 27));
xlsx.write("A7", QTime(6, 30));
xlsx.save();
return 0;
}
二、excel文件读写
1、写入excel文件

#include <QCoreApplication>
#include <QtCore>
#include "xlsxdocument.h"
#include <QDebug>
void WriteExcel()
{
QXlsx::Document xlsx;
for(int i = 1; i < 11; i++)
{
for(int j = 1; j < 11; j++)
{
QString sValue = QString("%1_%2").arg(i).arg(j);
xlsx.write(i,j,sValue);
}
}
xlsx.saveAs("WriteExcel.xlsx");
}
2、读取excel文件

void ReadExcel()
{
QXlsx::Document xlsx("WriteExcel.xlsx");
for(int i = 1; i < 11; i++)
{
for(int j = 1; j < 11; j++)
{
QVariant sValue = xlsx.read(i,j);
if(sValue.type() == QVariant::Int)
{
qDebug()<<sValue.toInt();
}
else if(sValue.type() == QVariant::Double)
{
qDebug()<<sValue.toDouble();
}
else if(sValue.type() == QVariant::String)
{
qDebug() << sValue.toString();
}
}
}
}
版权声明
本文为[欧特_Glodon]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_37251750/article/details/124341405
边栏推荐
- Distributed service governance Nacos
- [appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test
- LeetCode简单题之重新排列日志文件
- Implementation principle of instanceof
- sql 使用过的查询语句
- Draw a circle quickly in MATLAB (the one that can be drawn directly given the coordinates and radius of the center of the circle)
- 怎么读书读论文
- php高精度计算
- 使用 Ingress 实现金丝雀发布
- NFT ecological development of Ignis public chain: unicorn Donation and development of Art
猜你喜欢

扎心了!一女子发朋友圈羡慕别人按时发工资被开除,连点赞的同事也一同被开除了...

How does feign integrate hystrix

Draw a circle quickly in MATLAB (the one that can be drawn directly given the coordinates and radius of the center of the circle)

一篇文章看懂变量提升(hoisting)

巨头押注的全屋智能,正在驱动海信、华为、小米们「自我革命」

【无标题】

Ubuntu安装Mysql并查询平均成绩

Somme numérique de la chaîne de calcul pour un problème simple de leetcode

Mobile terminal layout (3D conversion, animation)

Positioning of high precision welding manipulator
随机推荐
[appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test
redis主从服务器问题
[effective go Chinese translation] part I
An article understands variable lifting
Compiler des questions de principe - avec des réponses
Usage of databinding
[effective go Chinese translation] function
岛屿的个数
php高精度计算
Implementation of new
LeetCode 1611. 使整数变为 0 的最少操作次数
单点登录 SSO
为什么会存在1px问题?怎么解决?
Weekly leetcode - 06 array topics 7 ~ 739 ~ 50 ~ offer 62 ~ 26 ~ 189 ~ 9
GUI,CLI与Unix哲学
PHP high precision computing
多目视觉SLAM
在MATLAB中快速画圆(给出圆心坐标和半径就能直接画的那种)
Ubuntu安装Mysql并查询平均成绩
高精度焊接机械臂定位