Using ActiveX Object in Qt
2015-12-24 22:42
651 查看
QAxObject* excel = new QAxObject( "Excel.Application", 0 ); QAxObject* workbooks = excel->querySubObject( "Workbooks" ); QAxObject* workbook = workbooks->querySubObject( "Open(const QString&)", "C:\\1.xls" ); QAxObject* sheets = workbook->querySubObject( "Worksheets" ); QList<QVariantList> data; //Data list from excel, each QVariantList is worksheet row //worksheets count int count = sheets->dynamicCall("Count()").toInt(); count = sheets->property("Count").toInt(); for (int i=1; i<=count; i++) //cycle through sheets { //sheet pointer QAxObject* sheet = sheets->querySubObject( "Item( int )", i ); QAxObject* rows = sheet->querySubObject( "Rows" ); int rowCount = rows->dynamicCall( "Count()" ).toInt(); //unfortunately, always returns 255, so you have to check somehow validity of cell values QAxObject* columns = sheet->querySubObject( "Columns" ); int columnCount = columns->property("Count").toInt(); for (int row=1; row <= rowCount; row++) { QVariantList dataRow; bool isEmpty = true; //when all the cells of row are empty, it means that file is at end (of course, it maybe not right for different excel files. it's just criteria to calculate somehow row count for my file) for (int column=1; column <= columnCount; column++) { //Do something usefule here } if (isEmpty) //criteria to get out of cycle break; data.append(dataRow); } } workbook->dynamicCall("Close()"); excel->dynamicCall("Quit()"); QFile file1("c://sheet2.html"); file1.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out(&file1); out << excel->generateDocumentation(); file1.close();
sheet->querySubObject( "Pictures" )
转自 https://wiki.qt.io/Using_ActiveX_Object_in_Qt
相关文章推荐
- 深入理解Objective-C:优化你的代码
- Objective - C UITabbarController
- Objective-C 省市区 三个tableView联动
- 【Objective-C学习记录】第二十三天
- Objective-C 集合之NSDictionary的常用方法
- Objective - C tableView自适应高度 & KVC (Key -Value-Coding)
- Objective-C tableView自定义cell
- How to call an Objective-C Method from a C Method?
- Objective - C UITableView界面传值 从前往后,从后往前
- Objective - C UITableView学习笔记
- 【转】Android自动化测试(UiAutomator)——UiObject
- java线程同步:使用Object的wait,notify,notifyAll做线程调度
- Objective--C 导航视图控制器
- Objective-C基础1-类目(Category)和延展(Extension)的区别
- Objective-C 集合之NSArray的常用方法
- Objective-C NSObject 的实现分析(2014-10-23更新)
- Objective-C Runtime 总结:消息机制 篇
- Object.ReferenceEquals
- 遍历系统的所有ObjectType和TypeIndex
- iOS开发系列--Objective-C之KVC、KVO