Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating, opening and printing a word file from C++

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.

like image 214
user23163 Avatar asked Sep 28 '08 09:09

user23163


4 Answers

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++:

  • http://support.microsoft.com/kb/220911/en-us
  • http://support.microsoft.com/kb/238393/en-us
  • http://support.microsoft.com/kb/238611/en-us

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.

like image 66
Franci Penov Avatar answered Nov 10 '22 07:11

Franci Penov


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.

like image 35
Benoit Avatar answered Nov 10 '22 05:11

Benoit


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.

like image 2
Kasprzol Avatar answered Nov 10 '22 07:11

Kasprzol


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)

like image 1
Peter Olsson Avatar answered Nov 10 '22 05:11

Peter Olsson