QString excelFilePath="C:\\test.xlsx";
if (QFile::exists(excelFilePath))QFile::remove(excelFilePath);
QString strDBName = QString("DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ="+excelFilePath);
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3","xls_db");
db.setDatabaseName(strDBName);
if (!(db.open())) qDebug()<<"DEBUG: "<<"open DB failed. "<<db.lastError();
else {
QSqlQuery query(db);
if (!query.exec("CREATE TABLE `testdb` (aaa CHAR(128), bbb CHAR(128))"))qDebug()<<"DEBUG: "<<"query exec error. table create failed."<<query.lastError();
else {
qDebug()<<"DEBUG: "<<"table created. inserting values...";
if (!query.exec("INSERT INTO testdb VALUES ('"+ QObject::tr("blebleble")+"', '"+QObject::tr("blblabla")+"')"))qDebug()<<"DEBUG: "<<"query exec error. insert values failed."<<query.lastError();
else {
};
};
qDebug()<<"DEBUG: "<<"closing DB..."; db.close();
};
};qDebug()<<"DEBUG: "<<"remove connection.";QSqlDatabase::removeDatabase("xls_db");