C++ (Qt)QSqlDatabase d=QSqlDatabase::addDatabase("QODBS");d.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls)};FIL={MS Excel};DBQ=D:\Qt\proba\release\file.xls");if(d.open()) QMessageBox::information(0,"ок","подключено");else QMessageBox::critical(0,"Ошибка подключения",d.lastError().text());
C++ (Qt)dbExl=QSqlDatabase::addDatabase("QODBC"); dbExl.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls)};FIL={MS Excel};DBQ=" + qApp->applicationDirPath().replace("/","\\") + "\\data\\report.xls"); if(!dbExl.open()){ QMessageBox::critical(0,"Error",dbExl.lastError().text());}QSqlQuery query=QSqlQuery(dbExl); query2.exec("INSERT INTO temp([Name auction],[Name_LPU]," "[Name_LS],[Summa]) " "values(fghbfg,gffhgh,gbhfc,67)"); QMessageBox::critical(0,"Error",query2.lastError().text());
C++ (Qt) QString excelFilePath="C:\\test.xls"; if (QFile::exists(excelFilePath))QFile::remove(excelFilePath); QString strDBName = QString("DRIVER={Microsoft Excel Driver (*.xls)};FIL={MS Excel}; READONLY=FALSE;DBQ="+excelFilePath); { QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","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 ('"+tr("blebleble")+"', '"+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");