Qt connect to XLSX file with ODBC driver
I have that code, that I took from Qt wiki:
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls)};DBQ=" + QString("sht.xlsx"));
if(db.open())
{
QSqlQuery query("select * from [" + QString("Sheet1") + "$]");
// Select range, place A1:B5 after $
while (query.next())
{
QString column1= query.value(0).toString();
qDebug() << column1;
}
}
else {
qDebug() << db.lastError().text();
}
But it doesn't connect :( I can't understand why:
[Microsoft] [Driver Manager ODBC] Data source name not found and no driver specified, the default QODBC3: Unable to connect
It was nedeed tp specify full path and set full name as in ODBC:
DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};
As always stack was useless. Guys here can answer only on noob questions, every real problem will stay here without answer.
You must compile and put database driver dll in a subfolder named 'sqldrivers' near your .exe file. In your case this should be qsqlodbc*.dll. Asterisk is a Qt major version number.