【Qt QAxObject】使用 QAxObject 高效任意读写 Excel 表

QAxObject操作excel QT +=axcontainer 阅读详情
AI摘要

本文介绍了在Qt中使用QAxObject实现读写Excel表的方法。先介绍了QAxObject相关的COM组件对象模型,接着阐述了基本使用步骤,包括包含相关文件、创建Excel进程、获取工作簿集和电子表格集、选取单元格范围、读写数据等,最后给出示例演示及源文件代码。

1. 用什么操作 Excel 表

  Qt 的官网库中是不包含 Microsoft Excel 的操作库,关于对 Microsoft Excel 的操作库可选的有很多,包含基于 Windows 系统本身的 ActiveX、Qt Xlsx、xlsLib、LibXL、qtXLS、BasicExcel、Number Duck。

库.xls.xlsx读写平台
Qt Xlsx❌✔️✔️✔️跨平台
xls✔️❌❌✔️跨平台
libxls✔️❌❌✔️跨平台
libXL✔️✔️✔️✔️跨平台
ActiveX✔️✔️✔️✔️Windows原生
qtXLS✔️❌✔️✔️Windows
BasicExcel✔️❌✔️✔️Windows
Number Duck✔️❌✔️✔️Windows,Linux

  本文采用基于 Windows 的 ActiveX 对象,在 Qt 中也就是 QAxObjcet 实现读写 Excel 表。

2. QAxObject 简介

  在介绍 QAxObject 之前,首先简单了解一下 Windows 上的 COM 组件对象模型,COM 是一个独立于平台的分布式面向对象的系统,用于创建可以交互的二进制软件组件。 COM 是 Microsoft 的 OLE (复合文档的基础技术,) 和 ActiveX (支持 Internet 的组件) 技术。可以使用各种编程语言创建 COM 对象。 面向对象的语言(如 C++)提供了简化 COM 对象的实现的编程机制。 这些对象可以位于单个进程中、其他进程中,甚至在远程计算机上也是如此。

COM 组件模型对象相信介绍可查看:https://download.csdn.net/download/qq_36393978/88268235

  而在 Qt 中的 QAxObject 是对 COM 组件模型对象的封装,QAxObject 派生自QAxBase,QAxBase 提供了一组 API 通过 IUnknown 指针直接访问 COM 对象,具体结构如下图。

在这里插入图片描述

  而在 Windows 上的 Excel 也是一个这样的 COM 对象,因此,可以采用在 Qt 中使用 QAxObjcet 实现对 Excel 的操作,其基本的操作流程如下:

在这里插入图片描述

  如上图描述了 Excel 的层次结构,Excel.Application 对象 → WorkBooks 对象 → WorkBook 对象 → WorkSheet 对象 → Range 对象,1 个 excel 有一个 Application 对象,1 个 Application 对象有多个 Workbook 对象组成,这些 Workbook 对象由 Workbooks 对象统一管理,Workbook 对象下包含若干个 WorkSheet,这些 WorkSheet 对象由 WorkSheets 对象统一管理,WorkSheet 下面的 Range 对象,对应这 WorkSheet 里面的表格单元了。箭头表示获取其子对象,获取方式需调用 querySubObject() 函数获取子对象实例,各个子对象调用 dynamicCall() 函数执行对各自的具体操作。

3. 基本使用方法

3.1. 包含相关文件

  要使用 QAxObject 首先要在 .pro 文件中添加其模块名称 axcontainer,这样工程文件在编译的时候就会加载该模块。

// project.pro
QT       += axcontainer

在头文件中需要包含如下几个头文件

#include <QString>
#include <QFileDialog>
#include <QAxObject>
#include <QVariant>
#include <QVariantList>

3.2. 创建 Excel 进程,获取 Excel 工作簿集

打开文件夹选择 Excel 文件,创建 Excel 进程:

// 打开文件夹
QString strFilePathName = QFileDialog::getOpenFileName(this, QStringLiteral("选择Excel文件"),"", tr("Exel file(*.xls *.xlsx)"));
if(strFilePathName.isNull()) {
	return ;
}
QAxObject *excel = new QAxObject(this);

if (excel->setControl("Excel.Application")) {	// 加载 Microsoft Excel 控件
} else {
	excel->setControl("ket.Application");  // 加载 WPS Excel 控件
}

excel->setProperty("Visible", false);  // 不显示 Excel 窗体
QAxObject* workBooks = excel->querySubObject("WorkBooks");  //获取工作簿集合
workBooks->dynamicCall("Open(const QString&)", strFilePathName); //打开打开已存在的工作簿
QAxObject* workBook = excel->querySubObject("ActiveWorkBook"); //获取当前工作簿

3.3. 获取电子表格集

每个 Excel 工作簿中都可以包含若干电子表格 Sheet:

QAxObject* sheets = workBook->querySubObject("Sheets");  //获取工作表集合,Sheets也可换用WorkSheets

获取需要操作的工作表:

QAxObject* sheet = workBook->querySubObject("WorkSheets(int)", 1);//获取工作表集合的工作表1,即sheet1

3.4. 选取需要操作的单元格范围

每页电子表格包含多个单元格,在操作之前需要选取所要操作的单元格范围:
选取当前页面所有已使用单元格:

//获取该sheet的使用范围对象(一般读取 Excel 时会选取全部范围)
QAxObject* usedRange = sheet->querySubObject("UsedRange"); 

选取指定范围的单元格:

//获取 sheet 的指定范围(一般写入数据时,会选取指定范围)
QAxObject* usedRange = sheet->querySubObject("Range(const QString)", "A1:C12");

这里的 A1:C12 则表示选取,A 到 C 列的 1~12 行单元格;若写成 A1:A12 则表示选取,A 列的 1~12 行单元格;当然你也可以写成 A1:A1 则表示只选取 A1 这一个单元格。

选择指定单元格:

//获取 sheet 的指定范围(一般修改数据时,会选取指定单元格)
QAxObject* usedRange = sheet->querySubObject("Range(QVariant,QVariant)", "A6");

这里的 A6,则表示选取 A6 这个单元格。

[注]:获取 UsedRange 操作将会得到一个动态创建 (new) 出来的对象。

3.5. 读取单元格范围内容

  当选取好要操作的单元各范围后,那么这里介绍如何读取选取范围内所有的单元格内容:

QVariant var = usedRange->dynamicCall("Value");
delete usedRange;

  需要注意的是上文代码中除了获取单元格范围 (UsedRange) 操作之外,其余得到的都是该对象的引用,不会占用内存空间,不需要释放,而获取单元格适用范围 (UsedRange) 则得到一个 new 出来新分配的对象,因此在读取或写入操作结束后需要手动释放该对象。

  QVariant 类是一个数据联合体,用来存放读取到的 Excel 数据。而事实上通过调用 dynamicCall("Value") 读到的数据类型是 QList<QList<QVariant>> 类型的,因此要将读到的 var 转换为该类型的数据。

QList<QList<QVariant>> xls_data;

QVariantList varRows = var.toList();
if (varRows.isEmpty()) {
    return;
}

const int rowCount = varRows.size();
this->excel.rowCount = rowCount;

QVariantList rowData;

for (int i = 0; i < rowCount; i++){
    rowData = varRows[i].toList();
    if (rowData.count() > this->excel.columnCount) {
    this->excel.columnCount = rowData.count();
    }
    this->xls_data.push_back(rowData);
}

3.6. 将读取到的数据用 QTableView 展示出来

  这里的 TbleView_table1 是在 Forms 中的直接拖拽的 QTableView 控件。

QStandardItemModel *tab_model;
for (int i = 0; i < xls_data.count(); i++) {
    for (int j = 0; j < xls_data.at(i).count(); j++) {
    QStandardItem *item = new QStandardItem(QString(xls_data.at(i).at(j).toByteArray()));
    tab_model->setItem(i, j, item);

    //delete item;
    }
}
this->ui->TbleView_table1->setModel(tab_model);

3.7. 向选取的单元格范围写入数据

  想必各位也注意到了,在 Excel 中横轴坐标都是用 A~Z 字母表示为了与纵轴的表示方式区别开来,而我们在操作是常用的则是以数字形式,或者说在设置循环中用数字方式更为方便,因此这里需要实现一个数字转 Excel 横坐标的函数,如下。

QString ExcelProcess::to26AlphabetString(int data)
{
    QChar ch = (QChar)(data + 0x40);//A对应0x41
    return QString(ch);
}


void ExcelProcess::convertToColName(int data, QString &res)
{
    Q_ASSERT(data > 0 && data < 65535);
    int tempData = data / 26;
    if (tempData > 0) {
        int mode = data % 26;
        convertToColName(mode, res);
        convertToColName(tempData, res);
    } else {
        res=(to26AlphabetString(data) + res);
    }
}

按照指定行、列,一行一行的添加要写入的数据。

QList<QList<QVariant>> data_total;

int row = 50 - 30, col = 100 - 10;	// 表示:选取范围为,30~50 行,10~100 列

for (int i = 0; i < row; i++) {
	QList<QVariant> data_row;
	for (int j = 0; j < col; j++) {
		data_row.append("ImagineMiracle");
	}
	data_total.append(QVariant(data_row));
}
QString row_s, row_e, col_s, col_e, targetRange;
convertToColName(30, row_s);
convertToColName(50, row_e);
convertToColName(10, col_s);
convertToColName(100, col_e);
targetRange= col_s + row_s + ":" + col_e + row_e ;

QAxObject* sheet = workBook->querySubObject("WorkSheets(int)", 1);//获取工作表集合的工作表1,即sheet1

QAxObject* usedRange = sheet->querySubObject("Range(const QString)", target);
usedRange->setProperty("NumberFormat", "@");    //  设置所有单元格为文本属性
usedRange->dynamicCall("SetValue(const QVariant&", QVariant(data_total));
workBook->dynamicCall("Save()");	// 保存文件
delete usedRange;

3.8. 退出操作

  当执行完所有操作后,需要关闭并退出 Excel,代码如下:

workBook->dynamicCall("Close()"); //关闭工作簿 
excel->dynamicCall("Quit()"); //退出进程

delete excel;

4. 示例演示

  下面是笔者写的一个简单的 Excel 表操作的代码,其功能包含
1.打开并读取 Excel 表内容;
2.根据指定表格中数据的范围计算范围内数据量并写入表格;
3.根据数据量计算数据的所在范围。

完成工程下载链接:ExcelProcess.zip

文件列表如下:

在这里插入图片描述

运行效果演示。
在这里插入图片描述

5. 附

这里贴出所有源文件的代码:

5.1. ExcelPrecess.pro

QT       += core gui axcontainer

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17
RC_ICONS += pic/ExcelTool.ico

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    excelprocess.cpp

HEADERS += \
    excelprocess.h

FORMS += \
    excelprocess.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += \
    pic.qrc

5.2. excelprocess.h

#ifndef EXCELPROCESS_H
#define EXCELPROCESS_H

#include "ui_excelprocess.h"
#include <QMainWindow>
#include <QLineEdit>
#include <QPushButton>
#include <QString>
#include <QLabel>
#include <QFileDialog>
#include <QStandardPaths>
#include <QDebug>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>
#include <QMovie>
#include <QScopedPointer>
#include <QList>
#include <QAxObject>
#include <QVariant>
#include <QVariantList>
#include <QStandardItemModel>
#include <QThread>
#include <QIcon>

QT_BEGIN_NAMESPACE
namespace Ui { class ExcelProcess; }
QT_END_NAMESPACE

#define APPNAME ("ExcelTool v1.3.0 build 20230828")

typedef struct {
    QAxObject *excel;
    QAxObject *workBooks;
    QAxObject *current_workBook;
    QAxObject *workSheets;
    QAxObject *current_workSheet;

    QAxObject *usedRange;
    QAxObject *rows;
    QAxObject *columns;

    int sheetCount, rowCount, columnCount;


}ExcelFile;

#define MODECOUNT (3)
static QString excel_mode[MODECOUNT] = {"Null", "Calc", "Range"};

typedef struct {
    int sheet;
    int col_src;
    //int col;
    int col_dest;
} CalcMode;

class ExcelProcess : public QMainWindow
{
    Q_OBJECT

private slots:
    void showFiles(void);

    void on_PBtn_View_clicked();

    void on_ComBox_Mode_currentIndexChanged(int index);

    void on_Btn_CalcRun_clicked();

    void on_LEdit_FilePath_textChanged(const QString &arg1);

    void on_Btn_RangeRun_clicked();

protected:
    void dragEnterEvent(QDragEnterEvent *event);    // 拖动进入事件

    void dropEvent(QDropEvent *event);      // 放下事件

public:
    ExcelProcess(QWidget *parent = nullptr);
    ~ExcelProcess();

    void openExcelFile();

    void closeExcelFile();

    void readExcel_OneSheet(int sheet_num);

    void showOneSheet(int sheet_num);

    void excelModeDisplay_00(void);

    void excelModeDisplay_01(void);

    void excelModeDisplay_02(void);

    void convertToColName(int data, QString &res);

    QString to26AlphabetString(int data);

    void castListListVariant2Variant(const QList<QList<QVariant> > &cells, QVariant &res);

private:
    Ui::ExcelProcess *ui;

    QString *fileName;

    QMovie *movie_01;

    ExcelFile excel;


    QList<QList<QVariant>> xls_data;    // excel 表数据

    CalcMode calcMode;

    QStandardItemModel *tab_model;

    void initUi(void);

    void initExcel(void);

};
#endif // EXCELPROCESS_H

5.3. excelprocess.cpp

#include "excelprocess.h"
#include "ui_excelprocess.h"

void ExcelProcess::showFiles()
{
    QString str = QFileDialog::getOpenFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),"Excel 文件(*.xls *.xlsx);;All file(*.*)");
    this->ui->LEdit_FilePath->setText(str.toUtf8());
    *this->fileName = this->ui->LEdit_FilePath->text();

    qDebug() << *this->fileName << "\n";

    return ;
}

void ExcelProcess::dragEnterEvent(QDragEnterEvent *event)
{
    if ((!event->mimeData()->urls()[0].fileName().right(3).compare("xls")) || (!event->mimeData()->urls()[0].fileName().right(4).compare("xlsx"))) {
        event->acceptProposedAction();
    } else {
        event->ignore();
    }

    return ;
}

void ExcelProcess::dropEvent(QDropEvent *event)
{
    const QMimeData *qm = event->mimeData();
    *this->fileName = qm->urls()[0].toLocalFile();  // 获取拖入的文件名
    this->ui->LEdit_FilePath->clear();
    this->ui->LEdit_FilePath->setText(*this->fileName);

    return ;
}

ExcelProcess::ExcelProcess(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::ExcelProcess)
{
    ui->setupUi(this);
    this->fileName = new QString;
    this->tab_model = new QStandardItemModel();
    this->setAcceptDrops(true);     // 设置主界面接收拖动进来的文件
    this->initUi();

    this->initExcel();


    return ;
}

ExcelProcess::~ExcelProcess()
{
    delete ui;
    delete fileName;

    this->tab_model->clear();
    delete this->tab_model;

    if (this->excel.current_workBook != nullptr) {
        this->excel.current_workBook->dynamicCall("Save()");
        this->excel.current_workBook->dynamicCall("Close()"); //关闭文件
    }

    if (this->excel.workBooks != nullptr) {
        this->excel.workBooks->dynamicCall("Close()"); //关闭文件
    }


    this->excel.excel->dynamicCall("Quit(void)");   // 退出


    delete this->excel.workBooks;
    delete this->excel.excel;

    return ;
}

void ExcelProcess::openExcelFile()
{

    //this->initExcel();
    if (this->excel.excel == nullptr) {
        return ;
    }

    this->excel.workBooks->dynamicCall("Open (const QString&)", *this->fileName);
    this->excel.current_workBook = this->excel.excel->querySubObject("ActiveWorkBook");
    this->excel.workSheets = this->excel.current_workBook->querySubObject("Sheets");

    this->excel.rowCount = 0;
    this->excel.columnCount = 0;

    this->excel.sheetCount = this->excel.workSheets->property("Count").toInt();

    qDebug() << "Sheet num: " << this->excel.sheetCount << "\n";

}

void ExcelProcess::closeExcelFile()
{
    if (this->excel.current_workBook != nullptr) {
        this->excel.current_workBook->dynamicCall("Save()");
        this->excel.current_workBook->dynamicCall("Close()"); //关闭文件
    }

    if (this->excel.workBooks != nullptr) {
        this->excel.workBooks->dynamicCall("Close()"); //关闭文件
    }


    this->excel.excel->dynamicCall("Quit(void)");   // 退出


    delete this->excel.workBooks;
    delete this->excel.excel;
    this->initExcel();


    return ;
}

void ExcelProcess::readExcel_OneSheet(int sheet_num)
{
    if (sheet_num > this->excel.sheetCount) {
        return;
    }


    // 读取一个 sheet
    this->excel.current_workSheet = this->excel.current_workBook->querySubObject("Sheets(int)", sheet_num);
    this->excel.usedRange = this->excel.current_workSheet->querySubObject("UsedRange");

    if (nullptr == this->excel.usedRange || this->excel.usedRange->isNull()) {
        return;
    }


    QVariant var = this->excel.usedRange->dynamicCall("Value");
    delete this->excel.usedRange;
    this->excel.usedRange = nullptr;


    // 读取一个 sheet 结束
    for (int i = 0; i < this->xls_data.count(); i++) {
        this->xls_data.value(i).clear();
    }

    this->xls_data.clear();

    QVariantList varRows = var.toList();
    if (varRows.isEmpty()) {
        return;
    }

    const int rowCount = varRows.size();
    this->excel.rowCount = rowCount;


    QVariantList rowData;

    for (int i = 0; i < rowCount; i++){
        rowData = varRows[i].toList();
        if (rowData.count() > this->excel.columnCount) {
            this->excel.columnCount = rowData.count();
        }
        this->xls_data.push_back(rowData);
    }

    //this->excel.current_workBook->dynamicCall("Close()");
    qDebug() << "Sheet:: row:" << this->excel.rowCount << "colum:" << this->excel.columnCount << "\n";

    this->ui->ComBox_Sheet->clear();
    for (int i = 1; i <= this->excel.sheetCount; i++) {
        this->ui->ComBox_Sheet->addItem(QString::number(i));
    }

    this->ui->ComBox_Row->clear();
    for (int i = 1; i <= this->excel.rowCount; i++) {
        this->ui->ComBox_Row->addItem(QString::number(i));
    }

    this->ui->ComBox_Column->clear();
    for (int i = 1; i <= this->excel.columnCount; i++) {
        this->ui->ComBox_Column->addItem(QString::number(i));
    }

}

void ExcelProcess::showOneSheet(int sheet_num)
{
    this->readExcel_OneSheet(sheet_num);



    this->tab_model->clear();
    for (int i = 0; i < this->xls_data.count(); i++) {
        for (int j = 0; j < this->xls_data.at(i).count(); j++) {
            QStandardItem *item = new QStandardItem(QString(this->xls_data.at(i).at(j).toByteArray()));
            this->tab_model->setItem(i, j, item);

            //delete item;
        }
    }

    this->ui->TbleView_table1->setModel(this->tab_model);
    //this->ui->TbleView_table1->setSectionResizeMode(QHeaderView::Stretch);
    //delete model;
}

void ExcelProcess::excelModeDisplay_00()
{
    this->ui->Lab_Row->setText("Row:");
    this->ui->Lab_Column->setText("Row:");

    this->ui->ComBox_Column->clear();

    for (int i = 1; i <= this->excel.columnCount; i++) {
        this->ui->ComBox_Column->addItem(QString::number(i));
    }

    this->ui->TbleView_table1->show();
    this->ui->Lab_Sheet->hide();
    this->ui->Lab_Row->hide();
    this->ui->Lab_Column->hide();
    this->ui->ComBox_Sheet->hide();
    this->ui->ComBox_Row->hide();
    this->ui->ComBox_Column->hide();
    this->ui->Btn_CalcRun->hide();
    this->ui->Btn_RangeRun->hide();

    this->ui->ComBox_Mode->setCurrentIndex(0);
}

void ExcelProcess::excelModeDisplay_01()
{

    this->ui->Lab_Row->setText("Col_s:");
    this->ui->Lab_Column->setText("Col_d:");
    this->ui->ComBox_Mode->setCurrentIndex(1);

    this->ui->ComBox_Row->clear();
    this->ui->ComBox_Column->clear();

    for (int i = 1; i <= this->excel.columnCount; i++) {
        this->ui->ComBox_Row->addItem(QString::number(i));
    }

    for (int i = 1; i <= this->excel.columnCount + 1; i++) {
        this->ui->ComBox_Column->addItem(QString::number(i));
    }

    this->ui->ComBox_Column->setCurrentIndex(this->ui->ComBox_Column->count() - 1);

    this->ui->Lab_Sheet->show();
    this->ui->Lab_Row->show();
    this->ui->Lab_Column->show();
    this->ui->TbleView_table1->show();
    this->ui->ComBox_Sheet->show();
    this->ui->ComBox_Row->show();
    this->ui->ComBox_Column->show();
    this->ui->Btn_CalcRun->show();
    this->ui->Btn_RangeRun->hide();
}

void ExcelProcess::excelModeDisplay_02()
{
    this->ui->Lab_Row->setText("Col_s:");
    this->ui->Lab_Column->setText("Col_d:");
    this->ui->ComBox_Mode->setCurrentIndex(2);

    this->ui->ComBox_Row->clear();
    this->ui->ComBox_Column->clear();

    for (int i = 1; i <= this->excel.columnCount; i++) {
        this->ui->ComBox_Row->addItem(QString::number(i));
    }

    for (int i = 1; i <= this->excel.columnCount + 1; i++) {
        this->ui->ComBox_Column->addItem(QString::number(i));
    }

    this->ui->ComBox_Column->setCurrentIndex(this->ui->ComBox_Column->count() - 1);

    this->ui->Lab_Sheet->show();
    this->ui->Lab_Row->show();
    this->ui->Lab_Column->show();
    this->ui->TbleView_table1->show();
    this->ui->ComBox_Sheet->show();
    this->ui->ComBox_Row->show();
    this->ui->ComBox_Column->show();
    this->ui->Btn_CalcRun->hide();
    this->ui->Btn_RangeRun->show();
}

void ExcelProcess::convertToColName(int data, QString &res)
{
    Q_ASSERT(data>0 && data<65535);
    int tempData = data / 26;
    if(tempData > 0) {
        int mode = data % 26;
        convertToColName(mode,res);
        convertToColName(tempData,res);
    } else {
        res=(to26AlphabetString(data)+res);
    }
}

QString ExcelProcess::to26AlphabetString(int data)
{
    QChar ch = (QChar)(data + 0x40);//A对应0x41
    return QString(ch);
}

void ExcelProcess::castListListVariant2Variant(const QList<QList<QVariant> > &cells, QVariant &res)
{
    QVariantList vars;
    const int rows = cells.size();      //获取行数
    for(int i = 0; i < rows; ++i)
    {
        vars.append(QVariant(cells[i]));    //将list(i)添加到QVariantList中 QVariant(cells[i])强制转换
    }
    res = QVariant(vars);   //强制转换
}

void ExcelProcess::initUi()
{
    this->setWindowTitle(APPNAME);
    this->setWindowIcon(QIcon(":/bk/pic/ExcelTool.ico"));
    this->ui->Lab_FilePath->setText("File Path:");
    this->ui->PBtn_View->setText("Open File");
    //this->ui->Lab_BottomBar->setText("");

    this->ui->Lab_Background->setText("");

    movie_01 = new QMovie(":/bk/pic/bk_01.gif");
    this->ui->Lab_Background->setGeometry(0, 0, 700, 500);
    this->ui->Lab_Background->setMovie(movie_01);
    movie_01->setScaledSize(this->ui->Lab_Background->size());
    movie_01->start();

    this->ui->Lab_Sheet->hide();
    this->ui->Lab_Row->hide();
    this->ui->Lab_Column->hide();
    this->ui->ComBox_Sheet->hide();
    this->ui->ComBox_Row->hide();
    this->ui->ComBox_Column->hide();
    this->ui->Lab_Mode->hide();
    this->ui->ComBox_Mode->hide();
    this->ui->Btn_CalcRun->hide();
    this->ui->Btn_RangeRun->hide();


    for (int i = 0; i < MODECOUNT; i++) {
        this->ui->ComBox_Mode->addItem(excel_mode[i]);
    }
    this->ui->ComBox_Mode->setCurrentIndex(0);
    this->ui->TbleView_table1->hide();



    return ;

}

void ExcelProcess::initExcel()
{
    this->excel.excel = new QAxObject("Excel.Application");   // 加载 excel 驱动
    this->excel.excel->setProperty("Visible", false);//不显示Excel界面,如果为true会看到启动的Excel界面
    //this->excel.excel->setProperty("Visible", true);
    this->excel.workBooks = this->excel.excel->querySubObject("WorkBooks");
}



void ExcelProcess::on_PBtn_View_clicked()
{
    *this->fileName = this->ui->LEdit_FilePath->text();
    if ((0 == this->fileName->right(3).compare("xls")) || (0 == this->fileName->right(4).compare("xlsx")) || this->fileName->isEmpty()) {
        ;
    } else {
        this->movie_01->stop();
        this->movie_01->setFileName(":/bk/pic/bk_04.gif");
        this->ui->Lab_Background->setMovie(movie_01);
        movie_01->setScaledSize(this->ui->Lab_Background->size());
        movie_01->start();

        return ;
    }

    if ("Done" == this->ui->PBtn_View->text()) {
        //QThread::usleep(5);
        this->ui->LEdit_FilePath->setEnabled(true);
        this->ui->PBtn_View->setText("Open File");
        this->tab_model->clear();


        this->ui->Lab_Sheet->hide();
        this->ui->Lab_Row->hide();
        this->ui->Lab_Column->hide();
        this->ui->ComBox_Sheet->hide();
        this->ui->ComBox_Row->hide();
        this->ui->ComBox_Column->hide();
        this->ui->Lab_Mode->hide();
        this->ui->ComBox_Mode->hide();
        this->ui->Btn_CalcRun->hide();
        this->ui->Btn_RangeRun->hide();
        this->ui->TbleView_table1->hide();
        this->movie_01->stop();
        this->movie_01->setFileName(":/bk/pic/bk_01.gif");
        this->ui->Lab_Background->setMovie(movie_01);
        movie_01->setScaledSize(this->ui->Lab_Background->size());
        movie_01->start();
        this->closeExcelFile();


    } else {
        if (this->ui->LEdit_FilePath->text().isEmpty()) {
            this->showFiles();
        } else {
            //QThread::usleep(5);
            this->excelModeDisplay_00();
            this->ui->LEdit_FilePath->setEnabled(false);
            this->ui->PBtn_View->setText("Done");
            this->movie_01->stop();
            this->movie_01->setFileName(":/bk/pic/bk_02.gif");
            this->ui->Lab_Background->setMovie(movie_01);
            movie_01->setScaledSize(this->ui->Lab_Background->size());
            movie_01->start();

            this->openExcelFile();
            this->showOneSheet(1);
            this->ui->TbleView_table1->setStyleSheet("background-color:transparent");
            this->ui->TbleView_table1->horizontalHeader()->setStyleSheet("QHeaderView::section{background:transparent},QHeaderView::Stretch");
            this->ui->TbleView_table1->verticalHeader()->setStyleSheet("QHeaderView::section{background:transparent}");

            this->ui->TbleView_table1->setCornerButtonEnabled(false);

            this->ui->Lab_Mode->show();
            this->ui->ComBox_Mode->show();
            this->ui->TbleView_table1->show();
        }

    }

}


void ExcelProcess::on_ComBox_Mode_currentIndexChanged(int index)
{
    switch(index) {
    case 0: {
        this->excelModeDisplay_00();
        break;
    }
    case 1: {
        this->excelModeDisplay_01();
        break;
    }
    case 2: {
        this->excelModeDisplay_02();
        break;
    }
    default: {
        break;
    }
    }

    return ;
}


void ExcelProcess::on_Btn_CalcRun_clicked()
{
    this->calcMode.sheet = this->ui->ComBox_Sheet->currentText().toInt();
    this->calcMode.col_src = this->ui->ComBox_Row->currentText().toInt();
    this->calcMode.col_dest = this->ui->ComBox_Column->currentText().toInt();

    QString data, num1, num2, result;

    qDebug() << "Sheet::" << this->calcMode.sheet;


    this->showOneSheet(this->calcMode.sheet);

    QList<QVariant> data_total;

    for (int i = 0; i < this->excel.rowCount; i++) {
        data = this->xls_data.at(i).at(this->calcMode.col_src - 1).toByteArray();
        bool flag = true;
        num1.clear();
        num2.clear();
        for (int i_d = 0; i_d < data.length(); i_d++) {
            if ('-' == data.at(i_d)) {
                flag = false;
                continue;
            }
            if (flag) {
                num1 += data.at(i_d);
            } else {
                num2 += data.at(i_d);
            }
        }

        QList<QVariant> data_row;

        result = QString::number(num2.toInt() - num1.toInt());

        qDebug() << "num1:" << num1 << "num2:" << num2 << "res:" << result << "\n";

        data_row.append(QString::number(num2.toInt() - num1.toInt() + 1));
        data_total.append(QVariant(data_row));


    }

    QString col_num, target;
    this->convertToColName(this->calcMode.col_dest, col_num);
    qDebug() << "Col:" << col_num << "\n";

    target = col_num + "1:" + col_num + QString::number(this->excel.rowCount);
    qDebug() << target ;
    this->excel.current_workSheet = this->excel.current_workBook->querySubObject("Sheets(int)", this->calcMode.sheet);
    this->excel.usedRange = this->excel.current_workSheet->querySubObject("Range(const QString)", target);
    this->excel.usedRange->setProperty("NumberFormat", "@");    //  设置所有单元格为文本属性
    this->excel.usedRange->dynamicCall("SetValue(const QVariant&", QVariant(data_total));
    this->excel.current_workBook->dynamicCall("Save()");
    //this->excel.current_workBook->dynamicCall("Close()");
    this->showOneSheet(this->calcMode.sheet);
    delete this->excel.usedRange;


}


void ExcelProcess::on_LEdit_FilePath_textChanged(const QString &arg1)
{
    if (arg1.isEmpty()) {
        this->movie_01->stop();
        this->movie_01->setFileName(":/bk/pic/bk_01.gif");
        this->ui->Lab_Background->setMovie(movie_01);
        movie_01->setScaledSize(this->ui->Lab_Background->size());
        movie_01->start();

        *this->fileName = "";
    } else if ((0 == arg1.right(3).compare("xls")) || (0 == arg1.right(4).compare("xlsx"))) {
        this->movie_01->stop();
        this->movie_01->setFileName(":/bk/pic/bk_03.gif");
        this->ui->Lab_Background->setMovie(movie_01);
        movie_01->setScaledSize(this->ui->Lab_Background->size());
        movie_01->start();

        *this->fileName = this->ui->LEdit_FilePath->text();
    } else {
        this->movie_01->stop();
        this->movie_01->setFileName(":/bk/pic/bk_04.gif");
        this->ui->Lab_Background->setMovie(movie_01);
        movie_01->setScaledSize(this->ui->Lab_Background->size());
        movie_01->start();
    }

    return ;
}


void ExcelProcess::on_Btn_RangeRun_clicked()
{
    this->calcMode.sheet = this->ui->ComBox_Sheet->currentText().toInt();
    this->calcMode.col_src = this->ui->ComBox_Row->currentText().toInt();
    this->calcMode.col_dest = this->ui->ComBox_Column->currentText().toInt();

    QString data;
    int num_src = 0, num1 = 0, num2 = 0;

    qDebug() << "Sheet::" << this->calcMode.sheet;


    this->showOneSheet(this->calcMode.sheet);

    QList<QVariant> data_total;

    for (int i = 0; i < this->excel.rowCount; i++) {
        data = this->xls_data.at(i).at(this->calcMode.col_src - 1).toByteArray();

        num_src = data.toInt();
        num1 = num2 + 1;
        num2 = num_src + num1 - 1;

        QList<QVariant> data_row;


        qDebug() << "src:" << num_src << "num1:" << num1 << "num2:" << num2 << "\n";
        qDebug() << "range:" << (QString::number(num1) + "-" + QString::number(num2)) << "\n";

        data_row.append(QString::number(num1) + "-" + QString::number(num2));
        data_total.append(QVariant(data_row));


    }

    QString col_num, target;
    this->convertToColName(this->calcMode.col_dest, col_num);
    qDebug() << "Col:" << col_num << "\n";

    target = col_num + "1:" + col_num + QString::number(this->excel.rowCount);
    qDebug() << target ;
    this->excel.current_workSheet = this->excel.current_workBook->querySubObject("Sheets(int)", this->calcMode.sheet);
    this->excel.usedRange = this->excel.current_workSheet->querySubObject("Range(const QString)", target);
    this->excel.usedRange->setProperty("NumberFormat", "@");    //  设置所有单元格为文本属性
    this->excel.usedRange->dynamicCall("SetValue(const QVariant&", QVariant(data_total));
    this->excel.current_workBook->dynamicCall("Save()");
    //this->excel.current_workBook->dynamicCall("Close()");
    this->showOneSheet(this->calcMode.sheet);
    delete this->excel.usedRange;

}

5.4. main.cpp

#include "excelprocess.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    ExcelProcess w;
    w.show();
    return a.exec();
}

5.5. excelprocess.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>ExcelProcess</class>
 <widget class="QMainWindow" name="ExcelProcess">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>700</width>
    <height>500</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>ExcelProcess</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QLineEdit" name="LEdit_FilePath">
    <property name="geometry">
     <rect>
      <x>80</x>
      <y>420</y>
      <width>490</width>
      <height>24</height>
     </rect>
    </property>
   </widget>
   <widget class="QPushButton" name="PBtn_View">
    <property name="geometry">
     <rect>
      <x>590</x>
      <y>417</y>
      <width>80</width>
      <height>30</height>
     </rect>
    </property>
    <property name="text">
     <string>Open File</string>
    </property>
   </widget>
   <widget class="QLabel" name="Lab_FilePath">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>420</y>
      <width>60</width>
      <height>24</height>
     </rect>
    </property>
    <property name="text">
     <string>File Path:</string>
    </property>
   </widget>
   <widget class="QLabel" name="Lab_Background">
    <property name="geometry">
     <rect>
      <x>700</x>
      <y>500</y>
      <width>53</width>
      <height>16</height>
     </rect>
    </property>
    <property name="text">
     <string>TextLabel</string>
    </property>
   </widget>
   <widget class="QTableView" name="TbleView_table1">
    <property name="geometry">
     <rect>
      <x>19</x>
      <y>280</y>
      <width>531</width>
      <height>100</height>
     </rect>
    </property>
   </widget>
   <widget class="QComboBox" name="ComBox_Sheet">
    <property name="geometry">
     <rect>
      <x>80</x>
      <y>390</y>
      <width>60</width>
      <height>24</height>
     </rect>
    </property>
   </widget>
   <widget class="QLabel" name="Lab_Sheet">
    <property name="geometry">
     <rect>
      <x>30</x>
      <y>390</y>
      <width>50</width>
      <height>24</height>
     </rect>
    </property>
    <property name="text">
     <string>Sheet:</string>
    </property>
   </widget>
   <widget class="QLabel" name="Lab_Row">
    <property name="geometry">
     <rect>
      <x>170</x>
      <y>390</y>
      <width>50</width>
      <height>24</height>
     </rect>
    </property>
    <property name="text">
     <string>Row_s:</string>
    </property>
   </widget>
   <widget class="QComboBox" name="ComBox_Row">
    <property name="geometry">
     <rect>
      <x>220</x>
      <y>390</y>
      <width>50</width>
      <height>24</height>
     </rect>
    </property>
   </widget>
   <widget class="QLabel" name="Lab_Column">
    <property name="geometry">
     <rect>
      <x>280</x>
      <y>390</y>
      <width>50</width>
      <height>24</height>
     </rect>
    </property>
    <property name="text">
     <string>Col_d:</string>
    </property>
   </widget>
   <widget class="QComboBox" name="ComBox_Column">
    <property name="geometry">
     <rect>
      <x>330</x>
      <y>390</y>
      <width>50</width>
      <height>24</height>
     </rect>
    </property>
   </widget>
   <widget class="QComboBox" name="ComBox_Mode">
    <property name="geometry">
     <rect>
      <x>620</x>
      <y>280</y>
      <width>70</width>
      <height>24</height>
     </rect>
    </property>
   </widget>
   <widget class="QLabel" name="Lab_Mode">
    <property name="geometry">
     <rect>
      <x>565</x>
      <y>280</y>
      <width>50</width>
      <height>24</height>
     </rect>
    </property>
    <property name="text">
     <string>Mode:</string>
    </property>
   </widget>
   <widget class="QPushButton" name="Btn_CalcRun">
    <property name="geometry">
     <rect>
      <x>620</x>
      <y>350</y>
      <width>70</width>
      <height>30</height>
     </rect>
    </property>
    <property name="text">
     <string>Run</string>
    </property>
   </widget>
   <widget class="QPushButton" name="Btn_RangeRun">
    <property name="geometry">
     <rect>
      <x>620</x>
      <y>350</y>
      <width>70</width>
      <height>30</height>
     </rect>
    </property>
    <property name="text">
     <string>Run</string>
    </property>
   </widget>
   <zorder>Lab_Background</zorder>
   <zorder>Lab_FilePath</zorder>
   <zorder>PBtn_View</zorder>
   <zorder>LEdit_FilePath</zorder>
   <zorder>TbleView_table1</zorder>
   <zorder>ComBox_Sheet</zorder>
   <zorder>Lab_Sheet</zorder>
   <zorder>Lab_Row</zorder>
   <zorder>ComBox_Row</zorder>
   <zorder>Lab_Column</zorder>
   <zorder>ComBox_Column</zorder>
   <zorder>ComBox_Mode</zorder>
   <zorder>Lab_Mode</zorder>
   <zorder>Btn_CalcRun</zorder>
   <zorder>Btn_RangeRun</zorder>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>700</width>
     <height>26</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

#完

qt操作excel(QAxObject详细介绍) 阅读详情

相关推荐

QT操作Excel

在 Qt 程序中操作 Excel 文件的常用方法有QAxObject、QtXlsx开源库、CSV格式等。使用 QAxObject (仅限 Windows,需安装 Excel) 2、读取数据(每个单元格) 3、批量读取数据(N个单元格) 4、写入数据 5、高级功能 1)插入单张图片 1.1)通过 Shapes.AddPicture 方法插入图片,需指定坐标、尺寸和链接方式‌。 坐标可通过单元格的 Left 和 Top 属性动态获取‌。 1.2)动态调整图片位置和大小

深之JohnChen的专栏 2563

QAxObject写Excel(详解)

QAxObject写Excel相关函数使用说明,较为完整的代码示例。实战方面的注意事项以及一些常见问题的解决方案

qq_39071305的博客 7355

Qt高效读写Excel:QAxObject与QTableWidget实战方案

桌面软件开发中,表格数据的导入导出是高频需求,尤其在Qt环境下构建数据管理工具时,如何高效处理Excel文件成为开发者关注的焦点。Excel文件的读写本质上是与应用程序的交互过程,通过COM组件可以直接驱动本机Office程序,实现对工作簿、工作表及单元格的灵活操作,这正是QAxObject的核心原理。相比传统逐格读写,利用COM接口的批量赋值特性可大幅提升性能,配合QTableWidget的数据展示与管理能力,能构建出稳定高效的导入导出流程。该方案适用于Windows平台的Qt上位机、桌面工具等场景,兼顾

weixin_34233974的博客 291

Qt之初识 QAxObject (附打印预览demo)

项目需要界面上加一个将表格数据保存至本地,存成excel.和打印预览。查了网上一些资料。发现有两种方法。 1. (.pro)工程文件中加入 “QT+= printsupport” 使用QPrinter和QprintDialog类。 2. (.pro)工程文件中加入 “QT+= axcontainer” 使用QAxObject 因为使用的是第二种,所以第一种方式只是做个记录,哪天...

qq_22328661的博客 8680

使用Qt与QXlsx/QAxObject进行高效Excel数据处理

Qt是一个跨平台的应用程序和用户界面框架,广泛应用于开发图形界面应用程序。它使用C++编写,并提供了一系列工具和库来简化跨平台开发过程。Qt框架的特点是其高度的模块化和丰富的API,这使得开发者可以方便地构建各种类型的应用程序。组件对象模型(Component Object Model,COM)是一种面向对象的编程架构,它允许在不同语言和不同进程中进行对象之间的通信。Qt通过QAxObject类封装了COM技术,使得开发者可以使用Qt来创建和控制ActiveX控件,并与Windows应用程序进行交互。

weixin_30356433的博客 452

QT读取excel,使用QAxObject

使用QAxObject读取excel,克服了空白单元格也会读取进去的问题,将读取结果显示到ui界面上,需手动在ui界面添加一下QLineEdit。如果想显示到其他控件上,修改控件名字即可。

【Qt】Qt使用QAxObject批量读写Excel

Qt使用QAxObject打开Excel、读写单个单元格、批量读写、文件保存、文件关闭代码示例。

huanqing2010的专栏 5824

EDKII实战:手把手调试PciHostBridge.c,看UEFI如何分配你的PCIe设备资源(IO/Memory空间)

本文深入解析EDKII中PciHostBridge.c模块的工作原理,详细指导如何调试PCIe设备资源分配(IO/Memory空间)。通过实战案例展示UEFI环境下Root Bridge初始化、地址空间转换及协议安装等核心流程,提供常见问题排查方法与性能优化建议,帮助开发者解决PCIe设备兼容性问题。

weixin_29201933的博客 213

Qt 快速读写Excel指南

Qt 快速读写Excel指南

m0_73443478的博客 8270

C8T6和ZET6选型更换过程中出现.\Obj\Project.sct(7): error: L6235E: More than one section matches selector - cann

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录前言一、问题原因二、解决方法三、现象总结 前言 又一件离谱的事情发生了,我之前转换过程中没有发生的错误,今天拿出来程序重新编译了一下,结果他奶奶滴一个新的错误出现了,而且我还完全不知道是什么原因导致的,先上图: 一、问题原因 之前我已经尝试过更换芯片选型,但是没有出现此类问题,今天更改的时候发现了,我还以为是个偶然错误,结果换来换去,还是有这个问题,那我之前说c8t6的程序更改成zet6上跑只需改芯片选型和宏定义岂不是啪啪打.

wx18045623090的博客 1496

双向全桥隔离DC-DC变换器(DAB)的调制优化与挑战解析

本文深入解析了双向全桥隔离DC-DC变换器(DAB)的核心调制技术及其面临的挑战。文章从基础的相移调制(SPS)入手,逐步探讨了扩展相移(EPS)、双重相移(DPS)等进阶策略,并重点分析了电流优化与零电压开通(ZVS)等硬核优化技巧。针对DAB在实际应用中存在的建模困难、多模块并联及数字实现等挑战,提供了实用的应对策略与设计思路,旨在帮助工程师在性能、复杂度与成本之间找到最佳平衡。

weixin_29271053的博客 581

Qt使用QAxObject写入Excel表格,包括填色、合并单元格、多行写入等

Qt使用QAxObject写入Excel表格,包括填色、合并单元格、多行写入等。

qq_23604781的博客 7391

liquibase扩展支持达梦数据库

近期项目中需要支持国产数据库,需要liquibase底层支持达梦数据库,记录下操作的详细步骤以便分享。 1.liquibase支持的数据库很多如MySQL, PostgreSQL, Oracle, Sql Server, DB2。但是达梦数据库并不支持,所以需要新建DMDatabase类来适配达梦数据库。达梦语法和Oracle很像所以只需要复制liquibase-core下的Oracle Database做些修改就可了。以下为需要修改的地方 public class DMDatabase extends A

qq_43677719的博客 5480

qt5 使用qtxlsx 读写excel

(1)开源项目下载地址:https://github.com/dbzhang800/QtXlsxWriter (2)建立pro TARGET = QtXlsx TEMPLATE = lib CONFIG += staticlib QT += core gui gui-private HEADERS += xlsxdocpropscore_p.h \ xlsxdocpropsapp...

乌托邦 6922

AFSim 2.9实战指南:从入门到精通的中文教程

本文是AFSim 2.9的实战中文教程,旨在帮助用户从零开始掌握这一先进的仿真框架。内容涵盖从环境安装、运行第一个“Hello World”仿真,到深入理解实体、组件、想定编辑器等核心概念,并进阶探讨动力学建模、传感器仿真与红蓝对抗想定构建。最后,指南还提供了效能分析与实战排错技巧,帮助用户将仿真结果转化为有价值的量化数据,适用于军事、航空航天等领域的复杂系统行为模拟研究。

weixin_29294395的博客 367

大疆2025八月份校招硬件工程师笔试真题A卷题目分享

大疆2025年笔试真题解析

weixin_63651698的博客 1576

Qt读写Excel文件(QAxObject)

Qt读写Excel文件(QAxObject)

VectorAL的博客 7282

Kali Linux实战:5分钟复现永恒之蓝漏洞攻击(附Win7靶机配置指南)

本文提供了一份详细的Kali Linux实战指南,指导读者在5分钟内于隔离的虚拟环境中复现经典的永恒之蓝漏洞攻击。内容涵盖从Windows 7靶机配置、网络设置,到使用Nmap进行服务发现、利用Metasploit框架进行漏洞扫描与利用的全过程,并演示了基础的Meterpreter后渗透操作,旨在帮助网络安全学习者通过亲手实践深入理解SMB协议漏洞的攻防原理。

weixin_29313547的博客 201

Qt 下快速读写Excel指南

Qt Windows 下快速读写Excel指南很多人搜如何读写excel都会看到用QAxObject来进行操作,很多人试了之后都会发现一个问题,就是慢,非常缓慢!因此很多人得出结论是QAxObject读写excel方法不可取,效率低。 后来我曾试过用ODBC等数据库类型的接口进行读写,遇到中文嗝屁不说,超大的excel还是会读取速度慢。 最后,看了一些开源的代码后发现,Windows下读取exc

尘中远的程序开发记录 6万+

【ESP32摄像头开发实例】-视频流接入Home Assistant

在这个项目中,我们将使用ESP32-CAM板构建一个IP监控摄像头。ESP32摄像头将托管一个视频流媒体网络服务器,您可以使用网络中的任何设备进行访问。

视觉与物联智能 802

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Windows Qt5下用QAxObject快速读写Excel指南

转自:https://blog.csdn.net/u013541325/article/details/102511490 Qt Windows 下快速读写Excel指南 很多人搜如何读写excel都会看到用QAxObject来进行操作,很多人试了之后都会发现一个问题,就是慢,非常缓慢!因此很多人得出结论是QAxObject读写excel方法不可取,效率低。 后来我曾试过用ODBC等数据库类型的接口进行读写,遇到中文嗝屁不说,超大的excel还是会读取速度慢。 最后,看了一些开源的代码后发现,Win..

qqwangfan的专栏 799

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Qt之QAxObject读写Excel教程:开启高效数据处理新篇章

Qt之QAxObject读写Excel教程:开启高效数据处理新篇章 去发现同类优质开源项目:https://gitcode.com/ 项目介绍 在当代软件开发领域,数据处理能力的重要性不言而喻。Qt之QAxObject读写Excel教程,是一个专注于教授开发者如何利用Qt框架中的QAxObject类,实现与Excel文件高效交互的开源项目。该项目通过详细的实例和代码解析,帮助开发者掌握读取、写入及...

gitblog_06763的博客 468

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

【QT教程】QT5+VS2017 绘制曲线(QCustomPlot) 及 EXCEL的快速读取和写入(QAxObject)

本篇文章对一下几点进行了总结 1.利用QCustomPlot绘制曲线的基本操作 2.利用QAxObject对excel文件进行读取、写入操作 3.比较了QT对Excel文件快速和慢速读写方法的异同 4.总结了一些常见坑爹地方

天才小傲傲的博客 8164

轻松实现Qt与Excel的无缝对接:Qt读写Excel的Demo推荐

轻松实现Qt与Excel的无缝对接:Qt读写Excel的Demo推荐 【下载地址】Qt读写Excel的Demo 本仓库提供了一个基于Qt的读写Excel的示例代码,展示了如何使用`QAxObject`在Qt中访问Excel文件。通过这个Demo,你可以轻松实现Excel表的导出和导入功能。为了方便使用,我们将Excel访...

gitblog_09762的博客 962

Qt5 QAxObject实现Excel读写与报表导出实践

在Windows桌面开发中,Excel报表导出与配置表读取常涉及COM/ActiveX跨进程调用。QAxObject作为Qt5的QtAxContainer模块组件,通过IDispatch桥接Excel对象模型,将C++调用转换为对Application、Workbook、Worksheet、Range的操作,从而复用Excel的公式、样式与格式能力。其技术价值在于减少对纯C++ xlsx解析库的依赖,统一处理Excel读写、中文路径和批量数据提交;在报表生成、配置维护、数据回填等场景中可提升开发效率与交付稳

weixin_29174141的博客 331
上一篇: Gif 动图制作工具——ScreenToGif
下一篇: CentOS Stream9 安装远程桌面服务 Xrdp
Imagine Miracle
Imagine Miracle 领域专家: 操作系统技术领域 领域专家: 操作系统技术领域
博客等级 码龄10年 5万+粉丝 190原创
评论 9
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Imagine Miracle

爱你哟 =^ v ^=

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值