当前位置:网站首页>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查询字符串类型的字段使用数字类型查询时问题

搜一下导航完整程序源码

Go语学习笔记 - 语言接口 | 从零开始Go语言

Data security has become a hidden danger. Let's see how vivo can make "user data" armor again

vslam PPT

Smart business card applet business card details page function implementation key code

高精度焊接机械臂定位

简述CPU

AAAI 2022招募讲者啦!!

扎心了!一女子发朋友圈羡慕别人按时发工资被开除,连点赞的同事也一同被开除了...
随机推荐
求3个字符串(每串不超过20个字符)中的最大者。
渗透测试面试合集---HVV---
输入/输出系统
惨了,搞坏了领导的机密文件,吐血分享备份文件的代码技巧
Briefly describe the hierarchical strategy of memory
Alibaba sentinel learning QA
C 输出一种二维数组,特点如下。
ApplicationReadyEvent的使用
redis主从服务器问题
clang 如何产生汇编文件
Why are there 1px problems? How?
LeetCode简单题之重新排列日志文件
浅谈ES6尾调优化
The following program deletes n consecutive words starting from the ith character from the string str
Implementation of promise all
[Effective Go 中文翻译]函数篇
AAAI 2022 recruit speakers!!
Ignis公链的NFT生态发展:Unicorn.art的捐赠开发之路
多目视觉SLAM
Depth of binary tree