QAxWidget *word=new QAxWidget("Word.Application", 0); word->setProperty("Visible", false); // 获取所有的工作文档 QAxObject * documents = word->querySubObject("Documents"); // 以文件template.doc为模版新建一个文档 documents->dynamicCall("Add(QString)",QString::fromLocal8Bit("C:/Users/Acharya/Desktop/test.docx")); // 获取当前激活的文档 QAxObject *document=word->querySubObject("ActiveDocument"); QAxObject *ActiveWindow = word->querySubObject("ActiveWindow"); QAxObject *ActivePane = ActiveWindow->querySubObject("ActivePane"); QAxObject* view = ActivePane->querySubObject("View"); QString name = view->property("Type").toString(); { QVariant tmp; tmp = 3; view->setProperty("Type", tmp); QString name1 = view->property("Type").toString(); qDebug() << name1; } // 开启页眉编辑(页眉属性值:9,页脚属性值:10-- 具体属性值在VB宏中可以查看) { QVariant tmp; tmp = 9; view->setProperty("SeekView", tmp); QString name1 = view->property("SeekView").toString(); qDebug() << name1; } QAxObject *selection = word->querySubObject("Selection"); selection->dynamicCall("TypeText(QVariant&)", "页眉页眉"); // 退出页眉编辑,自行处理 // 将文件另存为docbyqt.doc,关闭工作文档,退出应用程序 document->dynamicCall("SaveAs (const QString&)", QString("C:\\Users\\Acharya\\Desktop\\test1.doc")); document->dynamicCall("Close (boolean)", false); word->dynamicCall("Quit()");
正文
Qt利用QAxObject操作word--主要添加页眉或页脚
此篇文章发布距今已超过384天,您需要注意文章的内容或图片是否可用!
-- 展开阅读全文 --
还没有评论,来说两句吧...