火柴-人 2022-09-17 13:08 采纳率: 0%
浏览 83

使用QAxWidget嵌入excel窗口后怎么保存数据?

#include "QtWidgetsApplication3.h"

QtWidgetsApplication3::QtWidgetsApplication3(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

    _excelview = NULL;

    connect(ui.btOpen, SIGNAL(clicked()), this, SLOT(openOffice()));
    connect(ui.btClose, SIGNAL(clicked()), this, SLOT(closeOffice()));
}
    
QtWidgetsApplication3::~QtWidgetsApplication3()
{}

void QtWidgetsApplication3::OpenExcel(QString& fileName)
{

    //实例化一个操作Excel的控件
    _excelview = new QAxWidget("Excel.Application",ui.axWidget);
    _excelview->dynamicCall("SetVisible (bool Visible)", "false");
    
    _excelview->setProperty("DisplayAlerts", true);
    auto rect = ui.axWidget->geometry();
    _excelview->setGeometry(rect);
    _excelview->dynamicCall("Open (const QString&)",fileName);
    _excelview->setControl(fileName);
    _excelview->show();
}
void QtWidgetsApplication3::closeOffice()
{
    if (this->_excelview)
    {
        _excelview->dynamicCall("Save()");
        _excelview->dynamicCall("Close(Boolean)", true);
        _excelview->dynamicCall("Quit()");
        delete _excelview;
        _excelview = NULL;
    }
}


void QtWidgetsApplication3::openOffice()

{

    QFileDialog _dialog;

    _dialog.setFileMode(QFileDialog::ExistingFile);

    _dialog.setViewMode(QFileDialog::Detail);

    _dialog.setOption(QFileDialog::ReadOnly, true);

    _dialog.setDirectory(QString("./"));

    _dialog.setNameFilter(QString("所有文件(*.*);;word(*.docx *.doc);;excel(*.xlsx);;ppt(*.pptx *.ppt)"));

    if (_dialog.exec())
    {
        QStringList files = _dialog.selectedFiles();
        for (auto fileName : files)
        {

            if (fileName.endsWith(".xlsx"))
            {
                this->OpenExcel(fileName);
            }
        }
    }
}

怎么把在窗口的操作保存道xlsx文件中

  • 写回答

2条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-17 15:27
    关注
    评论

报告相同问题?

问题事件

  • 创建了问题 9月17日

悬赏问题

  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络
  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开
  • ¥30 crossover21 ARM64版本安装软件问题
  • ¥15 mymetaobjecthandler没有进入
  • ¥15 mmo能不能做客户端怪物