Hello,
Can any one let me know how to apply excel cell styles? http://msdn.microsoft.com/en-us/library/f1hh9fza(v=VS.100).aspx
Are you interested in adding the workbook styles specifically or are you just looking for a way to set the style of cells? If you want to add workbook styles, you can do something like this:
Workbook workbook = new Workbook(); Worksheet worksheet = workbook.Worksheets.Add("Sheet1"); IWorksheetCellFormat style = workbook.CreateNewWorksheetCellFormat(); style.Font.Name = "Verdana"; style.Font.Height = 240; style.Font.Color = System.Drawing.Color.Red; style.FillPatternForegroundColor = System.Drawing.Color.Gray; style.FillPattern = FillPatternStyle.Solid; workbook.Styles.AddUserDefinedStyle(style, "NewStyle"); WorksheetCell cell = worksheet.GetCell("A1"); cell.Value = "Test"; cell.CellFormat.SetFormatting(style); workbook.Save("Styles.xls");
But if you just want to change the style of a cell, you can do this:
Workbook workbook = new Workbook(); Worksheet worksheet = workbook.Worksheets.Add("Sheet1"); WorksheetCell cell = worksheet.GetCell("A1"); cell.Value = "Test"; cell.CellFormat.Font.Name = "Verdana"; cell.CellFormat.Font.Height = 240; cell.CellFormat.Font.Color = System.Drawing.Color.Red; cell.CellFormat.FillPatternForegroundColor = System.Drawing.Color.Gray; cell.CellFormat.FillPattern = FillPatternStyle.Solid; workbook.Save("Styles.xls");
When I apply the "SetFormatting" code you have listed in your example above (albeit aimed at WPF) using the Silverlight Infragistics.Excel library, the formatting does not get applied. Although I can see this custom style in the list of styles available to the worksheet, the text in the cell A1 does not have this style applied. Please advise.
Thank you.
Can you please let me know how to apply "Conditional Cell formatting".. If the value is > 5 then I want to apply a style..