ODBC에서 excel 콘텐츠 가져오기

4053 단어
// 
#include 
#include 
#include 

QString strFile = QFileDialog::getOpenFileName(NULL,tr(" Excel "),".",tr("Exel file(*.xls *.xlsx)"));
if (strFile.isEmpty())
{
    QMessageBox::about(this, " ", "");
    return;
}    
// ODBC 
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "excelexport");
if(!db.isValid())
{
     QMessageBox::about(this, " ", "
error:
"+ db.lastError().text()); return; } QString dsn="Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};Readonly=TRUE;DBQ="+strFile+ ";"; db.setDatabaseName(dsn); if(!db.open()) { QMessageBox::about(this, " ", "
error:
"+ db.lastError().text()); return; } QSqlQuery query(db); query.exec("select * from [Sheet1$]"); while (query.next()) { int index = query.value(0).toInt();// 0 } db.close();

좋은 웹페이지 즐겨찾기