I am writing some data from database to the excel via visual basic.net.I need to change background of some cells and also need to make text bold. I need something like that :
xlWorkSheet.Cells(rownumber, 1).BackgroundColor = Color.Yellow
xlWorkSheet.Cells(rownumber, 1).Font.isBold = True
Of course none of above is works.How can I achieve this? Thanks..
You need to create a Excel.Style object, and apply that to a range. Like this:
Dim style As Excel.Style = xlWorkSheet.Application.ActiveWorkbook.Styles.Add("NewStyle")
style.Font.Bold = True
style.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow)
xlWorkSheet.Cells(rownumber, 1).Style = "NewStyle"
This worked perfect for me.
xlsWorkSheet.Cells(row, column).interior.color = Color.Green
Thats few declaration that can help you for style an Excel
For color palette:
http://dmcritchie.mvps.org/excel/colors.htm
Dim xlsCell As Excel.Range
xlsCell = xlWorkSheet.Range("A1")
xlsCell.Range("A5").Value = "TEXT"
With xlsCell.Range("A12:J12")
.Merge()
.Borders(XlBordersIndex.xlEdgeBottom).Weight = 2
.Borders(XlBordersIndex.xlEdgeTop).Weight = 2
.Borders(XlBordersIndex.xlEdgeLeft).Weight = 2
.Borders(XlBordersIndex.xlEdgeRight).Weight = 2
.Borders(XlBordersIndex.xlInsideHorizontal).Weight = 2
.Borders(XlBordersIndex.xlInsideVertical).Weight = 2
.Interior.ColorIndex = 15
.WrapText = True
.Font.Name = "Arial"
.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter
.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft
End With
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With