День добрый!
Пытаюсь получить данные из книги Excel:
void readExcel (QTableWidget* table, QString path)
{
QAxObject *excel = new QAxObject( "Excel.Application",
table );
excel->dynamicCall( "SetVisible(bool)", true );
QAxObject *workbooks = excel->querySubObject( "WorkBooks" );
QAxObject *workbook = workbooks->querySubObject( "Open(QString)",
path );
if (workbook) {
QAxObject *sheets = workbook->querySubObject( "Sheets" );
QAxObject *sheet = sheets->querySubObject("Item(1)");
sheet->dynamicCall( "Select()" );
int r = 0;
table->setColumnCount(4);
table->setRowCount(0);
QString v = "";
while(r >= 0) {
for (int c=0; c<4 && r>=0; ++c){
QAxObject *cell = sheet->querySubObject(
"cells(int, int)", r+1, c+1 );
//cell->dynamicCall( "Select()" );
qDebug()<<cell->dynamicCall("Value()").toString();
if (cell)
v = cell->property("Value").toString();
else
v = "";
qDebug() << r << c << v;
if (c == 0 && r > 0)
{
if (v.length() != 0 && r < 10000)
{
table->insertRow(table->rowCount());
QAxObject *row = sheet->querySubObject(
"rows(int)", r+1 );
int points = row->property("Height").toInt();
int pixels = points * 1.2;
table->setRowHeight(r-1, pixels);
}
else
r = -11111;
}
if (r >= 0){
QTableWidgetItem *item = new QTableWidgetItem(v);
if (r == 0)
table->setHorizontalHeaderItem(c, item);
else
table->setItem(r-1, c, item);
}
}
r++;
}
}
excel->dynamicCall("Quit()");
}
Код работает, но значения ячеек всегда пустые. Не пойму в чем причина.