C++ – Write a *.doc or *.rtf file from a c/c++ application

cdocumentms-wordrtf

How can I write to/generate a *.doc file programmatically using c or c++? Is there a (open source/cross platform) library to do this? If this is not possible, can write an *.odt file and then convert it to *.doc? Thanks in advance!

EDIT: Anders Abel commented that *.rtf file type is an option, so any suggestions on this one are also accepted.

Best Answer

Joel has an interesing article about this topic: http://www.joelonsoftware.com/items/2008/02/19.html

Basically he suggest either:

  1. Use MS Word via COM to create the document.
  2. Generate another format that MS Word will load, such as RTF. RTF has the advantage that it is a text format. So you can generate a template document with place holders, and then just run a substitution operation when you want to generate your documents.