使用QAxObject获取excel的值
QApplication a(argc, argv);
QAxObject* excel = new QAxObject("Excel.Application");
excel->setProperty("Visible", true);
QAxObject* workbooks = excel->querySubObject("WorkBooks");
workbooks->dynamicCall("Open (const QString&)", QString("d:\\projects\\QT\\ninja\\a.xls"));
QAxObject* workbook = excel->querySubObject("ActiveWorkBook");
QAxObject* worksheets = workbook->querySubObject("WorkSheets");
QAxObject* worksheet = workbook->querySubObject("Worksheets(int)", 1);
QAxObject* usedrange = worksheet->querySubObject("UsedRange");
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();
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");
}
}
excel->setProperty("DisplayAlerts", 0);
workbook->dynamicCall("Save(void)");
workbook->dynamicCall("Close (Boolean)", false);
excel->setProperty("DisplayAlerts",1);
delete excel;
myxls w;
w.show();
return a.exec();
参考各种各样的资料,完整代码就是这样了.上面的代码基本没什么问题.就是
qDebug() << i << j << range->property("Value");
这里获取不到内容.输出的结果是1 1 QVariant(QVariant, ) .我装的是office2010.觉得应该不是office的问题.求解答
QAxObject* excel = new QAxObject("Excel.Application");
excel->setProperty("Visible", true);
QAxObject* workbooks = excel->querySubObject("WorkBooks");
workbooks->dynamicCall("Open (const QString&)", QString("d:\\projects\\QT\\ninja\\a.xls"));
QAxObject* workbook = excel->querySubObject("ActiveWorkBook");
QAxObject* worksheets = workbook->querySubObject("WorkSheets");
QAxObject* worksheet = workbook->querySubObject("Worksheets(int)", 1);
QAxObject* usedrange = worksheet->querySubObject("UsedRange");
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();
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");
}
}
excel->setProperty("DisplayAlerts", 0);
workbook->dynamicCall("Save(void)");
workbook->dynamicCall("Close (Boolean)", false);
excel->setProperty("DisplayAlerts",1);
delete excel;
myxls w;
w.show();
return a.exec();
参考各种各样的资料,完整代码就是这样了.上面的代码基本没什么问题.就是
qDebug() << i << j << range->property("Value");
这里获取不到内容.输出的结果是1 1 QVariant(QVariant, ) .我装的是office2010.觉得应该不是office的问题.求解答
...全文
相关推荐
Qt 之 QAxObject 读写 excel
使用Qt 中的 QAxObject ,对Excel 进行读写操作编辑。
Qt QAxObject 操作Excel
Qt使用QAxObject封装的COM组件的类来操作COM组件
【Qt QAxObject】使用 QAxObject 高效任意读写 Excel 表
【Qt QAxObject】使用 QAxObject 高效任意读写 Excel 表
QAxObject+Excel做的例程
内含自己总结写的一个类,包含Excel基本操作,如打开、创建、写入、连续写入、读、连续读出、更改字体颜色、获取行与列、删除表、设置字体等操作。
Qt中嵌入Excel
采用Qt中QAxObject和QAxWidget实现Excel表格嵌入进Qt程序中,实现Excel的读写操作



