利用ODBC将其打开:
int ce::excel(QString fileName)
{
QString sheetName;
sheetName="mydatas";
qDebug() <<"fileName"<<fileName;
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "excelexport");
if(!db.isValid())
{
qDebug() << "export2Excel failed: QODBC not supported.";
return -2;
}
//set the dsn string
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())
{
qDebug() << "export2Excel failed: Create Excel file failed by DRIVER={Microsoft Excel Driver (*.xls)}.";
QSqlDatabase::removeDatabase("excelexport");
return -3;
}
QSqlQuery query(db);
//dro