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;
}