Problem with ForegroungColor

Hi,

I want to use custom color in my Excel file but I have a problem. I do not see color in Excel file but I had it when I converted Excel into Pdf. So I thought that Excel do not support this color but I tried to set the same color in Excel and I was able to see correct color.

I did not attach my template because it is just a clean xls file without any settings.

There is my sample code
Workbook wb = new Workbook();
wb.Open(“C:\template.xls”);

Worksheet sheet = wb.Worksheets[0];
sheet.Cells[0, 0].PutValue(“sample text”);
sheet.Cells[0, 0].Style.ForegroundColor = System.Drawing.Color.FromArgb(201, 233, 255);
sheet.Cells[0, 0].Style.Pattern = BackgroundType.Solid;

//commented line to get the same file in Excel format
///wb.Save(“c:\sample.xls”, FileFormatType.Excel2003);

wb.Save(“c:\toPdf.xml”, FileFormatType.AsposePdf);
Aspose.Pdf.Pdf pdf1 = new Aspose.Pdf.Pdf();
pdf1.BindXML(“c:\toPdf.xml”, null);

pdf1.Save(“c:\SamplePdf.pdf”);

Regards,
Sergey Roznikov.

Hi Sergey,

Thank you for considering Aspose.

As you are trying to use a custom color which is not in the standard palette of the colors, you have to add this color to the color palette before using it. You can use ChangePalette(System.Drawing.Color,index) method to add your color to the palette. Please see the following sample code which will help you get your desired results.
Sample Code:

Workbook wb = new Workbook();

wb.Open("C:\\output1.xls");

wb.ChangePalette(System.Drawing.Color.FromArgb(201, 233, 255), 55);

Worksheet sheet = wb.Worksheets[0];

sheet.Cells[0, 0].PutValue("sample text");

sheet.Cells[0, 0].Style.ForegroundColor = System.Drawing.Color.FromArgb(201, 233, 255);

sheet.Cells[0, 0].Style.Pattern = BackgroundType.Solid;

wb.Save("c:\\sample.xls", FileFormatType.Excel2003);

Thank you & Best Regards,

Hi,

Thanks a lot.
I see that I have to read documentation more carefully.

Regards,
Sergey Roznikov.