16,201
社区成员
发帖
与我相关
我的任务
分享
QAxObject *excel = NULL;
QAxObject *workbooks = NULL;
QAxObject *workbook = NULL;
excel = new QAxObject("Excel.Application");
if (!excel)
{
QMessageBox::critical(this, "错误信息", "EXCEL对象丢失");
return;
}
excel->dynamicCall("SetVisible(bool)", false);
workbooks = excel->querySubObject("WorkBooks");
workbook = workbooks->querySubObject("Open(QString, QVariant)", QString(tr("g:\\BFS.xls")));
QAxObject * worksheet = workbook->querySubObject("WorkSheets(int)", 1);//打开第一个sheet
QAxObject * usedrange = worksheet->querySubObject("UsedRange");//获取该sheet的使用范围对象
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();
/*获取excel内容*/
for (int i = intRowStart; i < intRowStart + intRows; i++) //行
{
for (int j = intColStart; j < intColStart + intCols; j++) //列
{
QAxObject * range = worksheet->querySubObject("Cells(int,int)", i, j ); //获取单元格
qDebug() << i << j << range->property("Value"); //*****************************出问题!!!!!!
}
}