Qt中一个奇怪的excel读取错误
A strange reading excel error with Qt
在我的项目中,我试图阅读excel文件。然而,奇怪的事情发生了。当我打开excel可见,它将正确执行。当我把它设置为不可见时,它不会打开我的文件。
Qt版本:Qt -opensource-windows-x86-msvc2015_64-5.7.0
Windows版本:64位win-10
控制台错误信息:
读取Excel文件的代码:QAxBase: Error calling IDispatch member Open: Unknown Error
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;
try this:
workbooks->querySubObject("Open(const QString&)",QString(path));
我遇到同样的情况,当它不可见时,我试着这样做:
excel->setProperty("EnableEvents",false);
。
qt-version:4.8.6 windows -version:10 excel:2013
明白了!我认为这是Excel服务的错误。
Just change your code :
excel->dynamicCall("SetVisible(bool)", **true**);
And add another:
excel->dynamicCall("SetVisible(bool)", **false**),
after workbooks = excel->querySubObject("WorkBooks");
work on Qt5.6 excel 2013;
我不知道原因,但它有一点飞溅。
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- 使用新行和不使用新行读取文件
- 读取文件并输入到矢量中
- 用c++从输入文件中读取另一行
- 如何从excel文件中读取数据并存储到变量中?
- C++使用 adodb 在 64 位 Windows 7 中读取 Excel 文件?
- 在C J2ME中读取Excel文件,并从ITQ获取数据
- C 程序要读取包含两个双重值的Excel数据的单列,这些值由逗号分隔并存储在自己的数组中
- 从C 中读取Excel的细胞
- 使用visualstudio在c++中读取excel文件
- 用c++读取excel文件(通用方向)
- 通过读取excel表为c文件中的变量赋值
- 是否可以在没有安装 Office Excel 或其他先决条件框架的情况下读取 Qt 或 C++ Excel
- Qt中一个奇怪的excel读取错误
- Libxl从excel文件中读取整数
- 读取Excel文件
- 读取文件夹中的所有文件,然后将每个文件及其匹配项放入新的excel文档中.是否可以用c++
- 如何在c++中读取/写入excel复选框状态
- 从Excel文件中读取特定列到c++
- 从C++中读取MS excel文件