Good Evening; I am working first time on word documents in c++. I just generated a word file in which i just simply add two numbers. Now i just want to change the font size, style and font color of a particular word 'Sum' in whole document. Can any body help me to let me know just how can i do this.
code is given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
cout<<"Enter First Number: ";
cout<<"Enter Second Number: ";
cout<<"Sum of "<<a<<" and "<<b<<" is "<<c<<endl;
cout<<"File is being saved by the name of addition.doc .... "<<endl;
Save<< "Sum of "<<a<<" and "<<b<<" is "<<c<<" ... ";
You have not created a microsoft word document. Putting .doc at the end of the filename will not automatically change the format that the file is saved in.
Your program creates a text file that could just as well be opened in a simple text editor like notepad. Pure text doesn't have colours, font size and such stylistic features.
If you want to create microsoft word documents you should learn how the microsoft word document format works or use a library to help you. I have no experience working with this format other than saving through a word processor so I can't help you.
I'm sure there are libraries available to simplify the creation of such text. Or- if you want to do things the hard way (but possibly learn more than you ever wanted to know about rtf) you could study the specifications and create your own routines to generate the required tags.
Another, related option would be to output the required text as an HTML document with suitable tags and stylesheet to specify the formatting.
This is coded in C#, so you'll need to translate the code into C++. The System.IO.Packaging mechanism in the code is the .Net way of creating a zip file.
As that's what a docx file basically is: an XML doc conforming to the Office Open XML File Formats schema, plus some other stuff, all zipped up. As it's a zip file, rather than a compound storage document like a Word .doc (no x) file, you just need to be able to deal with zip and XML. (You can even open .docx, xlsx, etc with 7Zip, WinZip or extract the files with a command line zip.)
The Office Open XML File Formats standards (ISO/IEC 29500 part 1, ...) are available for free here: