How can I get a solid background color?

I have promised a customer that with your product I could create a spreadsheet that has the background colors of a style that they currently use. In fact they downloaded the spreadsheet from another web site that also creates spreadsheets from database tables.

The worksheet cells A1 to A5 and C1 to C5 have a very pleasant light blue background color, with no pattern. When I open up the spreadsheet they sent me in Excel 2003 and look at Cell Formatting there is nothing in the Pattern and just a Color is picked.

Originally I tried to simply copy a template created from that sample worksheet that had only Styles, Formatting and Headings into my Aspose workbook, but only the Headings came with it. None of the colors or font styles were imported.

Also, so far I have been able to get only the basic colors to even show up, like Red, Yellow or Blue. I would like to try SlateBlue, Beige or even LightBlue, but none of those colors seem to work, even with BackgroundType.Gray75.

When I try to set the Style.Pattern = BackgroundType.Solid I don't get any color at all. When I choose BackgroundType.Gray75 I get an ugly dot pattern. Is there any way with Aspose.Cells 4.4 that I can get a nice solid color in my cells?

Thank you

Could you please post your sample file here?
How do you copy the template? I think those colors are not in the standard color palette. So you have to add those color to the palette with code. Please check

for reference.

Here is my code where I copy the worksheet from the template XLS. I was hoping that the copy would include the formatting of the cells, colors and fonts, but all that came over was the data in the proper cells. So, as below, I tried to put some color into the cells that had color in the template. Note that I used Beige which showed up in the "common" tab of selectable colors in Visual Studio intellisense, but that color doesn't work.

Protected Sub GetSummarySheet()
'Create a Workbook.
Dim WBKsummary As Workbook = New Workbook()
'Create another Workbook.
'Open template
Dim path As String = System.Web.HttpContext.Current.Server.MapPath("~")
path = path.Substring(0, path.LastIndexOf("\"))
path += "\ExcelTemplates\ClientSummary.xls"
WBKsummary.Open(path)
Dim ws0 As Aspose.Cells.Worksheet = WBKsummary.Worksheets(0)
Dim i As Integer
For i = 0 To 7
ws0.Cells(0, i).Style.Pattern = BackgroundType.Gray75
ws0.Cells(0, i).Style.BackgroundColor = Color.Yellow
ws0.Cells(1, i).Style.Pattern = BackgroundType.Gray75
ws0.Cells(1, i).Style.BackgroundColor = Color.Yellow
ws0.Cells(2, i).Style.Pattern = BackgroundType.Gray75
ws0.Cells(2, i).Style.BackgroundColor = Color.Beige
Next
Dim excelWorkbook1 As Workbook = New Workbook()
'Copy the first sheet of the first book into second book.
excelWorkbook1.Worksheets(0).Copy(ws0)
excelWorkbook1.Worksheets(0).Cells("F224").Formula = "=SUM(F4:F223)"
excelWorkbook1.Worksheets(0).Cells("A225").PutValue("DeckSummary1")

'Save the file.
excelWorkbook1.Save("DeckSummary.xls", FileFormatType.Default, SaveType.OpenInExcel, System.Web.HttpContext.Current.Response)


End Sub

I have attached the template XLS with some data in it.

Hi,

Thanks for considering Aspose.

Well, the Beige color is not in the Excel standard color palette. So you have to add color to color palette.

I tried the following code and it works fine. Attached is the output file.

E.g.,

'Create a Workbook.
Dim WBKsummary As Workbook = New Workbook
'Create another Workbook.
'Open template

WBKsummary.Open("d:\test\ClientSummary.xls")
WBKsummary.ChangePalette(Color.Beige, 55)
Dim ws0 As Aspose.Cells.Worksheet = WBKsummary.Worksheets(0)
Dim i As Integer
For i = 0 To 7
ws0.Cells(0, i).Style.Pattern = BackgroundType.Gray75
ws0.Cells(0, i).Style.BackgroundColor = Color.Yellow
ws0.Cells(1, i).Style.Pattern = BackgroundType.Gray75
ws0.Cells(1, i).Style.BackgroundColor = Color.Yellow
ws0.Cells(2, i).Style.Pattern = BackgroundType.Gray75
ws0.Cells(2, i).Style.BackgroundColor = Color.Beige
Next
Dim excelWorkbook1 As Workbook = New Workbook
excelWorkbook1.ChangePalette(Color.Beige, 55)
'Copy the first sheet of the first book into second book.
excelWorkbook1.Worksheets(0).Copy(ws0)
excelWorkbook1.Worksheets(0).Cells("F224").Formula = "=SUM(F4:F223)"
excelWorkbook1.Worksheets(0).Cells("A225").PutValue("DeckSummary1")

'Save the file.
excelWorkbook1.Save("d:\test\DeckSummary.xls")

And by the way, for further reference about setting foreground and background colors, please check the thread: <A href="</A></P> <P>Thank you.</P> <P> </P>

Thanks Amjad,

While reading the link you supplied to another discussion about color in Excel, I began to understand the reason for my confusion and that of others who have experience in Web development and not so much with Excel.

An Excel spreadsheet can be created in HTML using tables and then setting the header information to indicate a document of type Excel and then placing an XLS extension onto the end of the filename.

When coloring the Table cells, to get a fill-color the Background-Color CSS attribute is used. To get the Font color in the Table Cell you use the Color CSS attribute. There is no font-color property in CSS.

Everyone new to Aspose (and Excel) should be told that to set a cell "background color", the ForegroundColor property is the one to set.

Also they should be told that the Excel workbook color palette does NOT equal the Common colors in Visual Studio.

Thanks for the help.