0
点赞
收藏
分享

微信扫一扫

数字信号处理2: 离散信号与系统的频谱分析

郝春妮 2024-08-14 阅读 32

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

相关推荐

0 条评论