QAxObject Importing Excel named ranges using MS Query

  • 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) ]",
    _excel->setProperty("DisplayAlerts", 0); //remove alert when close the file

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


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.