当前位置: 首页 > news >正文

QtExcel/QXlsx

GitHub地址:

https://github.com/QtExcel/QXlsx

1.3k的star,也挺多的。

使用Qt5 或 6的Excel 文件(*.xlsx)读取/写入库。

QtXlsxWriter的派生物

Descendant : 派生物


QtExcel的一个成员:

热衷于编写C++和Qt软件,已经超过10年了。

所属国家​​:巴西(Brazil)

行政地位​​:圣保罗州首府,巴西最大城市


首尔,南韩


QXlsx | Excel file(*.xlsx) reader/writer library using Qt 5 or 6. Descendant of QtXlsxWriter.

有简体中文版的介绍:

QXlsx | Excel file(*.xlsx) reader/writer library using Qt 5 or 6. Descendant of QtXlsxWriter.

很棒很棒!


关键点:

Qt框架,C++,Excel的读取/写入

这里提到:QtXlsx停止维护了。

Qt Xlsx-CSDN博客

确实,最近一次提交是在2020年了。

使用方法:

(1)把源码塞到项目中

(2)把它作为第三方库来使用。


如何安装QXlsx project?

如何设置 QXlsx 项目 | QXlsx

有中文版本,nice

我直接把zip下载下来啦,因为我的git好像配置的有点问题

md文件还挺多的,可以用vnote来查看。

选择'New File or Project'

选择'Qt Console Application',也可以选择'Qt Widgets Application'

(人家的文档写的真用心啊,手把手教)

拷贝文件到自己的项目的目录

在.pro文件中添入这段代码:

# QXlsx code for Application Qt project
QXLSX_PARENTPATH=./         # current QXlsx path is . (. means curret directory)
QXLSX_HEADERPATH=./header/  # current QXlsx header path is ./header/
QXLSX_SOURCEPATH=./source/  # current QXlsx source path is ./source/
include(./QXlsx.pri)

这种写法,是直接把代码嵌入到项目中了,可以看到,生成了很多相关的.o文件。

测试一下给的这个示例代码:

// main.cpp#include <QCoreApplication>#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;int main(int argc, char *argv[])
{QCoreApplication a(argc, argv);QXlsx::Document xlsx;xlsx.write("A1", "Hello Qt!"); // write "Hello Qt!" to cell(A,1). it's shared string.xlsx.saveAs("Test.xlsx"); // save the document as 'Test.xlsx'return 0;// return a.exec();
}

可以看到,这个库,使用起来还是挺方便的。


示例:

QXlsx Examples | QXlsx

示例:

写入excel,然后读取excel中的内容。

// main.cpp#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVariant>
#include <QDebug>//#include <iostream>
//using namespace std;// [0] include QXlsx headers
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
using namespace QXlsx;int main(int argc, char *argv[])
{QCoreApplication app(argc, argv);int row = 1; int col = 1;// [1]  Writing excel file(*.xlsx)QXlsx::Document xlsxW;QVariant writeValue = QString("Hello Qt!");xlsxW.write(row, col, writeValue); // write "Hello Qt!" to cell(A,1).xlsxW.saveAs("Test.xlsx"); // save the document as 'Test.xlsx'// [2] Reading excel file(*.xlsx)Document xlsxR("Test.xlsx");if (xlsxR.load()) // load excel file{auto cell = xlsxR.cellAt(row, col); // get cell pointer.if ( cell != NULL ){QVariant var = cell->readValue(); // read cell value (number(double), QDateTime, QString ...)qDebug() << var; // display value. it is 'Hello Qt!'.}}return 0;
}

http://www.xdnf.cn/news/1363483.html

相关文章:

  • 力扣82:删除排序链表中的重复元素Ⅱ
  • 《Password Guessing Using Large Language Models》——论文阅读
  • 离线可用的网络急救方案
  • JavaScript Intl.RelativeTimeFormat:自动生成 “3 分钟前” 的国际化工具
  • [React]Antd Select组件输入搜索时调用接口
  • 基于RFM模型的客户群体大数据分析及用户聚类系统的设计与实现
  • 【Flink】运行模式
  • 文献阅读笔记:KalmanNet-融合神经网络和卡尔曼滤波的部分已知动力学状态估计
  • Zabbix Vs. Grafana
  • win11中系统的WSL安装Centos以及必要组件
  • nmcli命令详解
  • Docker:网络连接
  • SQL性能调优
  • 2025年8月25日-8月31日(qtopengl+ue独立游戏)
  • 告别“复制粘贴”式换肤:我用Adobe XD组件变体与CC库,构建多品牌设计系统架构
  • THM Bricks Heist靶机
  • 新的 macOS 安装程序声称能够快速窃取数据,并在暗网上销售
  • 文入门Ubuntu:从零到精通的Linux之旅
  • 【ARM】MDK在debug模式下断点的类型
  • 中介者模式及优化
  • 使用EasyExcel根据模板导出文件
  • imx586手册和相机寄存器部分解读
  • 【Springboot】依赖注入方式
  • Linux 离线安装lrzsz(rz、sz上传下载小插件)
  • IntelliJ IDEA 新手入门教程-Java、Web、Maven创建(带图解)
  • 疯狂星期四文案网第49天运营日记
  • 使用现代 <img> 元素实现完美图片效果(2025 深度实战版)
  • 【图像处理基石】基于Real-ESRGAN的实时图像超分辨率技术实现
  • MongoDB vs MySQL:NoSQL 和 SQL 的核心区别与适用场景
  • Portswigger靶场之Visible error-based SQL injection通关秘籍