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. Qt & Excel xlsx outputs
Forum Updated to NodeBB v4.3 + New Features

Qt & Excel xlsx outputs

Scheduled Pinned Locked Moved Solved General and Desktop
excelqt5.15.1xlsxqsqlerrorsetdatabasename
25 Posts 4 Posters 5.9k Views
  • 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.
  • J J.Hilk
    21 Jan 2021, 18:39

    @Touchoco stupid question, but important

    you do not have that file open with excel, while you try to open it via Qt, right ?

    T Offline
    T Offline
    Touchoco
    wrote on 22 Jan 2021, 08:17 last edited by
    #16

    @J-Hilk I closed all Excel files to be sure. That's not a stupid question ^^

    J 1 Reply Last reply 22 Jan 2021, 08:20
    0
    • T Touchoco
      22 Jan 2021, 08:17

      @J-Hilk I closed all Excel files to be sure. That's not a stupid question ^^

      J Offline
      J Offline
      JonB
      wrote on 22 Jan 2021, 08:20 last edited by JonB
      #17

      @Touchoco
      Did you try my suggestion of Driver={...? I am wondering whether the space you have after the = is causing the parser not to respect your { starter for the { ... } data source name...?

      1 Reply Last reply
      0
      • J JonB
        21 Jan 2021, 18:44

        @J-Hilk
        Remember that he gets "data source too long" even without specifying a file.

        @Touchoco
        What does, say, QString connectionString("Driver={Microsoft Excel Driver}"); produce?

        P.S. This is a 100% longshot, but there's no example in the world which has the spaces you have in Driver = {. Try Driver={... just in case....

        T Offline
        T Offline
        Touchoco
        wrote on 22 Jan 2021, 08:29 last edited by
        #18

        @JonB

        I got differents messages by deplacing the space caracter.

        With :

        QString connectionString("Driver={Microsoft Excel Driver}");
        

        or

        QString connectionString("Driver={Microsoft Excel Driver (*.xls,*.xlsx,*.xlsm,*.xlsb)};Dbq=" + QString("D:\\test.xls"));
        

        or

        QString connectionString("Driver={Microsoft Excel Driver(*.xls,*.xlsx,*.xlsm,*.xlsb)};Dbq=" + QString("D:\\test.xls"));
        

        or

        QString connectionString("Driver={Microsoft Excel Driver};Dbq=" + QString("D:\\test.xls"));
        

        or

        QString connectionString("Driver ={Microsoft Excel Driver};Dbq=" + QString("D:\\test.xls"));
        

        or

        QString connectionString("Driver= {Microsoft Excel Driver};Dbq=" + QString("D:\\test.xls"));
        

        I got :
        QSqlError("0", "QODBC3: Unable to connect", "[Microsoft][Gestionnaire de pilotes ODBC] Data source not found and driver name not specified")

        With :

        QString connectionString("Driver = {Microsoft Excel Driver};Dbq=" + QString("D:\\test.xls"));
        

        I got :
        QSqlError("0", "QODBC3: Unable to connect", "[Microsoft][Gestionnaire de pilotes ODBC] Datasource name too long")

        todelete.png

        J 1 Reply Last reply 22 Jan 2021, 08:44
        0
        • C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 22 Jan 2021, 08:42 last edited by
          #19

          I assume you're using a 64Bit Qt - so do you also have installed a 64Bit Excel ODBC driver? You can check this by opening odbcad32.exe from <WinDir>\System32\ and take a look at your User DSNs if you can configure the Excel driver there.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          T 1 Reply Last reply 25 Jan 2021, 15:07
          2
          • T Touchoco
            22 Jan 2021, 08:29

            @JonB

            I got differents messages by deplacing the space caracter.

            With :

            QString connectionString("Driver={Microsoft Excel Driver}");
            

            or

            QString connectionString("Driver={Microsoft Excel Driver (*.xls,*.xlsx,*.xlsm,*.xlsb)};Dbq=" + QString("D:\\test.xls"));
            

            or

            QString connectionString("Driver={Microsoft Excel Driver(*.xls,*.xlsx,*.xlsm,*.xlsb)};Dbq=" + QString("D:\\test.xls"));
            

            or

            QString connectionString("Driver={Microsoft Excel Driver};Dbq=" + QString("D:\\test.xls"));
            

            or

            QString connectionString("Driver ={Microsoft Excel Driver};Dbq=" + QString("D:\\test.xls"));
            

            or

            QString connectionString("Driver= {Microsoft Excel Driver};Dbq=" + QString("D:\\test.xls"));
            

            I got :
            QSqlError("0", "QODBC3: Unable to connect", "[Microsoft][Gestionnaire de pilotes ODBC] Data source not found and driver name not specified")

            With :

            QString connectionString("Driver = {Microsoft Excel Driver};Dbq=" + QString("D:\\test.xls"));
            

            I got :
            QSqlError("0", "QODBC3: Unable to connect", "[Microsoft][Gestionnaire de pilotes ODBC] Datasource name too long")

            todelete.png

            J Offline
            J Offline
            JonB
            wrote on 22 Jan 2021, 08:44 last edited by JonB
            #20

            @Touchoco
            Well, I'm not 100%, but I do think we have found some improvement/difference. Only with extra spaces do you get Datasource name too long. Let's not do that, as none of the examples do, and nor does your working Native Client one.

            The referenced pages gives:

            To read an Excel file with ODBC (tested on Windows 7 with QT 4.7.1 and Windows 10 with QT 5.7) :

            QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "xlsx_connection"); db.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + QString("c:\\path\\to\\your\\file\\file.xlsx")); if(db.open()) {

            So, FWIW, let's stick to exactly that string, no changing in spacing or capitalization.

            Meanwhile, I see @Christian-Ehrlicher has queried that you verify your ODBC Excel driver is working. I wonder whether you do not have this set up right, e.g. 32-bit only when you're using 64-bit. Like I said earlier you can check this from Windows, please follow what he has said about how to do that.

            J T 2 Replies Last reply 22 Jan 2021, 08:55
            2
            • J JonB
              22 Jan 2021, 08:44

              @Touchoco
              Well, I'm not 100%, but I do think we have found some improvement/difference. Only with extra spaces do you get Datasource name too long. Let's not do that, as none of the examples do, and nor does your working Native Client one.

              The referenced pages gives:

              To read an Excel file with ODBC (tested on Windows 7 with QT 4.7.1 and Windows 10 with QT 5.7) :

              QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "xlsx_connection"); db.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + QString("c:\\path\\to\\your\\file\\file.xlsx")); if(db.open()) {

              So, FWIW, let's stick to exactly that string, no changing in spacing or capitalization.

              Meanwhile, I see @Christian-Ehrlicher has queried that you verify your ODBC Excel driver is working. I wonder whether you do not have this set up right, e.g. 32-bit only when you're using 64-bit. Like I said earlier you can check this from Windows, please follow what he has said about how to do that.

              J Online
              J Online
              J.Hilk
              Moderators
              wrote on 22 Jan 2021, 08:55 last edited by
              #21

              @JonB your right

              the issue is probably the use of Dbq instead of DBQ

              A wokring database name from one of my projects:

              db_XL.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + path );
              

              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              0
              • C Christian Ehrlicher
                22 Jan 2021, 08:42

                I assume you're using a 64Bit Qt - so do you also have installed a 64Bit Excel ODBC driver? You can check this by opening odbcad32.exe from <WinDir>\System32\ and take a look at your User DSNs if you can configure the Excel driver there.

                T Offline
                T Offline
                Touchoco
                wrote on 25 Jan 2021, 15:07 last edited by
                #22

                @Christian-Ehrlicher thank you for your help.

                I got the following screen but I don't understang how I could configure the Excel driver there.

                todelete2.png

                I also tried to compile my program with MinGw 32 bit : the error remain unchanged.

                1 Reply Last reply
                0
                • J JonB
                  22 Jan 2021, 08:44

                  @Touchoco
                  Well, I'm not 100%, but I do think we have found some improvement/difference. Only with extra spaces do you get Datasource name too long. Let's not do that, as none of the examples do, and nor does your working Native Client one.

                  The referenced pages gives:

                  To read an Excel file with ODBC (tested on Windows 7 with QT 4.7.1 and Windows 10 with QT 5.7) :

                  QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "xlsx_connection"); db.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + QString("c:\\path\\to\\your\\file\\file.xlsx")); if(db.open()) {

                  So, FWIW, let's stick to exactly that string, no changing in spacing or capitalization.

                  Meanwhile, I see @Christian-Ehrlicher has queried that you verify your ODBC Excel driver is working. I wonder whether you do not have this set up right, e.g. 32-bit only when you're using 64-bit. Like I said earlier you can check this from Windows, please follow what he has said about how to do that.

                  T Offline
                  T Offline
                  Touchoco
                  wrote on 25 Jan 2021, 15:45 last edited by
                  #23

                  @JonB

                  Thank you for your help.

                  I worked ! Sticking with exactly the same spaces to the same places. And with 32 bits compiler.
                  I tried to change to 64 bit compiler : KO. I tried with a very long and weird file name : it works.
                  Driver and dbq can be write : DRIVER, DBQ, driver, dbq, Driver, Dbq.

                  Here is the current working code :

                  QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
                      QString connectionString("DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + QString("D:\\sabin\\Documents\\C++ et C\\C++\\BaF\\BaF\\Templates\\TEST.xls"));
                      db.setDatabaseName(connectionString);
                      if(db.open())
                      {
                          QSqlQuery query("select * from [" + QString("Infos_adm") + "$A1:E20]");
                  
                          while (query.next())
                          {
                              //reading columns
                              QString column1= query.value(0).toString();
                              qDebug()<<column1;
                          }
                          qDebug()<<"done";
                          db.close();
                          QString dbConnectionName(db.connectionName());
                          db.~QSqlDatabase();
                          QSqlDatabase::removeDatabase(dbConnectionName);
                      }
                      else
                      {
                          qDebug()<<db.lastError();
                          qDebug() << connectionString ;
                      }
                  
                  
                  C J 2 Replies Last reply 25 Jan 2021, 15:53
                  0
                  • T Touchoco
                    25 Jan 2021, 15:45

                    @JonB

                    Thank you for your help.

                    I worked ! Sticking with exactly the same spaces to the same places. And with 32 bits compiler.
                    I tried to change to 64 bit compiler : KO. I tried with a very long and weird file name : it works.
                    Driver and dbq can be write : DRIVER, DBQ, driver, dbq, Driver, Dbq.

                    Here is the current working code :

                    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
                        QString connectionString("DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + QString("D:\\sabin\\Documents\\C++ et C\\C++\\BaF\\BaF\\Templates\\TEST.xls"));
                        db.setDatabaseName(connectionString);
                        if(db.open())
                        {
                            QSqlQuery query("select * from [" + QString("Infos_adm") + "$A1:E20]");
                    
                            while (query.next())
                            {
                                //reading columns
                                QString column1= query.value(0).toString();
                                qDebug()<<column1;
                            }
                            qDebug()<<"done";
                            db.close();
                            QString dbConnectionName(db.connectionName());
                            db.~QSqlDatabase();
                            QSqlDatabase::removeDatabase(dbConnectionName);
                        }
                        else
                        {
                            qDebug()<<db.lastError();
                            qDebug() << connectionString ;
                        }
                    
                    
                    C Online
                    C Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 25 Jan 2021, 15:53 last edited by
                    #24

                    @Touchoco said in Qt & Excel xlsx outputs:

                    And with 32 bits compiler.
                    I tried to change to 64 bit compiler : KO

                    So my idea was wrong. Install a 64 Bit Excel if you want to use a 64Bit Qt (sad but true).

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    0
                    • T Touchoco
                      25 Jan 2021, 15:45

                      @JonB

                      Thank you for your help.

                      I worked ! Sticking with exactly the same spaces to the same places. And with 32 bits compiler.
                      I tried to change to 64 bit compiler : KO. I tried with a very long and weird file name : it works.
                      Driver and dbq can be write : DRIVER, DBQ, driver, dbq, Driver, Dbq.

                      Here is the current working code :

                      QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
                          QString connectionString("DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + QString("D:\\sabin\\Documents\\C++ et C\\C++\\BaF\\BaF\\Templates\\TEST.xls"));
                          db.setDatabaseName(connectionString);
                          if(db.open())
                          {
                              QSqlQuery query("select * from [" + QString("Infos_adm") + "$A1:E20]");
                      
                              while (query.next())
                              {
                                  //reading columns
                                  QString column1= query.value(0).toString();
                                  qDebug()<<column1;
                              }
                              qDebug()<<"done";
                              db.close();
                              QString dbConnectionName(db.connectionName());
                              db.~QSqlDatabase();
                              QSqlDatabase::removeDatabase(dbConnectionName);
                          }
                          else
                          {
                              qDebug()<<db.lastError();
                              qDebug() << connectionString ;
                          }
                      
                      
                      J Offline
                      J Offline
                      JonB
                      wrote on 25 Jan 2021, 16:51 last edited by
                      #25

                      @Touchoco
                      Glad it works, but it's a shame to have to change over to 32-bit Qt app just to be able to talk ODBC to Excel.

                      If you want to pursue this further I think it is a non-Qt issue. You would have to Google for something about how to ODBC from a 64-bit executable when I have such-and-such (probably 32-bit) Excel, or similar.

                      1 Reply Last reply
                      2

                      25/25

                      25 Jan 2021, 16:51

                      • Login

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