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. [solved] Write into Excel table
Forum Updated to NodeBB v4.3 + New Features

[solved] Write into Excel table

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.6k 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

    Hey,
    I'm trying to wirte list of items into a column in excel file.
    with the ""SetValue2(const QVariantList&)" activex query.

    I can write cell by cell but it take a lot of time because I got 5000 items
    This is my code

    @
    bool Excel::writeCol(int col,int start_row, QVariantList &list)
    {
    char sCell[18];
    memset(sCell, 0, 18);
    if (col <= 26)
    sprintf(sCell, " %c", 'A' + col - 1);
    else
    sprintf(sCell, "%c%c", 'A' + col / 26 - 1, 'A' + col % 26 - 1);

    QString cell = sCell; //columnLetter
    
    QString columnName  = " A";
    columnName = columnName.toUpper() > cell.toUpper() ? columnName : cell;
    int endRow = list.size() + start_row;
    
    cell = cell.trimmed() + QString::number(endRow);
    QString srange = "Range(\""
                     + columnName.trimmed()
                     + QString::number(start_row)
                     + "\",\""
                     + cell
                     + "\")";
    qDebug("[%s]",srange.toAscii().constData());
    if (!excelSheet)
        return false;
    QAxObject *range = excelSheet->querySubObject(srange.toLocal8Bit());
    if (!range)
        return false;
    
    range->dynamicCall("SetValue2(const QVariantList&)", QVariant(list));
    delete range;
    
    return true;
    

    }
    @

    The result is that all the cells in the excel column filled by the same value ( the first value in the QVariantList )

    Any idea?

    I use QAxObject
    Setup: Qt 4.7.0 (32bit) win-xp sp3

    Thanks

    1 Reply Last reply
    0
    • S Offline
      S Offline
      simonCpp
      wrote on last edited by
      #2

      I found the solution here

      "Writing a Range of Rows & Columns to a Worksheet":http://www.qtforum.org/article/34059/qt-and-excel-writing-a-range-of-rows-columns-to-a-worksheet.html

      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