Skip to content

Instantly share code, notes, and snippets.

@fdeitelhoff
Created November 8, 2013 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdeitelhoff/7368922 to your computer and use it in GitHub Desktop.
Save fdeitelhoff/7368922 to your computer and use it in GitHub Desktop.
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