I have three related questions.
I want to create a word file with a name from C++. I want to be able to sent the printing command to this file, so that the file is being printed without the user having to open the document and do it manually and I want to be able to open the document. Opening the document should just open word which then opens the file.
You can use Office Automation for this task. You can find answers to frequently asked questions about Office Automation with C++ at http://support.microsoft.com/kb/196776 and http://support.microsoft.com/kb/238972 .
Keep in mind that to do Office Automation with C++, you need to understand how to use COM.
Here are some examples of how to perform various tasks in word usign C++:
Most of these samples show how to do it using MFC, but the concepts of using COM to manipulate Word are the same, even if you use ATL or COM directly.
As posted as an answer to a similar question, I advise you to look at this page where the author explains what solution he took to generate Word documents on a server, without MsWord being available, without automation or thirdparty libraries.
When you have the file and just want to print it, then look at this entry at Raymond Chen's blog. You can use the verb "print" for printing.
See the shellexecute msdn entry for details.
You can use automation to open MS Word (in background or foreground) and then send the needed commands.
A good starting place is the knowledge base article Office Automation Using Visual C++
Some C source code is available in How To Use Visual C++ to Access DocumentProperties with Automation (the title says C++, but it is plain C)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With