[solved] Write into Excel table
-
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 sp3Thanks
-
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