Morning21 2016-11-17 09:44 采纳率: 0%
浏览 3675
已结题

qt读取Excel,显示打开正确,隐示打开错误

QT版本为qt-opensource-windows-x86-msvc2015_64-5.7.0
_windows版本为 64位 win-10
若excel->dynamicCall("SetVisible(bool)", true); 那么程序可以正确运行
若excel->dynamicCall("SetVisible(bool)", false); 那么程序运行错误, 文件打开错误,提示 workbook error
workbook = workbooks->querySubObject("Open(const QString&, QVariant)", file->filePath, 0); // 文件打开错误

代码如下:_

void wellProject::readExcel(fileInput *file, QStringList **zuanjuDataBaseArray)
{
QAxObject *excel = NULL;
QAxObject *workbooks = NULL;
QAxObject *workbook = NULL;
excel = new QAxObject("Excel.Application");
excel->dynamicCall("SetVisible(bool)", false);
workbooks = excel->querySubObject("WorkBooks");
if(!workbooks){
QMessageBox msgBox;
msgBox.setWindowTitle(QString::fromLocal8Bit("error information"));
msgBox.setText(QString::fromLocal8Bit("workbooks error"));
msgBox.exec();
return;
}
workbook = workbooks->querySubObject("Open(const QString&, QVariant)", file->filePath, 0);
if(!workbook){
QMessageBox msgBox;
msgBox.setWindowTitle(QString::fromLocal8Bit("error information"));
msgBox.setText(QString::fromLocal8Bit("workbook error"));
msgBox.exec();
return;
}

QAxObject * worksheet = workbook->querySubObject("WorkSheets(int)", 1);

QAxObject * usedrange = worksheet->querySubObject("UsedRange");
QAxObject * rows = usedrange->querySubObject("Rows");
QAxObject * columns = usedrange->querySubObject("Columns");

int intRowStart = usedrange->property("Row").toInt();
int intColStart = usedrange->property("Column").toInt();
int intCols = columns->property("Count").toInt();
int intRows = rows->property("Count").toInt();


file->rowNum = intCols;
file->colNum = intRows;
this->zuanjuDataBaseArray = (QStringList **)malloc(sizeof(QStringList *)*(file->rowNum));
for(int i=0;i<file->rowNum;i++)
    this->zuanjuDataBaseArray[i] = new QStringList();

QAxObject * cell;
QString tempString;

//****
workbook->dynamicCall("Close (Boolean)", false);
delete excel;
}

  • 写回答

3条回答 默认 最新

  • devmiao 2017-01-26 18:15
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?