Free Support Forum - aspose.com

Problem writting border

Hi,
I got a problem writting borders. When cells have already borders from the outside, in some case it doesn’t work.
Better than words, here is my sample :
Cell 1,1 (B2) must finally have double border -> it’s working
Cell 1,4 (E2) must finally have medium border -> it’s NOT working

What I suppose : it’s working only when new Aspose.Cells.CellBorderType is > to old Aspose.Cells.CellBorderType (in my case Medium<Double)

Dim oWorkbook As Aspose.Cells.Workbook = New Aspose.Cells.Workbook
Dim oWorkSheet As Aspose.Cells.Worksheet = oWorkbook.Worksheets(0)
’ Working sample
’ lines outside
oWorkSheet.Cells(0, 1).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(0, 1).Style.Borders(Aspose.Cells.BorderType.BottomBorder).Color = Color.Black
oWorkSheet.Cells(2, 1).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(2, 1).Style.Borders(Aspose.Cells.BorderType.TopBorder).Color = Color.Black
oWorkSheet.Cells(1, 0).Style.Borders(Aspose.Cells.BorderType.RightBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(1, 0).Style.Borders(Aspose.Cells.BorderType.RightBorder).Color = Color.Black
oWorkSheet.Cells(1, 2).Style.Borders(Aspose.Cells.BorderType.LeftBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(1, 2).Style.Borders(Aspose.Cells.BorderType.LeftBorder).Color = Color.Black
’ lines inside
oWorkSheet.Cells(1, 1).Style.Borders(Aspose.Cells.BorderType.LeftBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(1, 1).Style.Borders(Aspose.Cells.BorderType.LeftBorder).Color = Color.Black
oWorkSheet.Cells(1, 1).Style.Borders(Aspose.Cells.BorderType.RightBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(1, 1).Style.Borders(Aspose.Cells.BorderType.RightBorder).Color = Color.Black
oWorkSheet.Cells(1, 1).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(1, 1).Style.Borders(Aspose.Cells.BorderType.TopBorder).Color = Color.Black
oWorkSheet.Cells(1, 1).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(1, 1).Style.Borders(Aspose.Cells.BorderType.BottomBorder).Color = Color.Black
’ Not Working sample
’ lines outside
oWorkSheet.Cells(0, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(0, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).Color = Color.Black
oWorkSheet.Cells(2, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(2, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).Color = Color.Black
oWorkSheet.Cells(1, 3).Style.Borders(Aspose.Cells.BorderType.RightBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(1, 3).Style.Borders(Aspose.Cells.BorderType.RightBorder).Color = Color.Black
oWorkSheet.Cells(1, 5).Style.Borders(Aspose.Cells.BorderType.LeftBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(1, 5).Style.Borders(Aspose.Cells.BorderType.LeftBorder).Color = Color.Black
’ lines inside
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.LeftBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.LeftBorder).Color = Color.Black
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.RightBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.RightBorder).Color = Color.Black
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).Color = Color.Black
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).Color = Color.Black
’ Save
oWorkbook.Save(“c:\test.xls”)



It’s not working also for
_oWorkSheet.Cells.Rows(
and
_oWorkSheet.Cells.Columns(

With your code, all these two cells should have double border. It's correct.

Each cell only have one border. There isn't outside border or inside order. So later set border will override previous set border.

For rows and columns, I will add a new method to set styles.

ooops sorry wrong copy paste the not working code is :


        ' Not Working sample<br>

        ' lines outside<br>

        oWorkSheet.Cells(0,

4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle =
Aspose.Cells.CellBorderType.Double

        oWorkSheet.Cells(0, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).Color = Color.Black<br>

        oWorkSheet.Cells(2,

4).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle =
Aspose.Cells.CellBorderType.Double

        oWorkSheet.Cells(2, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).Color = Color.Black<br>

        oWorkSheet.Cells(1,

3).Style.Borders(Aspose.Cells.BorderType.RightBorder).LineStyle =
Aspose.Cells.CellBorderType.Double

        oWorkSheet.Cells(1, 3).Style.Borders(Aspose.Cells.BorderType.RightBorder).Color = Color.Black<br>

        oWorkSheet.Cells(1,

5).Style.Borders(Aspose.Cells.BorderType.LeftBorder).LineStyle =
Aspose.Cells.CellBorderType.Double

        oWorkSheet.Cells(1, 5).Style.Borders(Aspose.Cells.BorderType.LeftBorder).Color = Color.Black<br>

        ' lines inside<br>

        oWorkSheet.Cells(1,

4).Style.Borders(Aspose.Cells.BorderType.LeftBorder).LineStyle =
Aspose.Cells.CellBorderType.Medium

        oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.LeftBorder).Color = Color.Black<br>

        oWorkSheet.Cells(1,

4).Style.Borders(Aspose.Cells.BorderType.RightBorder).LineStyle =
Aspose.Cells.CellBorderType.Medium

        oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.RightBorder).Color = Color.Black<br>

        oWorkSheet.Cells(1,

4).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle =
Aspose.Cells.CellBorderType.Medium

        oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).Color = Color.Black<br>

        oWorkSheet.Cells(1,

4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle =
Aspose.Cells.CellBorderType.Medium

        oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).Color = Color.Black<br>


It keeps Double but it must be medium


I know there is no ‘outside’ or ‘inside’ border, it was only to explain it.



for rows and columns it’s exactly the same problem (working one way and not the other one)

When setting Cell(1,4) border to Medium style, it should turn cell(1,3) right border to Medium style. That should also apply to other adjacent cells.

However, Aspose.Cells doesn't do this action as MS Excel because this action is a time and memory consuming routine. If there are many cells with Style settings, this action will degrade performance heavily. So Aspose.Cells doesn't merge them and leave you to do it.

Actually in your sample code, you can:

1. Don't set outside border.

Or

2. Reset outside border to none.

' lines outside
oWorkSheet.Cells(0, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(0, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).Color = Color.Black
oWorkSheet.Cells(2, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(2, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).Color = Color.Black
oWorkSheet.Cells(1, 3).Style.Borders(Aspose.Cells.BorderType.RightBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(1, 3).Style.Borders(Aspose.Cells.BorderType.RightBorder).Color = Color.Black
oWorkSheet.Cells(1, 5).Style.Borders(Aspose.Cells.BorderType.LeftBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(1, 5).Style.Borders(Aspose.Cells.BorderType.LeftBorder).Color = Color.Black

'reset outside lines

oWorkSheet.Cells(0, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle = Aspose.Cells.CellBorderType.None
oWorkSheet.Cells(2, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle = Aspose.Cells.CellBorderType.None
oWorkSheet.Cells(1, 3).Style.Borders(Aspose.Cells.BorderType.RightBorder).LineStyle = Aspose.Cells.CellBorderType.None
oWorkSheet.Cells(1, 5).Style.Borders(Aspose.Cells.BorderType.LeftBorder).LineStyle = Aspose.Cells.CellBorderType.None

' lines inside
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.LeftBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.LeftBorder).Color = Color.Black
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.RightBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.RightBorder).Color = Color.Black
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).Color = Color.Black
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).Color = Color.Black

>1. Don't set outside border or 2. Reset outside border to none.

I don't think that's the problem forget the outside and inside border
To simplfy the code just keep :
' Working sample
oWorkSheet.Cells(0, 1).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle = Aspose.Cells.CellBorderType.Medium
oWorkSheet.Cells(1, 1).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle = Aspose.Cells.CellBorderType.Double
' Not Working sample
oWorkSheet.Cells(0, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle = Aspose.Cells.CellBorderType.Medium

One time I set medium and then double it's working (medium<double)
The other time I set double and then medium and it's NOT working (double>medium)

When you use the following code:

' Not Working sample
oWorkSheet.Cells(0, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle = Aspose.Cells.CellBorderType.Double
oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle = Aspose.Cells.CellBorderType.Medium

Actually we saved Cell(0,4) as Double and Cell(1,4) as Medium. However, since it's a same border, MS Excel only display one settings and it always shows Double.

To make it work, you can try:

' Not Working sample
oWorkSheet.Cells(0, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle = Aspose.Cells.CellBorderType.Double

oWorkSheet.Cells(0, 4).Style.Borders(Aspose.Cells.BorderType.BottomBorder).LineStyle = Aspose.Cells.CellBorderType.None

oWorkSheet.Cells(1, 4).Style.Borders(Aspose.Cells.BorderType.TopBorder).LineStyle = Aspose.Cells.CellBorderType.Medium