长沙网站优化方案,网站后台字体安装,企业网站优化的方案,新手怎么学电商QT中操作word文档#xff1a;
参考如下内容#xff1a; C(Qt) 和 Word、Excel、PDF 交互总结
Qt对word文档操作总结
QT中操作word文档 Qt/Windows桌面版提供了ActiveQt框架#xff0c;用以为Qt和ActiveX提供完美结合。ActiveQt由两个模块组成#xff1a; QAxContainer模…QT中操作word文档
参考如下内容 C(Qt) 和 Word、Excel、PDF 交互总结
Qt对word文档操作总结
QT中操作word文档 Qt/Windows桌面版提供了ActiveQt框架用以为Qt和ActiveX提供完美结合。ActiveQt由两个模块组成 QAxContainer模块允许我们使用COM对象并且可以在Qt应用程序中嵌入QActive控件。 QAxServer模块允许我们导出使用Qt编写的自定义的COM对象和Active控件。 在这里我们使用了QAxContainer模块所以在.pro中需要使用下面这一项来链接这个QAxContainer模块CONFIGqaxcontainer注意在QT5.3中使用的是QT widgets gui axcontainer。
在头文件中包含QAxWidget和QAxObject。
一、建立一个word模板dot、dotx
新建一个word文档模板内容如下
选中项目下的一个单元格点击上面菜单栏中的 ”插入书签”添加如下书签
二、编写测试代码
//新建一个word应用程序QAxWidget *word new QAxWidget(Word.Application);if(word NULL){return 0;}//并设置为不可见word-setProperty(Visible, false);//获取所有的工作文档QAxObject *documents word-querySubObject(Documents);if (documents NULL){return 0;}//以template.dotx为模板新建一个文档documents-dynamicCall(Add(QString), QString(D:/template.dotx));//获取当前激活的文档QAxObject *document word-querySubObject(ActiveDocument);if (document NULL){return 0;}//获取文档中名字为Customer_Name的标签QAxObject *pCustomer_Name document-querySubObject(Bookmarks(QVariant), QString(Customer_Name));//选中标签将字符sText插入到标签位置if (!pCustomer_Name-isNull()){QString sText CJX;//此处为替换内容pCustomer_Name-dynamicCall(Select(void)); //选中要选中的区域pCustomer_Name-querySubObject(Range)-setProperty(Text, sText); //进行替换操作}//获取文档中名字为Name的标签QAxObject *pName document-querySubObject(Bookmarks(QVariant), QString(Name));//选中标签将字符sText插入到标签位置if (!pName-isNull()){QString sText 语文;//此处为替换内容pName-dynamicCall(Select(void)); //选中要选中的区域pName-querySubObject(Range)-setProperty(Text, sText); //进行替换操作}//获取文档中名字为Number的标签QAxObject *pNumber document-querySubObject(Bookmarks(QVariant), QString(Number));//选中标签将字符sText插入到标签位置if (!pNumber-isNull()){QString sText 100;//此处为替换内容pNumber-dynamicCall(Select(void)); //选中要选中的区域pNumber-querySubObject(Range)-setProperty(Text, sText); //进行替换操作}//将文件保存为doc同样可以生成docx文档QString pathsave QApplication::applicationDirPath() /template.docx;document-dynamicCall(SaveAs(const QString)), QDir::toNativeSeparators(pathsave));document-dynamicCall(Close (boolean), false);word-dynamicCall(Quit());delete word;最后附上测试文档链接 https://download.csdn.net/download/cao_jie_xin/88753710