Background problem on excel tab or conditionnal formatting

Hi,

I would like to dynamically set the background color of an excel tab to orange but in the generated exel document, the tab has no color.

If I try to set the color of this same tab to red, green or blue, it’s ok.

Can you tell me why I can’t use others color than red, green or blue when I want to set the color of a tab ?

I have the same problem when I set conditionnal formatting on excel cell using the following code :

FormatConditions fcs = worksheet.ConditionalFormattings[worksheet.ConditionalFormattings.Add()];
fcs.AddArea(new CellArea { StartRow = 1, StartColumn = 1, EndRow = 1, EndColumn = 1});
int conditionIndex = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.GreaterThan, “$B$1”, null);
fcs[conditionIndex].Style.BackgroundColor = Color.Orange;
fcs[conditionIndex].Style.Pattern = BackgroundType.Solid;

The cells remains blank.

Thanks in advance for your help


Hi,

For your information, MS Excel (97-2003) standard color palette has only 56 colors, and if you need to apply custom colors for different objects, you need to add these colors to the MS Excel standard color palette first. It is to be noted here, if you save the file in MS Excel 2007 format e.g XLSX, then you don’t need to do that.

See the sample code:

1)
Workbook workbook = new Workbook();
workbook.ChangePalette(Color.Orange, 55);
Worksheet worksheet = workbook.Worksheets[0];
worksheet.TabColor = Color.Orange;
workbook.Save(“e:\test\tabcolors.xls”);

2)

workbook.ChangePalette(Color.Orange, 55);
Worksheet worksheetDataEntry = workbook.Worksheets[0];
int conditionalFormattingIndex = worksheetDataEntry.ConditionalFormattings.Add();
FormatConditions formatConditions = worksheetDataEntry.ConditionalFormattings[conditionalFormattingIndex];
CellArea cellArea = new CellArea();
cellArea.StartColumn = 0;
cellArea.StartRow = 3;
cellArea.EndColumn = 10;
cellArea.EndRow = 100;

formatConditions.AddArea(cellArea);

int formatConditionIndex = formatConditions.AddCondition(FormatConditionType.Expression, OperatorType.None, “=AND(LEN(T($A4))>0,LEN(T($B4))>0)”, null);
FormatCondition formatCondition = formatConditions[formatConditionIndex];
formatCondition.Style.BackgroundColor = Color.Orange;
formatCondition.Style.Pattern = BackgroundType.Solid;


workbook.Save(“e:\test\condformat.xls”);


For complete reference, please see the document: http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/colors-and-palette.html

Thank you.