Problem with Styles- not applied consistently

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”)

Hi,

Could you try the attached version.

The following conditions should be implemented.

  • All cells between A1 and E3 should have a background color.
  • All cells from rows 7,8,9 should have a background color.
  • Related borders, we will check the issue soon.

    Thank you.

    Thank’s a lot for the answer.

    This is a dotnet runtime v1 version? It would be good, if always both versions of the DLL were posted here in the forum. It would be even better, if they were not posted at all, but saved at a central location where they could then be downloaded. That way we could find new versions without searching through the forum.

    Also with Aspose.Cells v4.4.3.2 - that is the version that I used today - the background color has been correct in all cases. It has been the border color which is not handled correctly by Aspose.Cells. The problems were

    • 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.

    Also with this new v4.4.3.13 these problems can be seen.

    Michael G. Schneider

    Hi Michael,

    Well, we will fix the borders formatting issue and provide you the .NET 2.0 fix soon.

    Keep in touch. Thanks.

    Hi,

    Please try this fix.

    Hello Warren,

    thanks a lot. The error is gone now.

    Michael G. Schneider