So I've been browsing for how to read / write excel files with Qt...I only found this one example:
// excel->dynamicCall("SetVisible(bool)",true);
QAxObject *workbooks
= excel
->querySubObject
( "Workbooks" );
QAxObject *workbook
= workbooks
->querySubObject
( "Open(const QString&)",
"e:/tmp/test.xls" );
QAxObject *sheets
= workbook
->querySubObject
( "Worksheets" );
int count = sheets->dynamicCall("Count()").toInt();
for (int i=1; i<=count; i++)
{
QAxObject* sheet
= sheets
->querySubObject
( "Item( int )", i
);
QString name
= sheet
->dynamicCall
("Name()").
toString();
sheetsList.append(name);
}
workbook->dynamicCall("Close()");
excel->dynamicCall( "Quit()");
QAxObject* excel = new QAxObject( "Excel.Application", 0 );
// excel->dynamicCall("SetVisible(bool)",true);
QAxObject *workbooks = excel->querySubObject( "Workbooks" );
QAxObject *workbook = workbooks->querySubObject( "Open(const QString&)", "e:/tmp/test.xls" );
QAxObject *sheets = workbook->querySubObject( "Worksheets" );
int count = sheets->dynamicCall("Count()").toInt();
QStringList sheetsList;
for (int i=1; i<=count; i++)
{
QAxObject* sheet = sheets->querySubObject( "Item( int )", i );
QString name = sheet->dynamicCall("Name()").toString();
sheetsList.append(name);
}
workbook->dynamicCall("Close()");
excel->dynamicCall( "Quit()");
To copy to clipboard, switch view to plain text mode
compiles fine, but it crashes on execution on the line
QAxObject *workbook
= workbooks
->querySubObject
( "Open(const QString&)",
"e:/tmp/test.xls" );
QAxObject *workbook = workbooks->querySubObject( "Open(const QString&)", "e:/tmp/test.xls" );
To copy to clipboard, switch view to plain text mode
(yes, the excel file does exist and resides in that directory. Replacing the / with \\ doesn't solve the problem)
what am I doing wrong?
Bookmarks