Aspose.Cells Setting Custom Colours


#1

Hi,

I am wondering if you could please help me - I am going crazy over this... I am using Aspose.Cells, and I want to set 3 different CUSTOM background colours in my Excel spreadsheet.

excel.Styles[0].ForegroundColor = ColorTranslator.FromHtml("#CCCC99");

Something strange seems to be happening (prehaps I do not fully understand how to use the ChangePalette). As far as I am aware the Palette needs to be reset every time you change the colour. Can you set multiple custom background colours on one Excel spreadsheet and how do u reset the palette each time? I seem to always get one or more of the colours overriding the other colours.

Please help

Sarah


#2

Hi Sarah,

Please check http://www.aspose.com/Wiki/default.aspx/Aspose.Cells/ColorAndPalette.html .

MS Excel can only contain 56 different colors in a single Excel file. Aspose.Cells provides a default 56 colors palette same as MS Excel.

If you want to set different custom colors, please carefully put them at the right places in the palette.

For example, if you want to put 3 different custom colors in a file: #CCCC99, #CC99CC, #99CCCC, please try:

excel.ChangePalette(ColorTranslator.FromHtml("#CCCC99"), 55);

excel.ChangePalette(ColorTranslator.FromHtml("#CC99CC"), 54);

excel.ChangePalette(ColorTranslator.FromHtml("#99CCCC"), 53);

excel.Styles[0].ForegroundColor = ColorTranslator.FromHtml("#CCCC99");

excel.Styles[0].Pattern = BackgroundType.Solid;

......

Or you can use Excel.GetMatchingColor method to get a matching color in the standard color palette.