Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. QAxObject Importing Excel named ranges using MS Query

QAxObject Importing Excel named ranges using MS Query

Scheduled Pinned Locked Moved 3rd Party Software
1 Posts 1 Posters 3.0k 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.
  • S Offline
    S Offline
    simonCpp
    wrote on last edited by
    #1

    Hi all, I got xlsm file format and I defined a table with name range.
    I can get the table name, but I didn't succeed to recive his ranges I tried this code

    @
    QAxObject* _excel = new QAxObject( "Excel.Application", 0 );
    QAxObject* workbooks = _excel->querySubObject( "Workbooks" );
    QAxObject* workbook = workbooks->querySubObject( "Open(const QString&)", fileName );
    QAxObject* sheets = workbook->querySubObject( "Worksheets" );
    //worksheets count
    int count = sheets->dynamicCall("Count()").toInt();
    count = sheets->property("Count").toInt();
    for (int i=1; i <= count; i++) //cycle through sheets
    {
    //sheet pointer
    QAxObject* sheet = sheets->querySubObject( "Item( int )", i );
    QString s_name = sheet->dynamicCall("Name()").toString();
    QAxObject* tables = sheet->querySubObject("Names");
    int table_count = tables->dynamicCall("Count()").toInt();
    table_count = tables->property("Count").toInt();
    qDebug("sheet name :%s",s_name.toAscii().constData());
    for (int j=1; j <= table_count; j++) //cycle through tables
    {
    QAxObject* table = tables->querySubObject( "Item( int )", j );
    QString t_name = table->dynamicCall("Name()").toString();
    qDebug("\ttable[%d]: %s",j,t_name.toAscii().constData());
    QAxObject * usedrange = table->querySubObject("UsedRange");
    QAxObject * rows = usedrange->querySubObject("Rows");
    QAxObject * columns = usedrange->querySubObject("Columns");
    int intRowStart = usedrange->property("Row").toInt();
    int intColStart = usedrange->property("Column").toInt();
    int intCols = columns->property("Count").toInt();
    int intRows = rows->property("Count").toInt();
    qDebug("\t\t[ Cells(C%d:C%d) , Rows(R%d:R%d) ]",
    intColStart,intCols,intRowStart,intRows);
    }
    }
    _excel->setProperty("DisplayAlerts", 0); //remove alert when close the file
    workbook->dynamicCall("Close()");
    _excel->dynamicCall("Quit()");
    @

    Got the error:
    QAxBase::dynamicCallHelper: UsedRange: No such property in [unknown]
    Candidates are:

    Help!

    1 Reply Last reply
    0

    • Login

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