Problems with style.ForegroundColor

Setting Cell.Style.ForegroundColor = Color.FromArgb(14, 88, 153) results in black colored cells. The color should come out blue. Is there a workaround for this?

Thanks.

Color 14,88,153 is not in the standard color palette. Please check Color and Palette.

So for your case, your code should be:

ExcelObj.ChangePalette(Color.FromArgb(14, 88, 153), 55)

Cell.Style.ForegroundColor = Color.FromArgb(14, 88, 153)

Cell.Style.Pattern = BackgroundType.Solid

Okay Laurence -

I have a generic routine called InsertCell - I am using the following code and I'm still getting black when I pass Color.FromArgb(14, 88, 153) to the "backgroundColor" parameter..

Here's the routine:

public void InsertCell(

int row,

int column,

object value,

bool isHeader,

TextAlignmentType alignment,

bool isTextWrapped,

bool isBold,

bool isFormula,

int indentLevel,

short fontSize,

Color fontColor,

Color backgroundColor,

string fontName

)

{

Cell cell = _currentSheet.Cells[row, column];

Aspose.Cells.Style style = cell.Style;

_excel.ChangePalette(backgroundColor, 55);

//setting default font properties on the whole column here

// so when the user edits or adds the font properties will match

//printOptions

_currentSheet.Cells.Columns[(byte) column].Style.Font.Name = fontName;

_currentSheet.Cells.Columns[(byte) column].Style.Font.Size = fontSize;

if(isFormula)

{

cell.Formula = value.ToString();

}

else

{

cell.PutValue(value);

}

if(indentLevel > 15)

indentLevel = 15;

style.IndentLevel = indentLevel;

if(isHeader)

{

fontColor = _printOptions.HeaderFontColor;

backgroundColor = _printOptions.HeaderBackgroundColor;

}

style.Font.IsBold = isBold;

style.Font.Color = fontColor;

style.Font.Size = fontSize;

style.VerticalAlignment = TextAlignmentType.Top;

style.HorizontalAlignment = alignment;

if(backgroundColor != Color.Empty)

{

style.Pattern = BackgroundType.Solid;

style.ForegroundColor = backgroundColor;

}

style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.None;

style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.None;

style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.None;

style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.None;

style.Font.Name = fontName;

if(isTextWrapped)

{

style.IsTextWrapped = true;

}

else

{

_currentSheet.AutoFitColumn(column);

}

}

What happens if you remove this piece of code?

if(isHeader)

{

fontColor = _printOptions.HeaderFontColor;

backgroundColor = _printOptions.HeaderBackgroundColor;

}

And when you call the InsertCell method, will background color be the same?

"What happens if you remove this piece of code?"

Same thing as before - the cell comes out black.

"And when you call the InsertCell method, will background color be the same? "

Not each time - thats the point of having it passed as an argument - so I can call one routine for formatting and entering values.. The deal is I have a PrintOptions class that allows our customers to set certain broad formatting (for instance the background color of a cell marked as a "header.")

So backgroundColor can change.. But I am not sure I understand your question.. I am assuming I answered correctly.

Also - it might be useful to know that if I pass in RGB values for colors which are "named" or "system" then it works fine.

Since the background color is not same, you should change the palette in other index, such as 54, 53... A palette can only contain 56 different colors. If a custom color is not added to the palette, it will show as black.

Aspose.Cells also provide a method to search a matching color in the palette then you can set color without change palette.

Following is the sample code:

public void InsertCell(

int row,

int column,

object value,

bool isHeader,

TextAlignmentType alignment,

bool isTextWrapped,

bool isBold,

bool isFormula,

int indentLevel,

short fontSize,

Color fontColor,

Color backgroundColor,

string fontName

)

{

Cell cell = _currentSheet.Cells[row, column];

Aspose.Cells.Style style = cell.Style;

//setting default font properties on the whole column here

// so when the user edits or adds the font properties will match

//printOptions

_currentSheet.Cells.Columns[(byte) column].Style.Font.Name = fontName;

_currentSheet.Cells.Columns[(byte) column].Style.Font.Size = fontSize;

if(isFormula)

{

cell.Formula = value.ToString();

}

else

{

cell.PutValue(value);

}

if(indentLevel > 15)

indentLevel = 15;

style.IndentLevel = indentLevel;

if(isHeader)

{

fontColor = _excel.GetMatchingColor(_printOptions.HeaderFontColor);

backgroundColor = _excel.GetMatchingColor(_printOptions.HeaderBackgroundColor);

}

style.Font.IsBold = isBold;

style.Font.Color = fontColor;

style.Font.Size = fontSize;

style.VerticalAlignment = TextAlignmentType.Top;

style.HorizontalAlignment = alignment;

if(backgroundColor != Color.Empty)

{

style.Pattern = BackgroundType.Solid;

style.ForegroundColor = _excel.GetMatchingColor(backgroundColor);

}

style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.None;

style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.None;

style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.None;

style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.None;

style.Font.Name = fontName;

if(isTextWrapped)

{

style.IsTextWrapped = true;

}

else

{

_currentSheet.AutoFitColumn(column);

}

}