Unsolved Reading excel file using QT
-
i tried below code, but its failed to open the .xslx file, can some please let me know where i am going wrong
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "excelexport"); if (!db.isValid()) { std::cout << "ExportExcelObject::export2Excel failed: QODBC not supported."; return -2; } QString excelFilePath = "C:\\My_work\\Personal\\info.xlsx"; /* set the dsn string*/ QString dsn = QString("DRIVER={Microsoft Excel Driver (*.xls,*.xlsx)};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%1\";DBQ=%2"). arg(excelFilePath).arg(excelFilePath); db.setDatabaseName(dsn); if (!db.open()) std::cout << "failed to openDb" << std::endl; else std::cout << "Db Opened Success" << std::endl;
-
The documentation says:
QODBC Open Database Connectivity (ODBC) - Microsoft SQL Server and other ODBC-compliant databasesODBC driver might not be able to read EXCEL. I have heard of Excel to read through ODBC format, which does not necessarily mean that the ODBC driver can read Excel as well.
You can also check the error return text with lastError and the member function text() This might give more explanations.
-
@koahnig thank for your input, do we have any option that we can read EXCEL file ?
-
I am not an expert in that area. I have found just now this Qt wiki
To my surprise it uses also ODBC interface. You need to check there