精华内容
下载资源
问答
  • QAxobject
    2021-05-18 16:34:26

    原文地址::https://blog.csdn.net/u010304326/article/details/82292195?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.control

    相关文章

    1、Qt5生成Word格式报告----https://blog.csdn.net/lm409/article/details/77965130?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-11.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-11.control

    2、QT word文档操作实例----https://blog.csdn.net/qq_35192280/article/details/83021975?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control

    3、使用QAxObject操作Word.docx----https://download.csdn.net/download/qq_16659823/12011266?utm_medium=distribute.pc_relevant_t0.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-download-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control

    4、2.QT中操作word文档----https://blog.csdn.net/tototuzuoquan/article/details/42001923?utm_medium=distribute.pc_relevant_download.none-task-blog-baidujs-2.nonecase&depth_1-utm_source=distribute.pc_relevant_download.none-task-blog-baidujs-2.nonecase

     

    因为最近项中需要生成报表,所以网上查了资料,因为VB看不懂所以总结的也不多,在实现中没有使用标签只是以光标的位置来插入,包括:创建文件,排版方式,添加文字,添加图片,添加表格,表格添加文字(图片),光标移动到尾部,光标跳转(类似tab)等

    添加 QT += axcontainer

    QAxObject *m_pWord;      //指向整个Word应用程序
    QAxObject *m_pWorkDocuments;  //指向文档集,Word有很多文档
    QAxObject *m_pWorkDocument;   //指向m_sFile对应的文档,就是要操作的文档

    /*
        创建word
    */

    void MainWindow::open()
    {
        m_pWord = new QAxObject();
        bool flag = m_pWord->setControl( "Word.Application" );
        if(!flag)
        {
            return;
        }
        m_pWord->setProperty("Visible", true);

        QAxObject *document = m_pWord->querySubObject("Documents");
        if(!document)
        {
            return ;
        }

        //获取当前激活的文档
        m_pWorkDocument = m_pWord->querySubObject("ActiveDocument");
    }

    /*
     * 排版方式
     * 纵行、横行
    */

    void MainWindow::setype(bool type)
    {
        QAxObject* selection = m_pWord->querySubObject("Selection");
        if(!selection)
        {
            return;
        }
        if(type)
        {
            selection->querySubObject("PageSetup")->setProperty("Orientation","wdOrientLandscape");
        }else{
            selection->querySubObject("PageSetup")->setProperty("Orientation","wdOrientPortrait");
        }
    }

    /*
     * 获取页宽
    */

    int MainWindow::pageWidth()
    {
        int width;
        QAxObject* selection = m_pWord->querySubObject("Selection");
        if(!selection)
        {
            return;
        }
        width = selection->querySubObject("PageSetup")->property("PageWidth").toInt();;
        return width;
    }

    /*
    *设置字号
    */

    void MainWindow::setFontSize(int size)
    {
        QAxObject* selection = m_pWord->querySubObject("Selection");
        if(!selection)
        {
            return;
        }
        selection->querySubObject("Font")->setProperty("Size",size);
    }

    /*
       设置对齐方式
    */

    void MainWindow::setAlignment(int index)
    {
        QAxObject *selection = m_pWord->querySubObject("Selection");
        if(!selection)
        {
            return;
        }
        if(index == 0)
        {
          selection->querySubObject("ParagraphFormat")->setProperty("Alignment","wdAlignParagraphCenter");
        }
        if(index == 1)
        {
           selection->querySubObject("ParagraphFormat")->setProperty("Alignment","wdAlignParagraphJustify");
        }
        if(index == 2)
        {
           selection->querySubObject("ParagraphFormat")->setProperty("Alignment","wdAlignParagraphRight");
        }
        if(index == 3)
        {
           selection->querySubObject("ParagraphFormat")->setProperty("Alignment","wdAlignParagraphLeft");
        }
    }


    /*
       插入文字
    */

    void MainWindow::typeText(QString text)
    {
        QAxObject* selection  = m_pWord->querySubObject("Selection");
        if(!selection)
        {
            return;
        }
        selection->dynamicCall("TypeText(const QString&)",text);
    }
    /*
        插入图片
    */

    void MainWindow::AddPicture(QString file)
    {
        QAxObject* selection  = m_pWord->querySubObject("Selection");
        if(!selection)
        {
            return;
        }
        QString filename = file;
        filename.replace("/","\\");
        QAxObject *Inlineshapes = selection->querySubObject("InlineShapes");
        Inlineshapes->dynamicCall("AddPicture(const QString&)",filename);
        delete Inlineshapes;
    }

    /*
        插入回车
    */

    void MainWindow::insertEnter()
    {
        QAxObject* selection  = m_pWord->querySubObject("Selection");
        if(!selection)
        {
            return;
        }
        selection->dynamicCall("TypeParagraph(void)");
    }

    /*
     * 光标移到末尾,跳出单元格
    */
    void MainWindow::moveForEnd()
    {
        QAxObject* selection = m_pWord->querySubObject("Selection");
        QVariantList params;
        params.append(6);
        params.append(0);
        selection->dynamicCall("EndOf(QVariant&, QVariant&)", params).toInt();
    }

    /*
       创建表格
       QStringList headList 添加表头
    */

    QAxObject* MainWindow::createTable(int row, int column,QStringList headList)
    {
        QAxObject* selection  = m_pWord->querySubObject("Selection");
        if(!selection)
        {
            return false;
        }
        selection->dynamicCall("InsertAfter(QString&)", "\r\n");

        QAxObject *range = selection->querySubObject("Range");
        QAxObject *tables = m_pWorkDocument->querySubObject("Tables");
        QAxObject *table = tables->querySubObject("Add(QVariant,int,int)",range->asVariant(),row,column);

        table->setProperty("Style","网格型");
        //表格自动拉伸列 0固定  1根据内容调整  2 根据窗口调整
        table->dynamicCall("AutoFitBehavior(WdAutoFitBehavior)", 2);

        //设置表头
        for(int i=0;i<headList.size();i++)
        {
            table->querySubObject("Cell(int,int)",1,i+1)->querySubObject("Range")->dynamicCall("SetText(QString)", headList.at(i));
            //加粗
            table->querySubObject("Cell(int,int)",1,i+1)->querySubObject("Range")->dynamicCall("SetBold(int)", true);
        }
        return table;
    }

    /*
       填充表格
    */

    void MainWindow::setCellText(QAxObject *table, int row, int column, QString text)
    {
        QAxObject* range = table->querySubObject("Cell(int, int)",row+1,column+1)->querySubObject("Range");
        if( range)
        {
            return;
        }

        range->dynamicCall("SetText(QString)", text);
    }

    /*
      表格插入图片
    */
    void MainWindow::setAddPicture(QAxObject *table, int row, int column, QString picPath)
    {
        QAxObject* range = table->querySubObject("Cell(int, int)",row+1,column+1)->querySubObject("Range");
        if(!range)
        {
            return;
        }
        range->querySubObject("InlineShapes")->dynamicCall("AddPicture(const QString&)",picPath);
    }

    /*
       光标跳转,类似表格中的tab
    */

    void MainWindow::moveRight()
    {
        QAxObject* selection  = m_pWord->querySubObject("Selection");
        if(!selection)
        {
            return;
        }
        selection->dynamicCall("MoveRight(int)",1);
    }

    /*特殊样例*/

    void MainWindow::Example()
    {
        QStringList header;

        newTable(1,2,header);//创建表格

        typeText(tr("文字1"));//添加文字
        insertEnter();//换行
        insertText("");
        AddPicture("图像1");//插入图片

        moveRight();//将光标插入到下个单元格中

        typeText(tr("文字2"));
        insertEnter();
        insertText("");
        AddPicture("图像2");

        moveForEnd();//光标跳出表格

        /*然后,可以做其他操作了*/

    }
    ————————————————
    版权声明:本文为CSDN博主「洗砚」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/u010304326/article/details/82292195

     

    更多相关内容
  • 使用QAxObject读取excel,克服了空白单元格也会读取进去的问题,将读取结果显示到ui界面上,需手动在ui界面添加一下QLineEdit。如果想显示到其他控件上,修改控件名字即可。
  • 创建文件,排版方式,添加文字,添加图片,添加表格,表格添加文字(图片),光标移动到尾部,光标跳转(类似tab)等
  • Qt中利用QAxObject操作word
  • Qt QAxObject 操作Excel

    2016-05-05 17:58:26
    Qt使用QAxObject封装的COM组件的类来操作COM组件
  • QAxObject+Excel做的例程

    2020-01-17 10:00:50
    内含自己总结写的一个类,包含Excel基本操作,如打开、创建、写入、连续写入、读、连续读出、更改字体颜色、获取行与列、删除表、设置字体等操作。
  • 使用Qt 中的 QAxObject ,对Excel 进行读写操作编辑。
  • 用于清除QAxObject创建的Office进程,可以区分是外部创建的Office进程还是软件内部创建的Office进程。
  • Qt使用QAxObject写入Excel表格,包括填色、合并单元格、多行写入等。

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

    QAxObject可以调用Excel表中的各种函数或者事件,来操控读写Excel表格。
    Excel表中所有的接口可以查看官方文档
    末尾可见源码。

    第一步 明确自己需要写入的数据

    我这边的示例是写入一个二维码解码结果的表格。
    例如我有4张图片,每张图片中都有一个或多个二维码,甚至也可能没有二维码。
    我需要把解码失败的二维码标记为红色,没有二维码的图片标记为灰色。
    得到一个这样的结果。
    在这里插入图片描述

    第二步 生成数据

    数据是模拟的,随便写点数据就好。
    定义一个数据结构体。

        struct Qrcode{
            QString result;
            QString points;
            int grade;
        };
    
        struct ExcelData{
            QString fileName;
            float elapsed;
            QVector<Qrcode> qrcodes;
        };
    

    填入数据

    void Datasets::initData()
    {
        Qrcode oneQrcodeOne = getQrcodeData("第一个二维码;", "(12,34),(566,322)", 4);
        Qrcode oneQrcodeTwo = getQrcodeData("第二个二维码;", "(87,190),(200,98)", 0);
        Qrcode oneQrcodeThree = getQrcodeData("第三个二维码", "(122,41),(59,345)", 1);
        ExcelData excelDataOne = getExcelData("1.bmp", 26.5, {oneQrcodeOne, oneQrcodeTwo, oneQrcodeThree});
        excelDatas.append(excelDataOne);
    
        Qrcode twoQrcodeOne = getQrcodeData("", "(87,140),(200,98)", 0);
        ExcelData excelDataTwo = getExcelData("2.bmp", 23.7, {twoQrcodeOne});
        excelDatas.append(excelDataTwo);
    
        ExcelData excelDataThree = getExcelData("3.bmp", 33.1, {});
        excelDatas.append(excelDataThree);
    
        Qrcode fourQrcodeTwo = getQrcodeData("第一个二维码;", "(87,1901),(200,98)", 2);
        Qrcode fourQrcodeThree = getQrcodeData("第二个二维码;", "(122,41),(59,345)", 2);
        ExcelData excelDataFour = getExcelData("4.bmp", 24.9, {fourQrcodeTwo, fourQrcodeThree});
        excelDatas.append(excelDataFour);
    
        Qrcode fiveQrcodeOne = getQrcodeData("第一个二维码;", "(87,192),(200,98)", 2);
        Qrcode fiveQrcodeTwo = getQrcodeData("第二个二维码;", "(122,41),(59,345)", 2);
        Qrcode fiveQrcodeThree = getQrcodeData("第三个二维码;", "(122,41),(59,345)", 2);
        Qrcode fiveQrcodeFour = getQrcodeData("", "(87,190),(200,98)", 0);
        Qrcode fiveQrcodeFive = getQrcodeData("第四个二维码;", "(122,41),(59,345)", 2);
        ExcelData excelDataFive = getExcelData("5.bmp", 32.1, {fiveQrcodeOne, fiveQrcodeTwo, fiveQrcodeThree, fiveQrcodeFour, fiveQrcodeFive});
        excelDatas.append(excelDataFive);
    }
    

    第三步 打开/新建一个Excel表格

    bool ExcelHandle::open(QString excelPath)
    {
        this->excelPath = excelPath;
        QFileInfo fileInfo(excelPath);
    
        excel = new QAxObject("Excel.Application");
        excel->setProperty("Visible", false);
        excel->setProperty("DisplayAlerts", false); // 在save和save as时,不弹窗提示
        workBooks = excel->querySubObject("WorkBooks");
    
        if(!fileInfo.exists()){
            //!!!新建工作簿
            workBooks->querySubObject("Add");
        } else {
            //!!!打开已存在的工作簿
            workBooks->querySubObject("Open (const QString&)", QDir::toNativeSeparators(excelPath));
        }
        workBook = excel->querySubObject("ActiveWorkBook");
        if (workBook == nullptr)
            return false;
    
        //!!!获取表页对象
        workSheets = workBook->querySubObject("WorkSheets");
        workSheet = workSheets->querySubObject("Item(int)", 1);
        changeSheetName("二维码"); // 给这个表页换一个名字
    
        if(workSheets == NULL)
            return false;
        return true;
    }
    

    第四步 写入二维码数据

    填入多行数据时,需要用QList<QList>转成QVariantList,再转成QVariant。不能直接用QVariantList写入再转成QVariant格式,会导致写入数据失败。

    bool ExcelHandle::writeExcelData(QVector<Datasets::ExcelData> excelDatas)
    {
        // 先写入一个头
        QList<QVariant> header;
        header << "序号" << "图片" << "耗时" << "解码内容" << "坐标" << "等级";
        QVariant headerV = header;
        writeMulty(headerV, "A1", "F1");
        int row = 2;    // 行
        for(int i = 0; i < excelDatas.size(); i++){
            // 填入序号
            QString indexStart = QString("A%1").arg(row);
            QString indexend = QString("A%1").arg(row + qMax(excelDatas[i].qrcodes.size(),1) - 1);
            mergeCells(indexStart, indexend, QString::number(i));
            // 填入图片名
            QString imgStart = QString("B%1").arg(row);
            QString imgEnd = QString("B%1").arg(row + qMax(excelDatas[i].qrcodes.size(),1) - 1);
            mergeCells(imgStart, imgEnd, excelDatas[i].fileName);
            // 填入耗时
            QString timeStart = QString("C%1").arg(row);
            QString timeEnd = QString("C%1").arg(row + qMax(excelDatas[i].qrcodes.size(),1) - 1);
            mergeCells(timeStart, timeEnd, QString("%1ms").arg(QString::number(excelDatas[i].elapsed,'f',2)));
            // 如果没有二维码,填入灰色
            if(excelDatas[i].qrcodes.size() <= 0){
                QString colorStart = QString("A%1").arg(row);
                QString colorEnd = QString("F%1").arg(row);
                setColor(QColor(100,100,100), colorStart, colorEnd);
            }
            // 填入解码数据
            QVariantList vars;
            QList<QList<QVariant>> qrcodeList;  // 需要先用QList<QList<QVariant>>包装一次
            for(int j = 0; j < excelDatas[i].qrcodes.size(); j++){
                QList<QVariant> cells;
                cells.append(excelDatas[i].qrcodes[j].result);
                cells.append(excelDatas[i].qrcodes[j].points);
                cells.append(excelDatas[i].qrcodes[j].grade);
                qrcodeList.append(cells);
                vars.append(QVariant(qrcodeList.last()));
                // 设置颜色,解码失败为红色,没有二维码的为灰色
                if(excelDatas[i].qrcodes[j].result == ""){
                    QString colorStart = QString("D%1").arg(row+j);
                    QString colorEnd = QString("F%1").arg(row+j);
                    setColor(QColor(255,0,0), colorStart, colorEnd);
                }
            }
            QVariant result = vars;
            QString dataStart = QString("D%1").arg(row);
            QString dataEnd = QString("F%1").arg(row + qMax(excelDatas[i].qrcodes.size(),1) - 1);
            writeMulty(result, dataStart, dataEnd);
    
            row = row + qMax(excelDatas[i].qrcodes.size(),1);
        }
        setAutoFit(row);
        return true;
    }
    

    第五步 保存并退出Excel

    bool ExcelHandle::save()
    {
        if(excel == NULL || workBooks == NULL || workBook == NULL)
            return false;
        /** 保存文件 **/
        QFileInfo fileInfo(excelPath);
        if(!fileInfo.exists())
            workBook->dynamicCall("SaveAs(const QString&)", QDir::toNativeSeparators(excelPath));
        else
            workBook->dynamicCall("Save()");
    
        /** 关闭并退出文件 **/
        workBooks->dynamicCall("Close()");
        excel->dynamicCall("Quit(void)");
        delete workSheet;
        workSheet = NULL;
        delete workSheets;
        workSheets = NULL;
        delete workBook;
        workBook = NULL;
        delete workBooks;
        workBooks = NULL;
        delete excel;
        excel = NULL;
        return true;
    }
    

    合并单元格

    bool ExcelHandle::mergeCells(QString start, QString end, QString value)
    {
        if(workSheet == NULL)
            return false;
        QAxObject *range = workSheet->querySubObject("Range(const Qvariant&)", QVariant("=(" +start+ ": " +end+ ")"));
        if(range == NULL)
            return false;
    
        range->setProperty("MergeCells", true); // 合并单元格
        range->setProperty("Value", value);
        return true;
    }
    

    设置背景色

    bool ExcelHandle::setColor(QColor color, QString start, QString end)
    {
        QAxObject *range = workSheet->querySubObject("Range(const Qvariant&)", QVariant("=(" +start+ ": " +end+ ")"));
        if(range == NULL)
            return false;
        QAxObject *cells = range->querySubObject("Columns");
        QAxObject *interior = cells->querySubObject("Interior");
        interior->setProperty("Color", color);
        delete interior;
        interior = NULL;
        delete cells;
        cells = NULL;
        return true;
    }
    

    插入多行数据

    bool ExcelHandle::writeMulty(QVariant value, QString start, QString end)
    {
        if(workSheet == NULL)
            return false;
        QAxObject *range = workSheet->querySubObject("Range(const QString&)",QString("(" +start+ ": " +end+ ")"));
        range->setProperty("Value", value);
        delete range;
        range = NULL;
        return true;
    }
    

    自动设置单元格宽度

    bool ExcelHandle::setAutoFit(int lines)
    {
        if(workSheet == NULL)
            return false;
        QAxObject *range = workSheet->querySubObject("Range(const Qvariant&)", QVariant(QString("A1:F%1").arg(lines)));
        if(range == NULL)
            return false;
    
        QAxObject *cells = range->querySubObject("Columns");
        cells->dynamicCall("AutoFit");
        return true;
    }
    

    源码

    数据文件:

    #ifndef DATASETS_H
    #define DATASETS_H
    
    /** Datasets.h **/
    
    #include <QObject>
    #include <QDebug>
    
    
    #pragma execution_character_set("utf-8")
    class Datasets : public QObject
    {
        Q_OBJECT
    public:
        struct Qrcode{
            QString result;
            QString points;
            int grade;
        };
    
        struct ExcelData{
            QString fileName;
            float elapsed;
            QVector<Qrcode> qrcodes;
        };
    
    
    public:
        explicit Datasets(QObject *parent = nullptr);
        QVector<ExcelData> getData();
    
    private:
        void initData();
        Qrcode getQrcodeData(QString result, QString point, int grade);
        ExcelData getExcelData(QString fileName, float elapsed, QVector<Qrcode> qrcodes);
    
    private:
        QVector<ExcelData> excelDatas;
    
    signals:
    
    };
    
    #endif // DATASETS_H
    
    
    /** Datasets.cpp **/
    #include "Datasets.h"
    
    Datasets::Datasets(QObject *parent) : QObject(parent)
    {
        initData();
    }
    
    QVector<Datasets::ExcelData> Datasets::getData()
    {
        return excelDatas;
    }
    
    void Datasets::initData()
    {
        Qrcode oneQrcodeOne = getQrcodeData("第一个二维码;", "(12,34),(566,322)", 4);
        Qrcode oneQrcodeTwo = getQrcodeData("第二个二维码;", "(87,190),(200,98)", 0);
        Qrcode oneQrcodeThree = getQrcodeData("第三个二维码", "(122,41),(59,345)", 1);
        ExcelData excelDataOne = getExcelData("1.bmp", 26.5, {oneQrcodeOne, oneQrcodeTwo, oneQrcodeThree});
        excelDatas.append(excelDataOne);
    
        Qrcode twoQrcodeOne = getQrcodeData("", "(87,140),(200,98)", 0);
        ExcelData excelDataTwo = getExcelData("2.bmp", 23.7, {twoQrcodeOne});
        excelDatas.append(excelDataTwo);
    
        ExcelData excelDataThree = getExcelData("3.bmp", 33.1, {});
        excelDatas.append(excelDataThree);
    
        Qrcode fourQrcodeTwo = getQrcodeData("第一个二维码;", "(87,1901),(200,98)", 2);
        Qrcode fourQrcodeThree = getQrcodeData("第二个二维码;", "(122,41),(59,345)", 2);
        ExcelData excelDataFour = getExcelData("4.bmp", 24.9, {fourQrcodeTwo, fourQrcodeThree});
        excelDatas.append(excelDataFour);
    
        Qrcode fiveQrcodeOne = getQrcodeData("第一个二维码;", "(87,192),(200,98)", 2);
        Qrcode fiveQrcodeTwo = getQrcodeData("第二个二维码;", "(122,41),(59,345)", 2);
        Qrcode fiveQrcodeThree = getQrcodeData("第三个二维码;", "(122,41),(59,345)", 2);
        Qrcode fiveQrcodeFour = getQrcodeData("", "(87,190),(200,98)", 0);
        Qrcode fiveQrcodeFive = getQrcodeData("第四个二维码;", "(122,41),(59,345)", 2);
        ExcelData excelDataFive = getExcelData("5.bmp", 32.1, {fiveQrcodeOne, fiveQrcodeTwo, fiveQrcodeThree, fiveQrcodeFour, fiveQrcodeFive});
        excelDatas.append(excelDataFive);
    }
    
    Datasets::Qrcode Datasets::getQrcodeData(QString result, QString point, int grade)
    {
        Qrcode qrcode;
        qrcode.result = result;
        qrcode.grade = grade;
        qrcode.points = point;
        return qrcode;
    }
    
    Datasets::ExcelData Datasets::getExcelData(QString fileName, float elapsed, QVector<Datasets::Qrcode> qrcodes)
    {
        ExcelData excelData;
        excelData.fileName = fileName;
        excelData.elapsed = elapsed;
        excelData.qrcodes.append(qrcodes);
        return excelData;
    }
    
    

    Excel表格操作文件:

    /** ExcelHandle.h **/
    #ifndef EXCELHANDLE_H
    #define EXCELHANDLE_H
    
    #include <QObject>
    #include <QDebug>
    #include <QAxObject>
    #include <QDir>
    #include <QColor>
    #include "Datasets.h"
    
    #pragma execution_character_set("utf-8")
    
    class ExcelHandle : public QObject
    {
        Q_OBJECT
    public:
        explicit ExcelHandle(QObject *parent = nullptr);
        bool open(QString excelPath);
        bool save();
        bool changeSheetName(QString newName);
        bool setColor(QColor color, QString start, QString end);
        bool writeOne(QString value, int row, int col);
        bool writeMulty(QVariant value, QString start, QString end); // value <== QVariantList <== QList<QList<QVariant>>
        bool writeExcelData(QVector<Datasets::ExcelData> excelDatas);
    
    
    private:
        bool mergeCells(QString start, QString end, QString value);
        bool setAutoFit(int lines);
    
    private:
        QString excelPath;
        QAxObject *excel = NULL;
        QAxObject *workBooks = NULL;
        QAxObject *workBook = NULL;
        QAxObject *workSheets = NULL;
        QAxObject *workSheet = NULL;
    
    signals:
    
    };
    
    #endif // EXCELHANDLE_H
    
    
    /** ExcelHandle.cpp **/
    #include "ExcelHandle.h"
    
    ExcelHandle::ExcelHandle(QObject *parent) : QObject(parent)
    {
    
    }
    
    /** 打开一个excel **/
    bool ExcelHandle::open(QString excelPath)
    {
        this->excelPath = excelPath;
        QFileInfo fileInfo(excelPath);
    
        excel = new QAxObject("Excel.Application");
        excel->setProperty("Visible", false);
        excel->setProperty("DisplayAlerts", false); // 在save和save as时,不弹窗提示
        workBooks = excel->querySubObject("WorkBooks");
    
        if(!fileInfo.exists()){
            //!!!新建工作簿
            workBooks->querySubObject("Add");
        } else {
            //!!!打开已存在的工作簿
            workBooks->querySubObject("Open (const QString&)", QDir::toNativeSeparators(excelPath));
        }
        workBook = excel->querySubObject("ActiveWorkBook");
        if (workBook == nullptr)
            return false;
    
        //!!!获取表页对象
        workSheets = workBook->querySubObject("WorkSheets");
        workSheet = workSheets->querySubObject("Item(int)", 1);
        changeSheetName("二维码"); // 给这个表页换一个名字
    
        if(workSheets == NULL)
            return false;
        return true;
    }
    
    bool ExcelHandle::save()
    {
        if(excel == NULL || workBooks == NULL || workBook == NULL)
            return false;
        /** 保存文件 **/
        QFileInfo fileInfo(excelPath);
        if(!fileInfo.exists())
            workBook->dynamicCall("SaveAs(const QString&)", QDir::toNativeSeparators(excelPath));
        else
            workBook->dynamicCall("Save()");
    
        /** 关闭并退出文件 **/
        workBooks->dynamicCall("Close()");
        excel->dynamicCall("Quit(void)");
        delete workSheet;
        workSheet = NULL;
        delete workSheets;
        workSheets = NULL;
        delete workBook;
        workBook = NULL;
        delete workBooks;
        workBooks = NULL;
        delete excel;
        excel = NULL;
        return true;
    }
    
    bool ExcelHandle::changeSheetName(QString newName)
    {
        if(workSheet == NULL)
            return false;
        workSheet->setProperty("Name", newName);
        QString sheetName = workSheet->property("Name").toString();
        qDebug() << sheetName;
        return true;
    }
    
    bool ExcelHandle::setColor(QColor color, QString start, QString end)
    {
        QAxObject *range = workSheet->querySubObject("Range(const Qvariant&)", QVariant("=(" +start+ ": " +end+ ")"));
        if(range == NULL)
            return false;
        QAxObject *cells = range->querySubObject("Columns");
        QAxObject *interior = cells->querySubObject("Interior");
        interior->setProperty("Color", color);
        delete interior;
        interior = NULL;
        delete cells;
        cells = NULL;
        return true;
    }
    
    bool ExcelHandle::writeOne(QString value, int row, int col)
    {
        if(workSheet == NULL)
            return false;
        QAxObject* range = workSheet->querySubObject("Cells(int, int)", qMax(row, 1), qMax(col, 1));
        range->setProperty("Value", value);
        delete range;
        range = NULL;
        return true;
    }
    
    bool ExcelHandle::writeMulty(QVariant value, QString start, QString end)
    {
        if(workSheet == NULL)
            return false;
        QAxObject *range = workSheet->querySubObject("Range(const QString&)",QString("(" +start+ ": " +end+ ")"));
        range->setProperty("Value", value);
        delete range;
        range = NULL;
        return true;
    }
    
    bool ExcelHandle::writeExcelData(QVector<Datasets::ExcelData> excelDatas)
    {
        // 先写入一个头
        QList<QVariant> header;
        header << "序号" << "图片" << "耗时" << "解码内容" << "坐标" << "等级";
        QVariant headerV = header;
        writeMulty(headerV, "A1", "F1");
        int row = 2;    // 行
        for(int i = 0; i < excelDatas.size(); i++){
            // 填入序号
            QString indexStart = QString("A%1").arg(row);
            QString indexend = QString("A%1").arg(row + qMax(excelDatas[i].qrcodes.size(),1) - 1);
            mergeCells(indexStart, indexend, QString::number(i));
            // 填入图片名
            QString imgStart = QString("B%1").arg(row);
            QString imgEnd = QString("B%1").arg(row + qMax(excelDatas[i].qrcodes.size(),1) - 1);
            mergeCells(imgStart, imgEnd, excelDatas[i].fileName);
            // 填入耗时
            QString timeStart = QString("C%1").arg(row);
            QString timeEnd = QString("C%1").arg(row + qMax(excelDatas[i].qrcodes.size(),1) - 1);
            mergeCells(timeStart, timeEnd, QString("%1ms").arg(QString::number(excelDatas[i].elapsed,'f',2)));
            // 如果没有二维码,填入灰色
            if(excelDatas[i].qrcodes.size() <= 0){
                QString colorStart = QString("A%1").arg(row);
                QString colorEnd = QString("F%1").arg(row);
                setColor(QColor(100,100,100), colorStart, colorEnd);
            }
            // 填入解码数据
            QVariantList vars;
            QList<QList<QVariant>> qrcodeList;  // 需要先用QList<QList<QVariant>>包装一次
            for(int j = 0; j < excelDatas[i].qrcodes.size(); j++){
                QList<QVariant> cells;
                cells.append(excelDatas[i].qrcodes[j].result);
                cells.append(excelDatas[i].qrcodes[j].points);
                cells.append(excelDatas[i].qrcodes[j].grade);
                qrcodeList.append(cells);
                vars.append(QVariant(qrcodeList.last()));
    
                // 设置颜色,解码失败为红色,没有二维码的为灰色
                if(excelDatas[i].qrcodes[j].result == ""){
                    QString colorStart = QString("D%1").arg(row+j);
                    QString colorEnd = QString("F%1").arg(row+j);
                    setColor(QColor(255,0,0), colorStart, colorEnd);
                }
            }
            QVariant result = vars;
            QString dataStart = QString("D%1").arg(row);
            QString dataEnd = QString("F%1").arg(row + qMax(excelDatas[i].qrcodes.size(),1) - 1);
            writeMulty(result, dataStart, dataEnd);
    
            row = row + qMax(excelDatas[i].qrcodes.size(),1);
        }
        setAutoFit(row);
        return true;
    }
    
    bool ExcelHandle::mergeCells(QString start, QString end, QString value)
    {
        if(workSheet == NULL)
            return false;
        QAxObject *range = workSheet->querySubObject("Range(const Qvariant&)", QVariant("=(" +start+ ": " +end+ ")"));
        if(range == NULL)
            return false;
    
        range->setProperty("MergeCells", true); // 合并单元格
        range->setProperty("Value", value);
        return true;
    }
    
    bool ExcelHandle::setAutoFit(int lines)
    {
        if(workSheet == NULL)
            return false;
        QAxObject *range = workSheet->querySubObject("Range(const Qvariant&)", QVariant(QString("A1:F%1").arg(lines)));
        if(range == NULL)
            return false;
    
        QAxObject *cells = range->querySubObject("Columns");
        cells->dynamicCall("AutoFit");
        return true;
    }
    
    

    demo示例文件:

    /** Demo.h **/
    #ifndef DEMO_H
    #define DEMO_H
    
    #include <QObject>
    #include <QDebug>
    #include <QFileInfo>
    #include "Module/ExcelHandle.h"
    #include "Module/Datasets.h"
    
    
    #pragma execution_character_set("utf-8")
    class Demo : public QObject
    {
        Q_OBJECT
    public:
        explicit Demo(QObject *parent = nullptr);
    
    private:
        void test();
    
    signals:
    
    };
    
    #endif // DEMO_H
    
    
    /** Demo.cpp **/
    #include "Demo.h"
    
    Demo::Demo(QObject *parent) : QObject(parent)
    {
        test();
    }
    
    void Demo::test()
    {
        QFileInfo infor("./testExcel.xlsx");
        Datasets dataSets;
        QVector<Datasets::ExcelData> excelDatas = dataSets.getData();
    
        ExcelHandle excelHandle;
        excelHandle.open(infor.absoluteFilePath());// 要绝对路径
    //    excelHandle.writeOne("ceshi一下中文", 1, 1);
        excelHandle.writeExcelData(excelDatas);
        excelHandle.save();
    }
    
    

    再贴一些其它功能

    ——居中

        QAxObject *range = workSheet->querySubObject("Range(const Qvariant&)", QVariant(QString("A1:F1")));
        if(range == NULL)
            return false;
    
        // 设置自动适配宽度
        range->setProperty("VerticalAlignment", -4108);     // 水平居中
        range->setProperty("HorizontalAlignment", -4108);   // 垂直居中
    

    ——固定宽度、自动换行

        // 把E那一列,设定固定宽度30,并设置自动换行
        QAxObject *E = workSheet->querySubObject("Columns(const QString&)", "E");
        E->setProperty("ColumnWidth", 30);
        E->setProperty("WrapText", true);
    

    ——设置字体

        QAxObject *font = workSheet->querySubObject("Range(const QString&)", "A1:P1")->querySubObject("Font");// 获取单元格字体
        font->setProperty("Bold",true);// 设置单元格字体加粗
        font->setProperty("Size",13);// 设置单元格字体大小
    

    ——冻结首行

        QAxObject* window = excel->querySubObject("ActiveWindow");
        window->setProperty("SplitRow", 1);
        window->setProperty("FreezePanes", true);
    
    展开全文
  • QAxObject操作word #插入word标题1级 2级 链接: [link](https://docs.microsoft.com/en-us/office/vba/api/word.wdbuiltinstyle) QAxObject* selection = m_pWord->querySubObject("Selection"); if (!...

    QAxObject操作word

    #插入word标题1级 2级
    链接: [link](https://docs.microsoft.com/en-us/office/vba/api/word.wdbuiltinstyle)

    QAxObject* selection = m_pWord->querySubObject("Selection");
    	if (!selection)
    	{
    		return;
    	}
    	    selection->dynamicCall("setStyle(WdBuiltinStyle)", "wdStyleBodyText");//文本
    
    	    selection->dynamicCall("setStyle(WdBuiltinStyle)", "wdStyleHeading1");//标题1
    

    在这里插入图片描述

    #QAxObject在光标处插入

    /*
    * 排版方式
    * 纵行、横行
    */
    
    void WordEngine::setype(bool type)
    {
    	QAxObject* selection = m_pWord->querySubObject("Selection");
    	if (!selection)
    	{
    		return;
    	}
    	if (type)
    	{
    		selection->querySubObject("PageSetup")->setProperty("Orientation", "wdOrientLandscape");
    	}
    	else {
    		selection->querySubObject("PageSetup")->setProperty("Orientation", "wdOrientPortrait");
    	}
    }
    
    /*
    * 获取页宽
    */
    
    int WordEngine::pageWidth()
    {
    	int width;
    	QAxObject* selection = m_pWord->querySubObject("Selection");
    	if (!selection)
    	{
    		return width;
    	}
    	width = selection->querySubObject("PageSetup")->property("PageWidth").toInt();;
    	return width;
    }
    
    /*
    *设置字号
    */
    
    void WordEngine::setFontSize(int size)
    {
    	QAxObject* selection = m_pWord->querySubObject("Selection");
    	if (!selection)
    	{
    		return;
    	}
    	selection->querySubObject("Font")->setProperty("Size", size);
    }
    
    /*
    设置对齐方式
    */
    
    void WordEngine::setAlignment(int index)
    {
    	QAxObject *selection = m_pWord->querySubObject("Selection");
    	if (!selection)
    	{
    		return;
    	}
    	if (index == 0)
    	{
    		selection->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphCenter");
    	}
    	if (index == 1)
    	{
    		selection->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphJustify");
    	}
    	if (index == 2)
    	{
    		selection->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphRight");
    	}
    	if (index == 3)
    	{
    		selection->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphLeft");
    	}
    }
    
    
    /*
    插入文字
    */
    
    void WordEngine::typeText(QString text, int index, int WdBuiltinStyle, bool bold, int size)
    {
    	QAxObject* selection = m_pWord->querySubObject("Selection");
    	if (!selection)
    	{
    		return;
    	}
    	setAlignment(index);
    	setFontSize(size);
    	if (bold)
    		selection->querySubObject("Range")->dynamicCall("SetBold(int)", true);
    	//if(WdBuiltinStyle==0)
    	//	selection->dynamicCall("setStyle(WdBuiltinStyle)", "wdStyleBodyText");
    	if(WdBuiltinStyle==1)
    	    selection->dynamicCall("setStyle(WdBuiltinStyle)", "wdStyleHeading1");
    	else if (WdBuiltinStyle == 2)
    		selection->dynamicCall("setStyle(WdBuiltinStyle)", "wdStyleHeading2");
    	else if (WdBuiltinStyle == 3)
    		selection->dynamicCall("setStyle(WdBuiltinStyle)", "wdStyleHeading3");
    	else if (WdBuiltinStyle == 4)
    		selection->dynamicCall("setStyle(WdBuiltinStyle)", "wdStyleHeading4");
    	selection->dynamicCall("TypeText(const QString&)", text);
    }
    /*
    插入图片
    */
    
    void WordEngine::AddPicture(QString file)
    {
    	QAxObject* selection = m_pWord->querySubObject("Selection");
    	if (!selection)
    	{
    		return;
    	}
    	setAlignment(0);
    	QString filename = file;
    	filename.replace("/", "\\");
    	QAxObject *Inlineshapes = selection->querySubObject("InlineShapes");
    	Inlineshapes->dynamicCall("AddPicture(const QString&)", filename);
    	delete Inlineshapes;
    }
    
    /*
    插入回车
    */
    
    void WordEngine::insertEnter()
    {
    	QAxObject* selection = m_pWord->querySubObject("Selection");
    	if (!selection)
    	{
    		return;
    	}
    	selection->dynamicCall("TypeParagraph(void)");
    }
    
    /*
    * 光标移到末尾,跳出单元格
    */
    void WordEngine::moveForEnd()
    {
    	QAxObject* selection = m_pWord->querySubObject("Selection");
    	QVariantList params;
    	params.append(6);
    	params.append(0);
    	selection->dynamicCall("EndOf(QVariant&, QVariant&)", params).toInt();
    }
    
    /*
    创建表格
    QStringList headList 添加表头
    */
    
    QAxObject* WordEngine::createTable(int row, int column, QStringList headList,bool SetLineStyleHide)
    {
    	QAxObject* selection = m_pWord->querySubObject("Selection");
    	if (!selection)
    	{
    		return false;
    	}
    	selection->dynamicCall("InsertAfter(QString&)", "\r\n");
    
    	QAxObject *range = selection->querySubObject("Range");
    	QAxObject *tables = m_pWorkDocument->querySubObject("Tables");
    	QAxObject *table = tables->querySubObject("Add(QVariant,int,int)", range->asVariant(), row, column);
    
    	table->setProperty("Style", "网格型");
    	//表格自动拉伸列 0固定  1根据内容调整  2 根据窗口调整
    	table->dynamicCall("AutoFitBehavior(WdAutoFitBehavior)", 2);
    
    	//设置表头
    	for (int i = 0; i<headList.size(); i++)
    	{
    		table->querySubObject("Cell(int,int)", 1, i + 1)->querySubObject("Range")->dynamicCall("SetText(QString)", headList.at(i));
    		//加粗
    		table->querySubObject("Cell(int,int)", 1, i + 1)->querySubObject("Range")->dynamicCall("SetBold(int)", true);
    		table->querySubObject("Cell(int,int)", 1, i + 1)->querySubObject("Font")->setProperty("Size", 10);
    	}
    	if (!SetLineStyleHide)
    	{
    		for (int i = 1; i <= 6; i++)
    		{
    			QString str = QString("Borders(-%1)").arg(i);
    			QAxObject *borders = table->querySubObject(str.toLatin1().constData());
    			borders->dynamicCall("SetLineStyle(int)", 1);
    		}
    	}
    	return table;
    }
    
    /*
    填充表格
    */
    
    void WordEngine::setCellText(QAxObject *table, int row, int column, QString text)
    {
    	QAxObject* range = table->querySubObject("Cell(int, int)", row + 1, column + 1)->querySubObject("Range");
    	if (range)
    	{
    		return;
    	}
    
    	range->dynamicCall("SetText(QString)", text);
    }
    
    /*
    表格插入图片
    */
    void WordEngine::setAddPicture(QAxObject *table, int row, int column, QString picPath)
    {
    	QAxObject* range = table->querySubObject("Cell(int, int)", row + 1, column + 1)->querySubObject("Range");
    	if (!range)
    	{
    		return;
    	}
    	range->querySubObject("InlineShapes")->dynamicCall("AddPicture(const QString&)", picPath);
    }
    
    /*
    光标跳转,类似表格中的tab
    */
    
    void WordEngine::moveRight()
    {
    	QAxObject* selection = m_pWord->querySubObject("Selection");
    	if (!selection)
    	{
    		return;
    	}
    	selection->dynamicCall("MoveRight(int)", 1);
    }
    

    #QAxObject在标签处插入

    /*****标签处添加字符串
    ******input:(QString)word模板地址,(bool)生成word文档是否可视
    ******output:
    */
    bool WordEngine::Open(QString sFile, bool bVisible)
    {
    	//新建一个word应用程序
    	m_pWord = new QAxObject();
    	bool bFlag = m_pWord->setControl("word.Application");
    	if (!bFlag)
    	{
    		return false;
    	}
    	QObject::connect(m_pWord, SIGNAL(exception(int, QString, QString, QString)),
    		this, SLOT(saveLastError(int, QString, QString, QString)));
    	m_pWord->setProperty("Visible", bVisible);
    	//获取所有的工作文档
    	QAxObject *document = m_pWord->querySubObject("Documents");
    	if (!document)
    	{
    		return false;
    	}
    	//以文件template.dot为模版新建一个文档
    	document->dynamicCall("Add(QString)", sFile);
    	//获取当前激活的文档
    	m_pWorkDocument = m_pWord->querySubObject("ActiveDocument");
    	if (m_pWorkDocument)
    		m_bIsOpen = true;
    	else
    		m_bIsOpen = false;
    
    	return m_bIsOpen;
    }
    /*****标签处添加字符串
    ******input:(QString)保存地址
    ******output:
    */
    void WordEngine::save(QString sSavePath)
    {
    	if (m_bIsOpen && m_pWorkDocument)
    	{
    		if (m_bNewFile) {
    			m_pWorkDocument->dynamicCall("Save()");
    		}
    		else {
    			//m_pWorkDocument->dynamicCall("SaveAs (const QString&,int,const QString&,const QString&,bool,bool)",
    			//                           m_sFile,56,QString(""),QString(""),false,false);
    			m_pWorkDocument->dynamicCall("SaveAs (const QString&)", sSavePath);
    		}
    	}
    	qDebug() << "save Done.";
    }
    /*****标签处添加字符串
    ******input:(bool)是否保存当前文件,(QString)保存地址[必填]
    ******output:
    */
    void WordEngine::close(bool bSave,QString save_path)
    {
    	if (bSave) {
    		save(save_path);
    	}
    	if (m_pWord) {
    		m_pWord->setProperty("DisplayAlerts", true);
    	}
    	if (m_pWorkDocument) {
    		m_pWorkDocument->dynamicCall("Close(bool)", true);
    	}
    	if (m_pWord) {
    		m_pWord->dynamicCall("Quit()");
    	}
    	if (m_pWorkDocuments)
    	{
    		delete m_pWorkDocuments;
    	}
    	if (m_pWord)
    	{
    		delete m_pWord;
    	}
    	m_pWorkDocument = NULL;
    	m_pWorkDocuments = NULL;
    	m_pWord = NULL;
    
    	m_bIsOpen = false;
    	m_bNewFile = false;
    }
    /*****标签处添加字符串
    ******input:(QString)标签名字,(QString)内容
    ******output: (bool)
    */
    bool WordEngine::replaceText(QString sLabel, QString sText)
    {
    	if (!m_pWorkDocument) {
    		return false;
    	}
    	//获取文档中名字为sLabel的标签
    	QAxObject *pBookmark = m_pWorkDocument->querySubObject("Bookmarks(QString)", sLabel);
    	if (pBookmark)
    	{
    		pBookmark->dynamicCall("Select(void)");
    		pBookmark->querySubObject("Range")->setProperty("Text", sText);
    		delete pBookmark;
    	}
    	return true;
    }
    /***** 插入文本到标签处 【 居中,行距1.5,段后0.5】
    ******input:(QString)标签名字,(QString)内容,(QString)字体,(int)字体大小 【默认黑体,字号12】
    ******output: (bool)
    */
    bool WordEngine::replaceTextStyle(QString sLabel, QString sText, QString FontName, int size)
    {
    	if (!m_pWorkDocument) {
    		return false;
    	}
    	//获取文档中名字为sLabel的标签
    	QAxObject *pBookmark = m_pWorkDocument->querySubObject("Bookmarks(QString)", sLabel);
    	if (pBookmark)
    	{
    
    		pBookmark->dynamicCall("Select(void)");
    
    		QAxObject *selection = m_pWord->querySubObj## 标题ect("Selection");//设置字体FontName
    		selection->dynamicCall("InsertAfter(QString&)", "\r\n");//不能删除,否则会出错
    		selection->querySubObject("Range")->querySubObject("Font")->setProperty("Size", size);//设置字体大小:小四12
    		selection->querySubObject("Range")->querySubObject("Font")->setProperty("Name", FontName);//字体(在插入字符前设置字体)
    
    		pBookmark->querySubObject("Range")->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphCenter");//水平居中
    		pBookmark->querySubObject("Range")->querySubObject("ParagraphFormat")->setProperty("LineSpacingRule", "wdLineSpace1pt5");//1.5行距  
    		pBookmark->querySubObject("Range")->querySubObject("ParagraphFormat")->setProperty("LineUnitAfter", 0.5);//段后0.5
    		pBookmark->querySubObject("Range")->setProperty("Text", sText);//插入字符
    		delete pBookmark;
    		//selection->querySubObject("Range")->querySubObject("Font")->setProperty("Bold", 1);//加粗
    	}
    	return true;
    }
    /***** 插入文本到标签处 【 居中,行距1.5,段后0.5】
    ******input:(QString)标签名字,(QString)内容,是否居中(0靠左,1居中,2靠右),(QString)字体,(int)字体大小 【默认黑体,字号12】
    ******output: (bool)
    */
    bool WordEngine::WordReplaceText(QString sLabel, QString sText, int iscenter, QString FontName, int size)
    {
    	if (!m_pWorkDocument) {
    		return false;
    	}
    	//获取文档中名字为sLabel的标签
    	QAxObject *pBookmark = m_pWorkDocument->querySubObject("Bookmarks(QString)", sLabel);
    	if (pBookmark)
    	{
    
    		pBookmark->dynamicCall("Select(void)");
    
    		QAxObject *selection = m_pWord->querySubObject("Selection");//设置字体FontName
    		selection->dynamicCall("InsertAfter(QString&)", "\r\n");//不能删除,否则会出错
    		selection->querySubObject("Range")->querySubObject("Font")->setProperty("Size", size);//设置字体大小:小四12
    		selection->querySubObject("Range")->querySubObject("Font")->setProperty("Name", FontName);//字体(在插入字符前设置字体)
    
    		if (iscenter == 1)
    			pBookmark->querySubObject("Range")->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphCenter");//水平居中
    		pBookmark->querySubObject("Range")->querySubObject("ParagraphFormat")->setProperty("LineSpacingRule", "wdLineSpace1pt5");//1.5行距  
    		pBookmark->querySubObject("Range")->querySubObject("ParagraphFormat")->setProperty("LineUnitAfter", 0.5);//段后0.5
    		pBookmark->querySubObject("Range")->setProperty("Text", sText);//插入字符
    		delete pBookmark;
    		//selection->querySubObject("Range")->querySubObject("Font")->setProperty("Bold", 1);//加粗
    	}
    	return true;
    }
    /*****删除标签处文本
    ******input:(QString)标签名
    ******output:
    */
    bool WordEngine::deleteLable(QString sLabel)
    {
    	if (!m_pWorkDocument) {
    		return false;
    	}
    	//获取文档中名字为sLabel的标签
    	QAxObject *pBookmark = m_pWorkDocument->querySubObject("Bookmarks(QString)", sLabel);
    	if (pBookmark)
    	{
    		pBookmark->dynamicCall("Select(void)");
    		pBookmark->querySubObject("Range")->deleteLater();
    		delete pBookmark;
    	}
    	return true;
    }
    /*****标签处添加图片
    ******input:(QString)标签名字,(QString)图片地址
    ******output: (bool) 
    */
    bool WordEngine::replacePic(QString sLabel, QString sFile)
    {
    	if (!m_pWorkDocument)
    		return false;
    
    	QAxObject *bookmark_pic = m_pWorkDocument->querySubObject("Bookmarks(QString)", sLabel);
    	if (bookmark_pic)
    	{
    		bookmark_pic->dynamicCall("Select(void)");
    		QAxObject *range = bookmark_pic->querySubObject("Range");
    		QVariant tmp = range->asVariant();
    		QList<QVariant> qList;
    		qList << QVariant(sFile);
    		qList << QVariant(false);
    		qList << QVariant(true);
    		qList << tmp;
    		QAxObject *Inlineshapes = m_pWorkDocument->querySubObject("InlineShapes");
    		Inlineshapes->dynamicCall("AddPicture(const QString&,QVariant,QVariant,QVariant)", qList);
    		delete Inlineshapes;
    	}
    	return true;
    }
    /*****标签处插入表格:不带头
    ******input:(QString)标签名字,(int)表格行数,(int)列数
    ******output: (QAxObject)
    */
    QAxObject *WordEngine::insertTable(QString sLabel, int row, int column)
    {
    	QAxObject *bookmark = m_pWorkDocument->querySubObject("Bookmarks(QVariant)", sLabel);
    	if (bookmark)
    	{
    		bookmark->dynamicCall("Select(void)");
    		QAxObject *selection = m_pWord->querySubObject("Selection");
    
    		selection->dynamicCall("InsertAfter(QString&)", "\n");
    		//selection->dynamicCall("MoveLeft(int)", 1);
    		selection->querySubObject("ParagraphFormat")->dynamicCall("Alignment", "wdAlignParagraphCenter");//水平居中
    		//selection->querySubObject("Cells")->setProperty("VerticalAlignment", "wdCellAlignVerticalCenter");//垂直居中
    		//selection->dynamicCall("TypeText(QString&)", "Table Test");//设置标题
    
    		QAxObject *range = selection->querySubObject("Range");
    		QAxObject *tables = m_pWorkDocument->querySubObject("Tables");
    		QAxObject *table = tables->querySubObject("Add(QVariant,int,int)", range->asVariant(), row, column);
    
    		for (int i = 1; i <= 6; i++)
    		{
    			QString str = QString("Borders(-%1)").arg(i);
    			QAxObject *borders = table->querySubObject(str.toLatin1().constData());
    			borders->dynamicCall("SetLineStyle(int)", 1);
    		}
    		return table;
    	}
    	return NULL;
    }
    /*****标签处插入表格:带头
    ******input:(QString)标签名字,(int)表格行数,(int)列数,(QStringList)表头数据
    ******output: (QAxObject)
    */
    QAxObject *WordEngine::insertTable(QString sLabel, int row, int column, QStringList headList)
    {
    	QAxObject *bookmark = m_pWorkDocument->querySubObject("Bookmarks(QVariant)", sLabel);
    	if (headList.size() != column) {
    		return NULL;
    	}
    	if (bookmark)
    	{
    		bookmark->dynamicCall("Select(void)");
    		QAxObject *selection = m_pWord->querySubObject("Selection");
    
    		selection->dynamicCall("InsertAfter(QString&)", "\r\n");
    		//selection->dynamicCall("MoveLeft(int)", 1);
    		selection->querySubObject("ParagraphFormat")->dynamicCall("Alignment", "wdAlignParagraphCenter");//水平居中
    		//selection->querySubObject("Cells")->setProperty("VerticalAlignment", "wdCellAlignVerticalCenter");//垂直居中
    		//设置标题
    		//selection->dynamicCall("TypeText(QString&)", "Table Test");
    
    		QAxObject *range = selection->querySubObject("Range");
    		QAxObject *tables = m_pWorkDocument->querySubObject("Tables");
    		QAxObject *table = tables->querySubObject("Add(QVariant,int,int)", range->asVariant(), row, column);
    		//表格自动拉伸列 0固定  1根据内容调整  2 根据窗口调整
    		table->dynamicCall("AutoFitBehavior(WdAutoFitBehavior)", 2);
    
    		//设置表头
    		for (int i = 0; i < headList.size(); i++) {
    			table->querySubObject("Cell(int,int)", 1, i + 1)->querySubObject("Range")->dynamicCall("SetText(QString)", headList.at(i));
    			//加粗
    			table->querySubObject("Cell(int,int)", 1, i + 1)->querySubObject("Range")->dynamicCall("SetBold(int)", true);
    		}
    
    		for (int i = 1; i <= 6; i++)
    		{
    			QString str = QString("Borders(-%1)").arg(i);
    			QAxObject *borders = table->querySubObject(str.toLatin1().constData());
    			borders->dynamicCall("SetLineStyle(int)", 1);
    		}
    		return table;
    	}
    	return NULL;
    }
    /*****为表格添加行
    ******input:(QAxObject)表格指针,(int)第几行处添加,(int)共添加几行
    ******output:
    */
    void WordEngine::addTableRow(QAxObject *table, int nRow, int rowCount)
    {
    	QAxObject *rows = table->querySubObject("Rows");
    	int count = rows->dynamicCall("Count").toInt();
    	if (0 <= nRow && nRow <= count)
    	{
    		for (size_t i = 0; i < rowCount; i++)
    		{
    			QString sPos = QString("Item(%1)").arg(nRow + i);
    			QAxObject *row = rows->querySubObject(sPos.toStdString().c_str());
    			QVariant param = row->asVariant();
    			rows->dynamicCall("Add(Variant)", param);
    		}
    	}
    }
    /*****获取表格行数
    ******input:所选信号
    ******output: (int)
    */
    int WordEngine::currenRow()
    {
    	QAxObject*selection = m_pWord->querySubObject("Selection");
    	int row = selection->dynamicCall("Information(QVariant&)", 10).toInt();
    	return row;
    }
    /*****合并单元格
    ******input:(int)开始行,(int)开始列,(int)结束行,(int)结束列,(QAxObject)表格指针
    ******output: (QAxObject)
    */
    void WordEngine::MergeCells(int nStartRow, int nStartCol, int nEndRow, int nEndCol, QAxObject *table, int tableIndex)
    {
    	if (nullptr == table)
    	{
    		return;
    	}
    	if (table)
    	{
    		QAxObject* StartCell = table->querySubObject("Cell(int, int)", nStartRow, nStartCol);
    		QAxObject* EndCell = table->querySubObject("Cell(int, int)", nEndRow, nEndCol);
    		if (nullptr == StartCell)
    		{
    			return;
    		}
    		if (nullptr == EndCell)
    		{
    			return;
    		}
    		StartCell->querySubObject("Merge(QAxObject *)", EndCell->asVariant());
    	}
    }
    /*****获取单元格内容 此处对于Excel来说列和行从1开始最少
    ******input:(int)行,(int)列
    ******output: (QVariant)
    */
    QVariant WordEngine::getCellValue(int row, int column)					
    {
    	QAxObject* selection = m_pWord->querySubObject("Selection");
    	QAxObject* table = selection->querySubObject("Tables(1)");
    	if (nullptr != selection && nullptr != table)
    		return table->querySubObject("Cell(int, int)", row, column)->querySubObject("Range")->property("Text");
    	else
    		return QVariant("");
    }
    /*****获取单元格内容 此处对于Excel来说列和行从1开始最少
    ******input:(int)行,(int)列,(QAxObject)表格指针
    ******output: (QVariant)
    */
    QVariant WordEngine::getCellValue(int row, int column, QAxObject *table)				
    {
    	if (nullptr != table)
    	{
    		QAxObject *cell = table->querySubObject("Cell(int, int)", row, column);
    		if (cell)
    			return cell->querySubObject("Range")->property("Text");
    	}
    	return QVariant("");
    }
    /*****设置表格列宽
    ******input:(QAxObject)表格指针,(int)列,(int)宽度
    ******output: 
    */
    void WordEngine::setColumnWidth(QAxObject *table, int column, int width)
    {
    	if (!table) {
    		return;
    	}
    	table->querySubObject("Columns(int)", column)->setProperty("Width", width);
    }
    /*****设置表格内容
    ******input:(QAxObject)表格指针,(int)行,(int)列,(int)内容
    ******output: 
    */
    void WordEngine::SetTableCellString(QAxObject *table, int row, int column, QString text,int Alignment)
    {
    	if (!table)
    		return;
    	QAxObject *cell = table->querySubObject("Cell(int,int)", row, column);
    	if (!cell)
    		return;
    	cell->dynamicCall("Select(void)");
    	if (!cell)
    		return;
    	cell->querySubObject("Range")->setProperty("Text", text);
    	if (row == 1)		//加粗
    		cell->querySubObject("Range")->dynamicCall("SetBold(int)", true);
    	setAlignment(Alignment);
    	cell->querySubObject("Range")->querySubObject("Font")->setProperty("Size", 10);
    	cell->querySubObject("Range")->querySubObject("Font")->setProperty("Name", "Times New Roman");
    }
    
    void WordEngine::saveLastError(int arg1, QString arg2, QString arg3, QString arg4)
    {
    	qDebug() << "QAxBase Error:" << QString::number(arg1) << arg2 << arg3 << arg4;
    }
    
    void WordEngine::setRowAlignment(QAxObject *table, int row, int flag)
    {
    	if (nullptr == table)
    	{
    		return;
    	}
    	QAxObject* Row = table->querySubObject("Rows(int)", row);
    	if (nullptr == Row)
    	{
    		return;
    	}
    	QAxObject* range = Row->querySubObject("Range");
    	if (nullptr == range)
    	{
    		return;
    	}
    	Row->querySubObject("Alignment(int)", flag);
    	if (flag == 0)
    	{
    		range->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphCenter");//水平居中
    		range->querySubObject("Cells")->setProperty("VerticalAlignment", "wdCellAlignVerticalCenter");//垂直居中
    	}
    	else if (flag == 1)
    	{
    		range->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphJustify");
    		range->querySubObject("Cells")->setProperty("VerticalAlignment", "wdCellAlignVerticalCenter");//垂直居中
    	}
    	else if (flag == 2)//wdAlignParagraphJustifyMed
    	{
    		range->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphRight");
    		range->querySubObject("Cells")->setProperty("VerticalAlignment", "wdCellAlignVerticalCenter");//垂直居中
    	}
    	else if (flag == 3)
    	{
    		range->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphLeft");
    		range->querySubObject("ParagraphFormat")->setProperty("VerticalAlignment", "wdCellAlignVerticalCenter");//垂直居中
    	}
    }
    
    void WordEngine::setCellAlignment(QAxObject *table, int row, int col, int flag)
    {
    	if (nullptr == table)
    	{
    		return;
    	}
    	QAxObject *cell = table->querySubObject("Cell(int,int)", row, col);
    	if (nullptr == cell)
    	{
    		return;
    	}
    	QAxObject* range = cell->querySubObject("Range");
    	if (nullptr == range)
    	{
    		return;
    	}
    	cell->querySubObject("Alignment(int)", flag);
    	if (flag == 0)
    	{
    		range->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphCenter");//水平居中
    		range->querySubObject("Cells")->setProperty("VerticalAlignment", "wdCellAlignVerticalCenter");//垂直居中
    	}
    	else if (flag == 1)
    	{
    		range->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphJustify");
    		range->querySubObject("Cells")->setProperty("VerticalAlignment", "wdCellAlignVerticalCenter");//垂直居中
    	}
    	else if (flag == 2)//wdAlignParagraphJustifyMed
    	{
    		range->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphRight");
    		range->querySubObject("Cells")->setProperty("VerticalAlignment", "wdCellAlignVerticalCenter");//垂直居中
    	}
    	else if (flag == 3)
    	{
    		range->querySubObject("ParagraphFormat")->setProperty("Alignment", "wdAlignParagraphLeft");
    		range->querySubObject("ParagraphFormat")->setProperty("VerticalAlignment", "wdCellAlignVerticalCenter");//垂直居中
    	}
    }
    
    展开全文
  • 使用Qt自带的axcontainer模块中的QAxObject类操作Excel需要知道其中的方法和属性,以下总结也是工作过程中用到过的。 使用QAxObject不足之处: 依赖本地Excel软件,否则无法正常导出 导出数据量太大时,会影响性能...

    使用Qt自带的axcontainer模块中的QAxObject类操作Excel需要知道其中的方法和属性,以下总结也是工作过程中用到过的。

    使用QAxObject不足之处:

    1. 依赖本地Excel软件,否则无法正常导出
    2. 导出数据量太大时,会影响性能,亲测,60w条数据需要两分钟
    bool ExportExcel::addWorkbook()
    {
        m_pExcel = new QAxObject();
        
         //连接Excel控件
        if (!m_pExcel->setControl("Excel.Application"))
            return false; 
            
        //窗体显示控制,用于调试,此处放开,导出excel整个过程都可以看到,想放电影一样
        //m_pExcel->dynamicCall("SetVisible (bool Visible)", true);
        
        //不显示任何警告信息。如果为true那么在关闭是会出现类似“文件已修改,是否保存”的提示
        m_pExcel->setProperty("DisplayAlerts", false);
        
        //获取工作簿集合
        auto pWorkbooks = m_pExcel->querySubObject("WorkBooks");
        if (!pWorkbooks) 
            return false;
            
        //新建一个工作簿    
        pWorkbooks->dynamicCall("Add");
        
    	//获取当前工作簿
        m_pWorkbook = m_pExcel->querySubObject("ActiveWorkBook");
        if (!m_pWorkbook)
            return false;
            
        return true;
    }
    
    QAxObject* GTJRuleContrastExportExcel::setWorkBook(QString strSheetName)
    {
        if (!m_pWorkbook)
        {
            return nullptr;
        }
    
        QAxObject *worksheets = m_pWorkbook->querySubObject("Sheets");//获取工作表集合
        int sheet_count = worksheets->property("Count").toInt();  //获取工作表数目
        QAxObject *last_sheet = worksheets->querySubObject("Item(int)", sheet_count);
        QAxObject *work_sheet = worksheets->querySubObject("Add(QVariant)", last_sheet->asVariant());
        work_sheet->dynamicCall("Move(QVariant)", last_sheet->asVariant());
        work_sheet->setProperty("Name", strSheetName);  //设置工作表Sheet名
        
        return work_sheet;
    }
    
    void ExportExcel::endExport()  //在析构函数中调用
    {
        if (m_pWorkbook)
        {
            QAxObject *worksheets = m_pWorkbook->querySubObject("Sheets");//获取工作表集合
            QAxObject *first_sheet = worksheets->querySubObject("Item(int)", 1);
            first_sheet->dynamicCall("Select()");//选中 sheet
    
            int sheet_count = worksheets->property("Count").toInt();  //获取工作表数目
            first_sheet = worksheets->querySubObject("Item(int)", sheet_count);
            first_sheet->dynamicCall("delete");//删除最后一个sheet页,为:sheet1
    
            m_pWorkbook->dynamicCall("SaveAs(const QString&)", QDir::toNativeSeparators(m_strSavePath));//保存至filepath,注意一定要用QDir::toNativeSeparators将路径中的"/"转换为"\",不然一定保存不了。
            m_pWorkbook->dynamicCall("Close()");//关闭工作簿
        }
    
        if (m_pExcel)
        {
            m_pExcel->dynamicCall("Quit()");//关闭excel
            delete m_pExcel;
            m_pExcel = nullptr;
        }
    }
    
    void ExportExcel::startExport()
    {
        if (!addWorkbook())
        {
            return;
        }
        
        QAxObject *work_sheet = setWorkBook(strSheetName);
        if (!work_sheet)
        {
            return;
        }
        
        //以下开始乱炖
        //以下有些指针没有判空,一定要养成指针判空的好习惯
        
       	//处理写入excel单元格数据
    	//方式一,使用Range方法统一写入excel表格,数据量过大时,可以提升性能
        {
    	    QList<QVariant> oRowdata;
    	    QList<QVariant> aline;	    
    	    aline.append(QVariant(QStringLiteral("哈哈")));
    	    aline.append(QVariant(QStringLiteral("呵呵")));
    	    aline.append(QVariant(QStringLiteral("嘿嘿")));   
    	    QVariant conv(aline);
    	    oRowdata.append(conv);
    	    QVariant oData(oRowdata);
    	    QString strRange = "A"+ QString::number(1) + ":" + "C" + QString::number(1);//A1:C1,需写入数据的表格范围
    	    QAxObject *oRange = work_sheet->querySubObject("Range(QString)", strRange);
    	    if (oRange)
    	    {
    	        oRange->setProperty("Value2", oData);//设置单元格值,使用Value2 wps 和 office可以正常导出数据
    	    }
    	}
    	
    	//方式二,指定行列写入数据,这种方式不仅显得很笨拙,而且数据量很大时,慢的要死,主要是每写入一个数据都要访问一次表格,性能很低。
    	{
    		//第5行第3列
    		QAxObject *cell_5_3 = work_sheet->querySubObject("Cells(int,int)", 5, 3);
    		cell_5_3->setProperty("Value2", "C++"); 
    	}
    	
    	{
    	    QAxObject *pCell = work_sheet->querySubObject("Range(const QString&)", "A1:C1");
    	    if (pCell)
    	    {	    	        	
            	//字体对齐(居中)
    	        pCell ->setProperty("HorizontalAlignment", -4108);//左对齐(xlLeft):-4131  居中(xlCenter):-4108  右对齐(xlRight):-4152
    	        pCell ->setProperty("VerticalAlignment", -4108); //上对齐(xlTop)-4160 居中(xlCenter):-4108  下对齐(xlBottom):-4107
    	    	        
    	        //设置字体
    	        QAxObject *font = pCell->querySubObject("Font");  //获取单元格字体
    	        font->setProperty("Bold", true);  //字体加粗
    			font->setProperty("Name", QStringLiteral("华文彩云"));  //设置单元格字体
    			font->setProperty("Bold", true);  //设置单元格字体加粗
    			font->setProperty("Size", 20);  //设置单元格字体大小
    			font->setProperty("Italic", true);  //设置单元格字体斜体
    			font->setProperty("Underline", 2);  //设置单元格下划线
    			font->setProperty("Color", QColor(255, 0, 0));  //设置单元格字体颜色(红色)
    	
    	        //设置单元格背景色(灰色)
    	        QColor bkColor(125, 125, 125);
    	        QAxObject* interior = pCell->querySubObject("Interior");
    	        interior->setProperty("Color", bkColor);
    	        
    	        //绘制单元格边框(黑色)
    	        QAxObject* border = pCell->querySubObject("Borders");
    	        border->setProperty("Color", QColor(0, 0, 0)); 
    	       
    	       //创建组
            	QAxObject* rows = pCell->querySubObject("Rows");
            	rows->querySubObject("Group");
    	    }
    
    		//宽度自适应
    	  	auto range = work_sheet->querySubObject("UsedRange");
    		QAxObject * cells = range->querySubObject("Columns");
    	  	if (cells)
    	   	{
    	       cells->dynamicCall("AutoFit");
    	   	}	
    
    		//设置单元格格式(文本)
    		QAxObject *oRange = work_sheet->querySubObject("Range(QString)", "A1:A99");
       		if (oRange)
       		{
           		oRange->setProperty("NumberFormatLocal", "@");
       		}
       		
       		oRange = work_sheet->querySBubObject("Range(QString)", "A1:B1");
       		if (oRange)
       		{
           		pCell ->setProperty("WrapText", true); //内容过多,自动换行
            	pCell ->setProperty("MergeCells", true); //合并单元格
            	//pCell ->setProperty("MergeCells", false);  //拆分单元格
            	//pcell->dynamicCall("ClearContents()");  //清空单元格内容
       		}
    	}
    }
    
    展开全文
  • 本文主要介绍QAxObject类导出为word文件操作。以实现导出一份成绩单为例,介绍可能会出现的问题,如何去解决。同时讲word中常用的一些属性封装为函数进行介绍,方便读者理解。
  • Qt使用QAxObject读写Excel 的方法

    千次阅读 2021-05-23 00:23:12
    参考资料: Qt导出Excel的简单实现 QT界面开发-QAxObject 读写excel(COM组件) 浅谈 Excel 对象模型 ActiveX Objects Excel VBA 参考 ...QAxObject对COM对象进行了封装,QAxObject派生自QAxBase...QAxObject是一个QOb.
  • 操作EXECL文件 修改execl直接通过行,列修改对应值,不用插入标签 打开execl文件 QAxObject *pApplication = pApplication = new QAxObject(); //Excel服务 pApplication->setControl("Excel.Application"); //设置...
  • 最后附上我用QAxBase::generateDocumentation()方法获得的对应于Excel.Application的带Qt数据类型的QAxObject或者QAxWidget中可用的属性、信号和槽列表(虽然我还不大会用,不过参考下还是很好的): ...
  • qt 调用QAxObject访问excel,word接口
  • Qt的windows商业版本提供了ActiveQt这个framework,使用这个组件我们可以在Qt中使用ActiveX控件。 这个代码提供了基本的Excel操作范例:打开 关闭 读写 另外,还实现了如何在Excel中插入散点图图表并添加趋势线,...
  •  1.QAxObject *excel = new QAxObject("Excel.Application"); //!建立excel操作对象,并连接Excel控件 2.excel->dynamicCall("SetVisible (bool Visible)", "false"); //! 设置为不显示窗体 更改 Excel 标题栏:...
  • QAxObject操作Excel表格

    千次阅读 2019-08-06 16:16:09
    QAxObject * a = sheets->querySubObject(“Item(const QString&)”, sheetName); a->dynamicCall(“delete”); } void QExcel::deleteSheet(int sheetIndex) { QAxObject * a = sheets->querySubObject(...
  • QAxObject合并单元格

    2022-03-15 15:33:51
    QAxObject *sheet = workbook->querySubObject("ActiveSheet"); //指向当前活动表格 ... //设置单元格范围,合并单元格 QAxObject *range=sheet->querySubObject("Range(const Qvariant&)", QVariant(...
  • QT 利用QAxObject大数据读写excel文件

    千次阅读 2020-12-05 11:25:37
    查阅了大部分资料,大数据读写excel文件用QAxObject对象最快,借鉴了一些读写excel文件的demo,所以本文也采用了这种方法。 大部分对于代码的解释,我都写在注释里了,有不明白或者建议的话,欢迎大家提出来。 ...
  • 【Qt】Qt使用QAxObject批量读写Excel

    千次阅读 2022-01-20 21:10:28
    Qt使用QAxObject打开Excel、读写单个单元格、批量读写、文件保存、文件关闭代码示例。
  • QT :QAxObject操作Excel

    2022-06-27 15:37:19
    QAxObject *excel = new QAxObject();//建立excel操作对象 excel->setControl("Excel.Application");//连接Excel控件 excel->setProperty("Visible", false);//显示窗体看效果 excel->setProperty("DisplayAlerts",...
  • // 操作Excel的对象 QAxObject *excel = NULL; // workbook对象 QAxObject *workbooks = NULL; // workbook对象 QAxObject *workbook = NULL; excel = new QAxObject("Excel.Application"); //true 表示操作文件时...
  • //****************************************************************** //新添加 m_word = new QAxObject("Word.Application"); //启动word应用进程 m_document = m_word->querySubObject("Documents"); //获取...
  • QT之使用QAxObject操作excel

    千次阅读 2020-02-28 17:19:32
     在VBA的参考手册中就可以看到具体函数、属性的用法,Qt操作Excel主要通过 QAxObject + Excel VBA来实现!  关于Qt对Excel的操作,网上的资料挺多的,但大多数都是比较基础的,关于插入工作表(至最后一行)...
  • QAxObject读写Excel文档
  • 使用QAxObject注意事项
  • Qt 导出Excel表 在Qt软件开发过程中,有时候软件导出...QAxObject *excel = new QAxObject("Excel.Application"); //如果为了看自己的程序到底怎样工作,可以设置为true excel->dynamicCall("SetVisible(bool)", f
  • QAxObject保存Excel表格

    千次阅读 2019-08-07 20:52:35
    QAxObject新建并保存Excel表格 C++中有三种常用的操作Excel的方式,Xlnt、QtXlsx以及QAxObject 本文使用QAxObject来新建并保存Excel表格 1:初始化Excel程序 /*初始化Excel对象*/ QAxObject *_excelObject = ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,529
精华内容 611
关键字:

QAxobject