[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Collapse]Office File API
  Demo Application
  Redistribution and Deployment
 [Collapse]Spreadsheet Document API
   Product Structure
   Getting Started
  [Expand]Spreadsheet Document
   Supported Formats
  [Expand]Cell Basics
   Defined Names
   Data Binding
  [Expand]Pivot Tables
  [Expand]Charts and Graphics
  [Expand]Mail Merge
   [Expand]Rows and Columns
   [Expand]Import and Export Data
   [Expand]Data Binding
   [Expand]Mail Merge
   [Collapse]Formatting Cells
     How to: Apply a Style to a Cell or Range of Cells
     How to: Create or Modify a Style
     How to: Format a Cell or Range of Cells
     How to: Apply Rich Formatting to Cell Text
     How to: Specify Number or Date Format for Cell Content
     How to: Change Cell Font and Background Color
     How to: Configure Cell Font Settings
     How to: Align Cell Content
     How to: Add and Remove Cell Borders
     How to: Clear Cell Formatting
   [Expand]Conditional Formatting
   [Expand]Group Data
   [Expand]Filter Data
   [Expand]Pivot Tables
 [Expand]Word Processing Document API
 [Expand]PDF Document API
 [Expand]Excel Export Library
 [Expand]Snap Report API
 [Expand]Zip Compression and Archive API
 [Expand]Barcode Generation API
 [Expand]Unit Conversion API
 [Expand]API Reference
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Add and Remove Cell Borders

To access and specify cell borders, use the Borders collection. To access this collection in an individual cell, use the Cell object's Formatting.Borders property, which is inherited form the Formatting interface. To change the borders of a range of cells, call the Range.BeginUpdateFormatting method for this range, and use the Borders property of the returned Formatting object to access and modify the Borders collection. Then call the Range.EndUpdateFormatting method to finalize the modification.

Each border of a cell is accessed via the corresponding property of the Borders collection and represented by the Border object. This object provides the Border.LineStyle and Border.Color properties, allowing you to specify border line style and color, respectively. The BorderLineStyle enumerator lists the available line styles. The border color is defined by the System.Drawing.Color value.

Use the following properties and methods to specify each particular border of a cell or cell range, or set several borders at once (for example, all outside, inside, vertical or horizontal borders).

To share the same cell border settings between multiple cells in one step, create or modify a style with the Formatting.Borders property specified as required, and assign this style to Range.Style for the desired cells.

This example demonstrates how to specify different borders for individual cells and ranges of cells by modifying the Borders object.

The image below shows which borders are applied to cells after executing the code above (the workbook is opened in Microsoft® Excel®).

Is this topic helpful?​​​​​​​