Cell border in Excel Addin C#

Cell border in Excel Addin C#

Border:

Another object which helps user to decorate information in a Sheet. In this article we will learn, how to put border around each cell using VSTO C#. Dear readers while writing this article I am really happy to share that Corona (COVID-19) medicine is announced in the market named as “Fabiflue“. Please be safe and stay healthy.

Input Source:

Let’s put border around above data depicted in the input source image

Code:

private void btnBorder_Click(object sender, RibbonControlEventArgs e)
{
	//Capture user selection
	excel.Range oRange = Globals.ThisAddIn.Application.Selection;
	foreach (excel.Range oCell in oRange.Cells)
	{
		oCell.Borders[excel.XlBordersIndex.xlEdgeTop].LineStyle = excel.XlLineStyle.xlContinuous;
		oCell.Borders[excel.XlBordersIndex.xlEdgeBottom].LineStyle = excel.XlLineStyle.xlContinuous;
		oCell.Borders[excel.XlBordersIndex.xlEdgeLeft].LineStyle = excel.XlLineStyle.xlContinuous;
		oCell.Borders[excel.XlBordersIndex.xlEdgeRight].LineStyle = excel.XlLineStyle.xlContinuous;
	}
}

Output:

Please leave your valuable comments!!!

Next: Cell text alignment using VSTO C#

Leave a Reply

Your email address will not be published. Required fields are marked *