Interface IBorder
Represents the border of an object.
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.Portable.dll
Syntax
public interface IBorder : IParentApplication
Properties
Color
Returns or sets a color of the border from ExcelKnownColors enumeration.
Declaration
ExcelKnownColors Color { get; set; }
Property Value
Type |
---|
ExcelKnownColors |
Examples
The following code illustrates how to set a color from ExcelKnownColors enumeration to the border.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
//Set borders
IBorders borders = worksheet["C2"].Borders;
//Set border color
borders[ExcelBordersIndex.EdgeTop].Color = ExcelKnownColors.Red;
borders[ExcelBordersIndex.EdgeBottom].Color = ExcelKnownColors.Blue;
//Set line style
borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thick;
borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thick;
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
}
ColorObject
Returns or sets the primary color of the object.
Declaration
ColorObject ColorObject { get; }
Property Value
Type |
---|
ColorObject |
Examples
The following code illustrates how to access ColorObject
and set a color from ExcelKnownColors to the border.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Set borders
IBorders borders = worksheet["C2"].Borders;
//Set color object
ColorObject colorObject = borders[ExcelBordersIndex.EdgeTop].ColorObject;
//Set color
colorObject.SetIndexed(ExcelKnownColors.Red);
//Set line style
borders.LineStyle = ExcelLineStyle.Thick;
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
}
ColorRGB
Sets or gets the RGB color of the border from System.Drawing.Color structure.
Declaration
Color ColorRGB { get; set; }
Property Value
Type |
---|
Color |
Examples
The following code illustrates how to set a RGB color from System.Drawing.Color structure to the border.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
//Set borders
IBorders borders = worksheet["C2"].Borders;
//Set border color
borders[ExcelBordersIndex.EdgeTop].ColorRGB = System.Drawing.Color.Red;
borders[ExcelBordersIndex.EdgeBottom].ColorRGB = System.Drawing.Color.Blue;
//Set line style
borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thick;
borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thick;
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
}
LineStyle
Returns or sets the line style for the border. Read/write ExcelLineStyle.
Declaration
ExcelLineStyle LineStyle { get; set; }
Property Value
Type |
---|
ExcelLineStyle |
Remarks
To know more about borders refer Apply Border Settings.
Examples
By default LineStyle is set to None so borders are not applied. Here for example, we set Thick to EdgeTop and EdgeBottom borders.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
//Set borders
IBorders borders = worksheet["C2"].Borders;
//Set border color
borders[ExcelBordersIndex.EdgeTop].Color = ExcelKnownColors.Red;
borders[ExcelBordersIndex.EdgeBottom].Color = ExcelKnownColors.Blue;
//Set line style
borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thick;
borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thick;
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
}
ShowDiagonalLine
This property is used only by Diagonal borders. For any other border index property will have no influence.
Declaration
bool ShowDiagonalLine { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to set visibility of the DiagonalDown and DiagonalUp borders.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
//Set text
worksheet["C2"].Text = "Sample";
worksheet["D2"].Text = "text";
worksheet["C3"].Text = "in";
worksheet["D3"].Text = "cell";
//Set borders
IBorders borders = worksheet["C2:D3"].Borders;
//Set color
borders.Color = ExcelKnownColors.Red;
//Set line style
borders.LineStyle = ExcelLineStyle.Thick;
//Set diagonal line visibility
borders[ExcelBordersIndex.DiagonalDown].ShowDiagonalLine = false;
borders[ExcelBordersIndex.DiagonalUp].ShowDiagonalLine = false;
//Save and dispose
workbook.SaveAs("CellFormats.xlsx");
workbook.Close();
}