Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Format a 170 x 170 cell area in Excel 2013 with a gray background and a black border.
private void ApplyFormatting(int rows, int columns)
{
// Complete surrounding borders of the gray box.
Range[Cells[1, 1], Cells[rows, columns]].Interior.Color = Color.LightGray;
Range[Cells[1, 1], Cells[rows, columns]].Borders[XlBordersIndex.xlEdgeTop].LineStyle = XlLineStyle.xlContinuous;
Range[Cells[1, 1], Cells[rows, columns]].Borders[XlBordersIndex.xlEdgeLeft].LineStyle = XlLineStyle.xlContinuous;
Range[Cells[1, 1], Cells[rows, columns]].Borders[XlBordersIndex.xlEdgeBottom].LineStyle = XlLineStyle.xlContinuous;
Range[Cells[1, 1], Cells[rows, columns]].Borders[XlBordersIndex.xlEdgeRight].LineStyle = XlLineStyle.xlContinuous;
// Set all column width to 2.14. That's a nice looking width.
for (var i = 1; i <= 170; i++)
{
var column = Columns[i, System.Type.Missing] as Range;
if (column != null) column.EntireColumn.ColumnWidth = 2.14;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.