Sunday, March 14, 2010

Ms Word Automation using C#, Filling a shape with a specific RGB values.

In the development process of Abey Limousines Management System for Monaco France we were asked to export their Invoices to Ms Word where they can have it totally editable. We were asked to insert a shape to the word document to show their Facture No (Invoice No), We had to fill that shape with RGB(51,102,153) values, but we found it extremely hard to fill the shape with the above specific RGB value.

The RGB(51,102,153) is close to a blue color, but the colors we got close to blue are WdColor.wdColorLightBlue which has RGB(51,102,255) and WdColor.wdColorBlue which has RGB(0,0,255). Above those colors were presets and we found it hard to set it to the color of RGB(51,102,153).

Finally we found the solution, It was creating the color RGB(51,102,153) from the preset colors WdColor.wdColorLightBlue and WdColor.wdColorBlue. It is like mixing color and creating a new color.
The amazing thing in computers is you can subtract colors, This is how we created RGB(51,102,153).


WdColor.wdColorLightBlue -WdColor.wdColorBlue*2/5 which means


RGB(51,102,255) – RGB(0,0,255)*2/5
= RGB(51, 102,255 – 255*2/5)
=RGB(51,102,153)

So finally we were able to get the color we wanted by subtracting two colors