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.";
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值