How to pass array objects to QAxObject property (Excel)? [SOLVED]



  • To be specific, I'm trying to set an Excel.Range.Value property using a QVariantList but all the time I get the same values in all of the cells inside Excel sheet. It only takes the first item out of my QVariantList and fills all of the cells with that same value.

    Any ideas?



  • You have to create a QVariant, which is actually a QList<QList<QVariant> >

    I did it the following way:
    @
    QStringList row1;
    row1<<"asdf"<<"asdf";
    QList<QVariant> varlist;
    varlist.append(QVariant(row1));

    xls.selectRange(1,1, rowCount, columnCount);
    xls.setValue(QVariant(varlist);
    @



  • Wow it worked! Thanks for this GREAT tip :) Owe you a beer.
    In my case it was a column instead of row so I did something like this:
    @
    QVariantList varlist;
    for(.. some loop ..)
    {
    // do things
    QStringList item;
    item << someItem;
    varlist.append(item);
    }

    and later on ...

    excel.setValue(QVariant(varlist));
    @
    I assume the same method can be used for ranges with diff with and height.


Log in to reply
 

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