Qt C++库怎么读取Excel中第一列数据
1个回答
展开全部
QStringList referList;
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + dir.filePath("test.xlsx"));
if(db.open())
{
QSqlQuery query("select * from [Sheet1$A:A]",db); // Select range, place A1:B5 after $
while (query.next())
{
QString dataStr= query.value(0).toString();
if(dataStr != "0")
{
referList << dataStr;
}
}
}
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + dir.filePath("test.xlsx"));
if(db.open())
{
QSqlQuery query("select * from [Sheet1$A:A]",db); // Select range, place A1:B5 after $
while (query.next())
{
QString dataStr= query.value(0).toString();
if(dataStr != "0")
{
referList << dataStr;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询