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. QAxObject Excel
Forum Updated to NodeBB v4.3 + New Features

QAxObject Excel

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 860 Views 1 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.
  • C Offline
    C Offline
    Ceng0
    wrote on last edited by Ceng0
    #1

    Hi,
    I am newbie to using QAxObject.
    My problem is I know how to use the find method, but I don't know how to use the row and column values I get with the find method in the for loop.

    For example;
    First, I need to find out which column the number information is in. Then i'll get the numbers and l take the values corresponding to the numbers.

    afe00369-2712-4297-8f64-bab8c81565b9-image.png

     QString noStr = "No";
     QAxObject* findNoStr = range->querySubObject("Find(const QString&)", noStr );   // ForExample (&B&2)  
    
     for (int row = 1; row <= /*findNoStr.row*/; row++)
     {
         // Something like this
         QAxObject* value = sheet->querySubObject("Cells(int,int)", row ,/*findNoStr.column */);
         numbers.pushback(value ->dynamicCall("Value()").toInt())
     }
     
    
    JonBJ 1 Reply Last reply
    0
    • C Ceng0

      Hi,
      I am newbie to using QAxObject.
      My problem is I know how to use the find method, but I don't know how to use the row and column values I get with the find method in the for loop.

      For example;
      First, I need to find out which column the number information is in. Then i'll get the numbers and l take the values corresponding to the numbers.

      afe00369-2712-4297-8f64-bab8c81565b9-image.png

       QString noStr = "No";
       QAxObject* findNoStr = range->querySubObject("Find(const QString&)", noStr );   // ForExample (&B&2)  
      
       for (int row = 1; row <= /*findNoStr.row*/; row++)
       {
           // Something like this
           QAxObject* value = sheet->querySubObject("Cells(int,int)", row ,/*findNoStr.column */);
           numbers.pushback(value ->dynamicCall("Value()").toInt())
       }
       
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Ceng0
      This would be better asked in an Excel forum, it is not connected to Qt.

      But if you are saying you get back a string like B2, or similar, but you have to call something else with a row and column number, then just turn the "B2" into its row/column in your code. (I actually have a feeling there are Excel utility methods to convert between A1-format and row-column-numbers, but it may be just as easy to do it yourself.)

      1 Reply Last reply
      0
      • Ketan__Patel__0011K Offline
        Ketan__Patel__0011K Offline
        Ketan__Patel__0011
        wrote on last edited by Ketan__Patel__0011
        #3

        If you want to read any excel file then use QSqlDatabase For It

        my personal experience saying that QAxObject take Lot's of time for read any kind of Excel file
        And QAxObject Very complicated Concept

        you can see my code for Read Any Kind Of Excel File

        QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "xlsx_connection");
            db.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + QString(FilePath) + "");
            if(db.open())
                qDebug() << "Excel Is Connected";
            else
                qDebug() << "Excel Is Not Connected";
        
            QSqlQuery query(db);
            query.prepare("SELECT * FROM [" + QString("Sheet1") + "$]"); // Select range, place A1:B5 after $
            if(query.exec())
            {
                while (query.next())
                {
                           ///// Your Code
                }
            }
        

        for this You must have to Install Mysql Driver For Excel

        JonBJ 1 Reply Last reply
        1
        • Ketan__Patel__0011K Ketan__Patel__0011

          If you want to read any excel file then use QSqlDatabase For It

          my personal experience saying that QAxObject take Lot's of time for read any kind of Excel file
          And QAxObject Very complicated Concept

          you can see my code for Read Any Kind Of Excel File

          QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "xlsx_connection");
              db.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + QString(FilePath) + "");
              if(db.open())
                  qDebug() << "Excel Is Connected";
              else
                  qDebug() << "Excel Is Not Connected";
          
              QSqlQuery query(db);
              query.prepare("SELECT * FROM [" + QString("Sheet1") + "$]"); // Select range, place A1:B5 after $
              if(query.exec())
              {
                  while (query.next())
                  {
                             ///// Your Code
                  }
              }
          

          for this You must have to Install Mysql Driver For Excel

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Ketan__Patel__0011
          This is interesting, thanks for posting it.

          But I think it's only right to point out that what you get back, and what you can do with it, is very different from the VBA approach.

          Ketan__Patel__0011K 1 Reply Last reply
          0
          • JonBJ JonB

            @Ketan__Patel__0011
            This is interesting, thanks for posting it.

            But I think it's only right to point out that what you get back, and what you can do with it, is very different from the VBA approach.

            Ketan__Patel__0011K Offline
            Ketan__Patel__0011K Offline
            Ketan__Patel__0011
            wrote on last edited by Ketan__Patel__0011
            #5

            @JonB

            You can see OP Is shared her one image there he try to read All Rows One By One

                QSqlQuery query(db);
                query.prepare("SELECT * FROM [" + QString("Sheet1") + "$]")
                if(query.exec())
                {
                    while (query.next())
                    {
                               QString column1 = query.value(0).toString(); /// Column 1 Value
                               QString column2 = query.value(1).toString(); /// Column 1 Value
                               QString column3 = query.value(2).toString(); /// Column 1 Value
                    }
                }
            

            According to the my code
            all columns value are store in specific variable one by one
            You can store all are the values in Array Or List

            Or If You want to read any single value then just provide it Range in Query
            Because Excel Is working on Range Based (Range Based Structure)

            1 Reply Last reply
            0
            • JonBJ JonB referenced this topic on

            • Login

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