Qt Xlsx使用教程、Qt操作Excel、Qt生成Excel图表、跨平台不依赖Office 直接使用源码

1.Qt Xlsx库简介

官方文档:Qt Xlsx | QtXlsx 0.3 (debao.me)

下载地址:dbzhang800/QtXlsxWriter: .xlsx file reader and writer for Qt5 (github.com)

CSDN下载地址:QtXlsxWriter-master源码资源-CSDN文库

2.源码取出

3.目录结构

再根目录下创建一个 qtxlsx 文件夹 把src都解压进去

4.引入目录

.pro文件引入

复制代码
# 使用qtxlsx源代码
include(qtxlsx/src/xlsx/qtxlsx.pri)

软件代码引入

复制代码
//引入头文件
#include "xlsxdocument.h"

实例

自己弄的一个简单写入动作 需要的自改

复制代码
void MainWindow::appendXlsxFile(const QString &firmwareVersion, const QString &imei, const QString &imsi, const QString &ID1, const QString &ID2, const QString &macAddress) {
    QString fileName = "自定义名称.xlsx";

    QXlsx::Document xlsx(fileName); // This will load the file if it exists or create a new one

    if (!xlsx.sheetNames().isEmpty()) {
        // File exists, load the existing document
    } else {
        xlsx.addSheet("Device Info");
        QXlsx::Worksheet *sheet = xlsx.currentWorksheet();
        sheet->write(1, 1, "Firmware Version");
        sheet->write(1, 2, "IMEI");
        sheet->write(1, 3, "IMSI");
        sheet->write(1, 4, "ID1");
        sheet->write(1, 5, "ID2");
        sheet->write(1, 6, "MAC (Formatted)");
        sheet->write(1, 7, "MAC (Original)");
        sheet->write(1, 8, "Generation DateTime");
    }

    QXlsx::Worksheet *sheet = xlsx.currentWorksheet();
    int lastRow = sheet->dimension().lastRow() + 1;

    QString TmpstrMac = macAddress;
    TmpstrMac = TmpstrMac.remove(":");

    // 添加新行数据
    sheet->write(lastRow, 1, firmwareVersion);
    sheet->write(lastRow, 2, imei);
    sheet->write(lastRow, 3, imsi);
    sheet->write(lastRow, 4, ID1);
    sheet->write(lastRow, 5, ID2);
    sheet->write(lastRow, 6, TmpstrMac);
    sheet->write(lastRow, 7, macAddress);
    sheet->write(lastRow, 8, QDateTime::currentDateTime().toString(Qt::ISODate));

    if (xlsx.save()) {
        qDebug() << "XLSX file appended successfully.";
    } else {
        qDebug() << "Failed to save XLSX file.";
    }
}
相关推荐
用户805533698033 天前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner3 天前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz8 天前
QML Hello World 入门示例
qt
xcyxiner11 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner11 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner12 天前
DicomViewer (添加模型类)3
qt
xcyxiner12 天前
DicomViewer (目录调整) 2
qt
xcyxiner12 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR00614 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术14 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript