Articles in this section
Category / Section

How to apply borders for the merge cells programmatically at runtime in WinForms Spreadsheet (SfSpreadsheet)?

1 min read

Set the cell borders for merged cell

WinForms Spreadsheet provides support to set the cell borders for merged cells programmatically at runtime.

Cell Merging

For merging the cells, you need to add the CoveredCellInfo into CoveredCells collection of SpreadsheetGrid in WorkbookLoaded event and merge the range using Merge method in XlsIO.

C#

spreadsheet.WorkbookLoaded += Spreadsheet_WorkbookLoaded;
private void Spreadsheet_WorkbookLoaded(object sender, WorkbookLoadedEventArgs args)
{
    var worksheet = spreadsheet.Workbook.Worksheets[0];
    var coveredcell = new CoveredCellInfo(8, 8, 11, 11);
    spreadsheet.ActiveGrid.CoveredCells.Add(coveredcell);
    var range = worksheet.Range[8, 8, 11, 11];
    range.Merge();
    spreadsheet.ActiveGrid.InvalidateCell(GridRangeInfo.Cells(8,8,11,11),false);
}

Border settings

Border can be applied by setting LineStyle and Color property of IBorders to the merged range.

C#

var worksheet = spreadsheet.Workbook.Worksheets[0];
var cell = worksheet.Range[8, 8, 11, 11];
//Apply border for the cell
cell.Borders.LineStyle = ExcelLineStyle.Thick;
cell.Borders.Color = ExcelKnownColors.Red;
spreadsheet.ActiveGrid.InvalidateCell(cell.Row, cell.Column);

Samples:

WPF

WinForms

UWP

Conclusion

I hope you enjoyed learning about how to apply borders for the merge cells programmatically at runtime in WinForms Spreadsheet (SfSpreadsheet).

You can refer to our WinForms Spreadsheet’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms Spreadsheet documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms Spreadsheet and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied