I think there are some problems with style handling in Aspose.Cells v4.4.3.2. I prepared a test case, the code is below.
The code tries to set some cells background-color and border-color independently. If the code is executed…
- Cells F5, G5, H5, I5, J5 do not have a border color.
- Almost all cells from rows 7, 8, 9 do not have a border color. Actually only cell A7 has a border color.
I think the following would have been correct.
- All cells from columns A-J should have a border color.
- All cells between A1 and E3 should have a background color.
- All cells from rows 7,8,9 should have a background color.
Michael G. Schneider
’’ Create Workbook and Worksheet
Dim oWorkbook As New Aspose.Cells.Workbook
Dim oWorksheet As Aspose.Cells.Worksheet = oWorkbook.Worksheets.Item(0)
’’ Colors for Background (BGR) and Border (BRD)
Dim iColorBGR As System.Drawing.Color = oWorkbook.Colors(18)
Dim iColorBRD As System.Drawing.Color = oWorkbook.Colors(14)
’’ Style for Border
Dim oStyleBRD As Aspose.Cells.Style = oWorkbook.Styles.Item(oWorkbook.Styles.Add)
Dim oStyleFlagBRD As New Aspose.Cells.StyleFlag
oStyleBRD.Name = "BRD"
oStyleBRD.Borders.SetColor(iColorBRD)
oStyleBRD.Borders.SetStyle(Aspose.Cells.CellBorderType.Thin)
oStyleFlagBRD.TopBorder = True
oStyleFlagBRD.RightBorder = True
oStyleFlagBRD.BottomBorder = True
oStyleFlagBRD.LeftBorder = True
’’ Style for Background
Dim oStyleBGR As Aspose.Cells.Style = oWorkbook.Styles.Item(oWorkbook.Styles.Add)
Dim oStyleFlagBGR As New Aspose.Cells.StyleFlag
oStyleBGR.Name = "BGR"
oStyleBGR.ForegroundColor = iColorBGR
oStyleBGR.Pattern = Aspose.Cells.BackgroundType.Solid
oStyleFlagBGR.CellShading = True
’’ Apply BorderColor to Columns A - J
Dim iRow As Integer
Dim oRange As Aspose.Cells.Range
Dim oRow As Aspose.Cells.Row
Dim iColumn As Integer
Dim oColumn As Aspose.Cells.Column
For iColumn = 0 To 9
oColumn = oWorksheet.Cells.Columns.Item(iColumn)
oColumn.ApplyStyle(oStyleBRD, oStyleFlagBRD)
Next
’’ Apply BackgroundColor to Range
oRange = oWorksheet.Cells.CreateRange(0, 0, 3, 5)
oRange.ApplyStyle(oStyleBGR, oStyleFlagBGR)
’’ Apply BackgroundColor to single Row
oRow = oWorksheet.Cells.Rows.Item(4)
oRow.ApplyStyle(oStyleBGR, oStyleFlagBGR)
’’ Apply BackgroundColor to several Rows
For iRow = 6 To 8
oRow = oWorksheet.Cells.Rows.Item(iRow)
oRow.ApplyStyle(oStyleBGR, oStyleFlagBGR)
Next
’’ Save Workbook
oWorkbook.Save(“C:\temp\aspose\style-test.xls”)