title: QT read spreadsheets (Excel) file
body: <p>I need to read a spreadsheet in Excel using Qt in order to import data in a db.</p>
  
  <p>I can read the data using:</p>
  
  <pre><code>qDebug() &lt;&lt; "Open excel.." &lt;&lt; endl;
  QSqlDatabase excel = QSqlDatabase::addDatabase("QODBC");
  excel.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls)};DBQ=" + file);
  
  if(excel.open())
  {
      int cont = 0;
      QSqlQuery query("select * from [Sheet1"  + "$]");
      while(query.next())
      {
         QString column1= query.value(0).toString();
         QString column2= query.value(1).toString();
         QString column3= query.value(2).toString();
         QString column4= query.value(3).toString();
         QString column5= query.value(4).toString();
  
          qDebug("('', %d, %d, %d, \"%s\"),",
                 column2.toInt(),
                 column3.toInt(),
                 column4.toInt(),
                 column5.toStdString().c_str());
  
          cont++;
      }
  
      QString reg = "Regs: " + cont;
      qDebug() &lt;&lt; reg;
  
  }
  else
  {
      qDebug() &lt;&lt; "Can't open file (Excel)" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>This method works but I must to known the name(s) of the sheets in the excel file. I need read the file dynamically.</p>
  
  <p>I have been reading about QAxObject class but I can't find a working example. </p>
  
  <pre><code>QAxWidget excel("Excel.Application");
  excel.setProperty("Visible", true);
  
  QAxObject * workbooks = excel.querySubObject("WorkBooks");
  workbooks-&gt;dynamicCall("Open (const QString&amp;)", file);
  </code></pre>
  
  <p>Here get the error:</p>
  
  <pre><code>invalid use of incomplete type 'class QAxObject'
      workbooks-&gt;dynamicCall("Open (const QString&amp;)", QString("C:/test7.xls"));
            ^
  </code></pre>
  
  <p>Someone knows or have a functional example?? I will appreciate it a lot.</p>
  
  <p>Gretings.</p>