Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Reading excel file using QT
Forum Updated to NodeBB v4.3 + New Features

Reading excel file using QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pradip Shinde
    wrote on last edited by VRonin
    #1

    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;
    
    K 1 Reply Last reply
    0
    • P Pradip Shinde

      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;
      
      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Pradip-Shinde

      The documentation says:
      QODBC Open Database Connectivity (ODBC) - Microsoft SQL Server and other ODBC-compliant databases

      ODBC 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.

      Vote the answer(s) that helped you to solve your issue(s)

      P 1 Reply Last reply
      0
      • K koahnig

        @Pradip-Shinde

        The documentation says:
        QODBC Open Database Connectivity (ODBC) - Microsoft SQL Server and other ODBC-compliant databases

        ODBC 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.

        P Offline
        P Offline
        Pradip Shinde
        wrote on last edited by
        #3

        @koahnig thank for your input, do we have any option that we can read EXCEL file ?

        K 1 Reply Last reply
        0
        • P Pradip Shinde

          @koahnig thank for your input, do we have any option that we can read EXCEL file ?

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Pradip-Shinde

          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

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved