sendur

Hello - I'am working on a Word Add-In project. We are converting the document to HTML for further processing by our application. Until Word 2007 everything worked fine. But when the users select a color from the ThemeColor for table border in Word 2007, the Border.Color property gives a strange negative value. (In case of black the value is "border.Color = -587137025"). I'am unable to map this color back to RGB equivalents. Is there any class / method for getting this converted back to RGB The same thing is true for any color selected from the Theme Color Palette.

If a proper RGB color is selected the program still works properly. Any suggestion would be appreciated !!

Thanks



Re: Visual Studio Tools for Office Getting Hex Color from Word Theme color

Ji Zhou ¨C MSFT

Hi,

I use calc.exe in Windows and I see -587137025 is DD00FFFF in Hex. The Color class stores a color's RGB component values as an integer in the AARRGGBB format. The two most significant bytes represent the color's alpha value, followed by the red, green, and blue color component values. I think DD stands for alpha value, and 00FFFF is the Color's RGB you want. It seems that you use a signed integer variable to represent the color, so it will be a negative value. You can write some codes to translate it manually.

Thanks

Ji






Re: Visual Studio Tools for Office Getting Hex Color from Word Theme color

Phil Hoff - MSFT

While it is technically a valid RGB value--in this case, yellow--it is not the true color of the border. The value actually represents a particular color and tint/shade combination within the current document theme. Unfortunately, the Office group has not (yet) publicly documented how to translate this value back to the true color.

-Phil

(I don't know what method you use to translate the colors, but System.Drawing.ColorTranslator.FromOle() is handy for this purpose.)





Re: Visual Studio Tools for Office Getting Hex Color from Word Theme color

Ji Zhou ¨C MSFT

Hi Phil,

I find something describe the difference between Color in .NET Framework and COM in a MSDN article. It says:

Because the object model for Excel 2007 is COM-based, the ColorScaleCriterion.FormatColor.Color property expects a color value as an integer with the color components in the 00BBGGRR order. Trying to set the ColorScaleCriterion.FormatColor.Color property to a value returned from a Color object's ToArgb() method does not work because the bytes for the color's red and blue components are swapped. You could create a C# method that would be the equivalent of the Visual Basic RGB function, but for the purposes of this article, the code simply uses hard-coded values.

Original link is: http://msdn2.microsoft.com/en-us/library/bb404903.aspx

Is this what you say: it is not the true color of the border If yes, I think the we can find some way to translate the color to the true one. Or maybe I am missing something. :-)

Best Regards,

Ji






Re: Visual Studio Tools for Office Getting Hex Color from Word Theme color

Phil Hoff - MSFT

You're right in that the encoding used by System.Drawing.Color is not the same as that used by the Office object model. However, the ColorTranslator class can be used to perform the conversion between the two encodings. That said, when some aspect of an Office document is set to one of the document's theme colors, the value returned by the Color property for that aspect will not be the color as seen on the screen. It is not simply a difference in RGB encoding; Office is using (at least) the upper bytes of the value to indicate which color and tint/shade combination within the document's current theme was chosen for that aspect. That is, the value is not a color in the sense of "the RGB value for light red" so much as it is "the first accent color of the current theme plus 10% tint". However, Office has not publicly released information about how to map such values back to the color as seen on the screen.

-Phil