通过C++/Qt生成word文档(.doc/.odt) [英] Generating word documents (.doc/.odt) through C++/Qt

查看:46
本文介绍了通过C++/Qt生成word文档(.doc/.odt)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Qt 4.5.3 和 Windows XP.我需要我的应用程序生成包含正在使用和生成的信息的文档.正在使用的信息将只是字符串(QString 更具体),正在生成的信息也将是字符串和图像.

I am using Qt 4.5.3 and Windows XP. I need my application to generate documents that contains the information that is being used and generated. The information that is being used will be just strings (QString to be more specific) and the information that is being generated will be strings and images as well.

我希望文档是 MS word 文档 (.doc) 或可以是开放文档格式 (.odt) 另外我希望文档的格式为字体、图像、数据表、一些背景颜色和所有.

I want documents to be a MS word document (.doc) or can be an Open Document Format (.odt) Also I want the documents to be formatted with fonts,images, tables of data, some background colors and all.

我已经使用QTextDocumentQTextCursorQPrinter 创建了PDF 文件.但是,当我尝试为 odt 应用相同的 QTextDocument 时,结果只是格式错误.

I have done the creation PDF files using QTextDocument, QTextCursor and QPrinter. But when I tried to apply the same QTextDocument for odt, I ended up with just format error.

有没有办法使用任何其他使用 C++ 的库生成此类文档?你们是如何使用 C++ 生成此类文档 (.odt/.doc) 的?欢迎提供与此相关的任何指示、链接和示例.

Is there a way to generate such documents using any other libraries that use C++? How you guys use to generate such documents (.odt/.doc) in C++? Any pointers, links, examples regarding this are welcome.

推荐答案

我已经通过 Qt 方式做到了这一点.即通过使用 ActiveQt 模块.

I have done this through the Qt way. i.e by using ActiveQt module.

MS Word 的参考文档可以通过,

The reference documentation for MS Word can be obtained through,

MSDN 文档,实际上指向了VBAWD10.chm具有 MS Word 的 ActiveX api 的文件.

MSDN documentation, which actually pointed to the VBAWD10.chm file that has the ActiveX apis for MS Word.

Word 应用程序可以被初始化

The Word Application can be initialized by

QAxWidget wordApplication("Word.Application"); 

可以通过函数获取word应用程序的子对象,

The sub-objects of the word application can be obtained through the function,

QAxBase::querySubObject()

例如:

QAxObject *activeDocument = wordApplication.querySubObject("ActiveDocument");

将获得的子对象作为参数传递,

To pass the obtained sub-object as an argument,

QVariant QAxBase::asVariant () const

任何涉及单词对象的函数调用都可以使用函数调用,

Any function calls involving the word object can be called using the function using,

 QAxBase::dynamicCall ()

例如:

activeDocument->dynamicCall("Close(void)");

经过相当多的挣扎和很少的说服之后,它运行良好.:)

After a quite good amount of struggle and few convinces, it's working fine. :)

希望它对那些正在寻找类似解决方案的人有所帮助...

Hope it helps for those who are all looking for similar solutions...

这篇关于通过C++/Qt生成word文档(.doc/.odt)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆