ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Color Mismatch from System.Drawing.Color (https://www.excelbanter.com/excel-programming/399174-color-mismatch-system-drawing-color.html)

[email protected]

Color Mismatch from System.Drawing.Color
 
Hi,
i setting the interior color of a cell in excel from a C# code and when i
see the result in excel the color is not matching. The color i start from is
RED and the result in the produced Excel document is BLUE.

My question is, how do i set the Color property of the interior of a cell
from a System.Drawing.Color instance... Here is what i tried...

Microsoft.Office.Interop.Excel.Range rng = sheet.Cells[Row, Col] as
Microsoft.Office.Interop.Excel.Range;
rng.Interior.Color = (interiorCellColor.Value.R << 16) |
(interiorCellColor.Value.G << 8) | interiorCellColor.Value.B;

I also tried the ToArgb method with the same result...

I will take any theory explaining the difference in color from what i start
from and the result in excel.

Remi

[email protected]

Color Mismatch from System.Drawing.Color
 
Ok, i think i got it:
rng.Interior.Color = (interiorCellColor.Value.B << 16) |
(interiorCellColor.Value.G << 8) | interiorCellColor.Value.R;

I think i just misplaced the values, which definitely dont make much sense
to me anyway...

Any comments ?

" wrote:

Hi,
i setting the interior color of a cell in excel from a C# code and when i
see the result in excel the color is not matching. The color i start from is
RED and the result in the produced Excel document is BLUE.

My question is, how do i set the Color property of the interior of a cell
from a System.Drawing.Color instance... Here is what i tried...

Microsoft.Office.Interop.Excel.Range rng = sheet.Cells[Row, Col] as
Microsoft.Office.Interop.Excel.Range;
rng.Interior.Color = (interiorCellColor.Value.R << 16) |
(interiorCellColor.Value.G << 8) | interiorCellColor.Value.B;

I also tried the ToArgb method with the same result...

I will take any theory explaining the difference in color from what i start
from and the result in excel.

Remi



All times are GMT +1. The time now is 05:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com