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

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

问题描述

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



我希望文档成为MS Word文档( .doc ),或者可以是开放文档格式( .odt )另外,我想要使用字体,图像,数据表,一些背景颜色和全部格式化文档。



我已经使用 QTextDocument QTextCursor创建了 PDF / code>和 QPrinter 。但是当我试图为 odt 应用相同的 QTextDocument 时,我最终只是格式化错误。



有没有办法使用任何其他使用C ++的库来生成这些文档?您如何用C ++生成这些文档( .odt /。 doc )?

解决方案

我已经通过 Qt 方式。即使用 ActiveQt 模块。



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



MSDN文档,其中实际上指向具有MS Word的ActiveX apis的 VBAWD10.chm 文件。



Word应用程序可以初始化为

  QAxWidget wordApplication(Word.Application); 

可以通过函数

$ b获取单词应用程序的子对象
$ b

  QAxBase :: querySubObject()

例如:

  QAxObject * activeDocument = wordApplication.querySubObject(ActiveDocument); 

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

  QVariant QAxBase :: asVariant()const 

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

  QAxBase :: dynamicCall()

例如:

  activeDocument-> dynamicCall( 关闭(无效)); 

经过相当多的努力和很少的说服力,它的工作正常。 :)



希望能帮助那些正在寻找类似解决方案的人...


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.

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.

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.

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.

解决方案

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

The reference documentation for MS Word can be obtained through,

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

The Word Application can be initialized by

QAxWidget wordApplication("Word.Application"); 

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

QAxBase::querySubObject()

For e.g:

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 ()

For e.g:

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生成单词文档(.doc / .odt)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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