DOCX, sure, but better not DOC. You can use Microsoft open-source product Open XML Format SDK:
Office Open XML - Wikipedia, the free encyclopedia[
^],
Microsoft Office XML formats - Wikipedia, the free encyclopedia[
^];
this product is available on github:
OfficeDev/Open-XML-SDK · GitHub[
^].
See also Microsoft warnings about using Office interop in server settings:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[
^],
http://support.microsoft.com/kb/257757/en-us[
^].
See also this Microsoft article of 2007 (the version of SDK referenced to is obsolete, but you can get a good idea how to use it):
Creating Documents by Using the Open XML Format SDK Version 2.0 CTP (Part 1 of 3)[
^].
I really hope we don't need to discuss obsolete DOC formats, which are bad, messed up and proprietary, without official open documentation. It's also possible, but mach harder to do.
But RTF is much simpler. For example, see these CodeProject articles:
RTF Document Constructor Library[
^],
RichText Builder (StringBuilder for RTF)[
^].
—SA