Search code examples
c#.netexcelgembox-spreadsheet

How can I use 2 MultipleBorders option in GemBox


I can use an inside border line style and an outside line style, but I don't know how I can use both.

As in this picture:

Excel borders

I am using C# and GemBox.Spreadsheet

//inside border
for (int line = 0; line < Projectsource.Count(); line++) //바깥border과 안쪽 얇은 border 같이 쓰면 안됨
{
    for (int j = 0; j < 14; j++)//안쪽 cell border 얇게
    {
        worksheet.Cells[line, j].Style.Borders.SetBorders(
            MultipleBorders.Outside, SpreadsheetColor.FromArgb(255, 0, 0), LineStyle.Thin);
    }
}

//outside border
//style.Borders.SetBorders(
//    MultipleBorders.Outside, SpreadsheetColor.FromArgb(140, 120, 50), LineStyle.Thick);//바깥쪽 border 두껍게 성공

worksheet.Cells.GetSubrange("A2:N762").Style = style;

Solution

  • Note that MultipleBorders is a flag enum which means that you can use bitwise operators with it.

    So, here is how you can set both inside and outside borders with the newer versions of GemBox.Spreadsheet:

    worksheet.Cells.GetSubrange("A2:N762").Style.Borders.SetBorders(
        MultipleBorders.Inside | MultipleBorders.Outside,
        SpreadsheetColor.FromArgb(255, 0, 0),
        LineStyle.Thin);
    

    Or you could use this instead:

    worksheet.Cells.GetSubrange("A2:N762").Style.Borders.SetBorders(
        MultipleBorders.All,
        SpreadsheetColor.FromArgb(255, 0, 0),
        LineStyle.Thin);
    

    However, as you already noticed that older version (GemBox.Spreadsheet 3.9) doesn't have MultipleBorders.Inside. Also, even though it does have MultipleBorders.All, the behavior is different.

    Nevertheless, here is how to set the desired borders with those older versions of GemBox.Spreadsheet:

    foreach (var cell in worksheet.Cells.GetSubrange("A2:N762"))
        cell.Style.Borders.SetBorders(
            MultipleBorders.Outside,
            SpreadsheetColor.FromArgb(255, 0, 0),
            LineStyle.Thin);