读取word中表格的数据

  1. 在pro文件中加入
    QT += axcontainer
  2. 按步骤:
    1)创建Word应用程序对象;
    2)获取文档集;
    3)打开文档;
    4)获取活动表格;
    5)读取表格中的信息;
    QAxObject *myword = new QAxObject("Word.Application");//1)创建Word应用程序对象;
    QAxObject *mydocs = myword->querySubObject("Documents");//2)获取文档集;
    mydocs->dynamicCall("Open(const QString&)","C:\\Users\\Public\\Documents\\1.docx");//3)打开文档;
    QAxObject *document = myword->querySubObject("ActiveDocument");//4)获取活动表格;
    QAxObject *mytable = document->querySubObject("Tables(int)",table);
    
     	int rows = mytable->querySubObject("Rows")->dynamicCall("Count").toInt();
    	int cols = mytable->querySubObject("Columns")->dynamicCall("Count").toInt();
    	qDebug()<<"table:"<<table<<" rows:"<<rows<<" column:"<<cols;
        for(int i = 1; i < rows + 1; i++ )
            for(int j = 1; j < cols + 1; j++)
            {
                QAxObject *item = mytable->querySubObject("Cell(int,int)",i,j);// 5)读取表格中的信息;
                QString itemString = item->querySubObject("Range")->property("Text").toString();
                               qDebug()<<itemString;
            }        
上一篇:win7使用subst设置虚拟盘符


下一篇:UVA 11123 - Counting Trapizoid(计数问题+容斥)