当前位置:网站首页>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
边栏推荐
猜你喜欢
mysql查询字符串类型的字段使用数字类型查询时问题
[programming practice / embedded competition] learning record of embedded competition (II): picture streaming based on TCP
Install MySQL for Ubuntu and query the average score
高精度焊接机械臂定位
Samsung, March to the west again
扎心了!一女子发朋友圈羡慕别人按时发工资被开除,连点赞的同事也一同被开除了...
Briefly describe the hierarchical strategy of memory
输入 “ net start mysql ”,出现 “ 发生系统错误 5。 拒绝访问 ” 。问题详解
浅谈ES6尾调优化
Brief description of CPU
随机推荐
Convert object to URL
一个没啥L用,但可以装X的IDEA插件
【无标题】
Why are there 1px problems? How?
2022.4.11-4.17 AI行业周刊(第93期):AI行业的困局
简述存储器的分级策略
为什么会存在1px问题?怎么解决?
LeetCode15. Sum of three
GUI,CLI与Unix哲学
Mobile terminal layout (3D conversion, animation)
How does feign integrate hystrix
User manual of Chinese version of solidity ide Remix
数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲
LeetCode簡單題之計算字符串的數字和
Penetration test interview collection -- HVV---
Jetson Xavier NX(3)Bazel Mediapipe 安装
3C装配中的机械臂运动规划
Reverse linked list exercise
访问数据库的时候出现错误 Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY.详解
LeetCode15. 三数之和