Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating word documents (.doc/.odt) through C++/Qt

Tags:

c++

ms-word

qt

odf

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.

like image 648
liaK Avatar asked Jul 05 '10 04:07

liaK


People also ask

How do I export a DOCX file?

You can export documents to a MS Word DOCX file for sharing, printing or conversion to PDF. To export a DOCX file, click File, mouseover Export and click DOCX File.

How can I process a doc file in Qt?

Files using the XML-based (.docx) format could be processed using Qt's XML handling classes (see Handling Document Formats ). TODO: Expand this section.

How can I integrate Qt with Microsoft Word?

If you are exclusively targeting the Windows platform and Microsoft Word will be installed on all target machines, then you can use Qt’s ActiveX framework to access Word’s .doc and .docx processing functionality through OLE automation.

How to create a Word document in Qt using Aspose?

Lets now check out how to create a Word document in this Qt project. The following are the steps to create a Word document in the Qt application using Aspose.Words for C++: Open the solution in Visual Studio. Create a new .cpp file named main.cpp and include the following headers files in it.

What is the ODT file extension?

ODT files are type of documents created with word processing applications that are based on OpenDocument Text File format. These are created with word processor applications such as free OpenOffice Writer and can hold content such as text, images, objects and styles. The ODT file is to Writer word processor what the DOCX is to Microsoft Word.


2 Answers

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...

like image 76
liaK Avatar answered Oct 19 '22 18:10

liaK


maybe you can use this and write to a file in odf format http://doc.trolltech.com/4.6/qtextdocumentwriter.html#supportedDocumentFormats qt does not know how to output doc docx etc but you can use com(activeQt) or some other library to write in those or other formats you need

like image 38
Olorin Avatar answered Oct 19 '22 17:10

Olorin