在我的项目中,我试图读取excel文件。然而,奇怪的事情发生了。当我打开excel时,它将正确执行。当我设置它不可见时,它将不会打开我的文件。
Qt版本:qt-开源-windows-x86-msvc2015 2015_64-5.7.0
Windows版本:64位win-10
控制台中的错误信息:
QAxBase:调用IDispatch成员时出错打开:未知错误
读取Excel文件的代码:
QAxObject *excel = NULL;
QAxObject *workbooks = NULL;
QAxObject *workbook = NULL;
excel = new QAxObject("Excel.Application");
excel->dynamicCall("SetVisible(bool)", false);
// The code to set invisible, project will work correctly when set visible true
workbooks = excel->querySubObject("WorkBooks");
if(!workbooks){
QMessageBox msgBox;
msgBox.setWindowTitle("error information");
msgBox.setText("workbooks error");
msgBox.exec();
return;
}
workbook = workbooks->querySubObject("Open(const QString&, QVariant)", file->filePath, 0);
//This code will not execute correctly, causing "workbook error"
if(!workbook){
QMessageBox msgBox;
msgBox.setWindowTitle("error information");
msgBox.setText("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();
workbook->dynamicCall("Close (Boolean)", false);
delete excel;发布于 2018-06-27 03:02:18
我遇到同样的情况,当它看不见的时候,我试着这样做:
excel->setProperty("EnableEvents",false);它起作用了。
qt-版本:4.8.6窗口-版本:10 excel:2013
https://stackoverflow.com/questions/40635184
复制相似问题