void exceladapter::readfile(QString filename, QString sheetname, int colNo)
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "excelexport");
if(!db.isValid())
{
return;
}
QString dsn = QString("DRIVER={Microsoft Excel Driver (*.xls)};DSN=''; FIRSTROWHASNAMES=1; READONLY=FALSE;CREATE_DB=\"%1\";DBQ=%2").
arg(filename).arg(filename);
db.setDatabaseName(dsn);
if(!db.open())
{
return;
}
QSqlQuery query(db);
query.exec("select * from"+sheetname);
while (query.next())
{
valuelist.append(query.value(colNo));
}
db.close();
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章