I want to add borders to a range on a spreadsheet. Based on some VB code here, I tried this:
Range range = locationWorksheet.Cells.CreateRange(7, 0, 93, 6);
range.SetOutlineBorder(BorderType.TopBorder, CellBorderType.Thick, Color.Blue);
range.SetOutlineBorder(BorderType.BottomBorder, CellBorderType.Thick, Color.Blue);
range.SetOutlineBorder(BorderType.LeftBorder, CellBorderType.Thick, Color.Blue);
range.SetOutlineBorder(BorderType.RightBorder, CellBorderType.Thin, Color.Red);
...but it pushes most of the data down the sheet, as can be seen here:
...and here:
This is what the sheet looked like prior to adding those borders.
Actually, I want internal borders, too, not just around the edge, but first things first.
BTW, it also seemed like a very "expensive" operation - the report took much longer to generate with that borderizing code added.
UPDATE
I was able to get it to work better, but it's still messing up my formatting. With this code:
private void BorderizeDataPortionOfLocationSheet()
{
int FUDGE_FACTOR = 5;
int rowsUsed = locationWorksheet.Cells.Rows.Count + FUDGE_FACTOR;
int colsUsed = locationWorksheet.Cells.Columns.Count; //QTY_COL; // last column
string rangeBegin = RoboReporterConstsAndUtils.GetRangeLettersNumbersAsStr(1, 8);
string rangeEnd = RoboReporterConstsAndUtils.GetRangeLettersNumbersAsStr(6, rowsUsed);
Range entireSheetRange = locationWorksheet.Cells.CreateRange(rangeBegin, rangeEnd);
CellsFactory cf = new CellsFactory();
Style style = cf.CreateStyle();
entireSheetRange.SetStyle(style);
entireSheetRange.SetOutlineBorders(CellBorderType.Thin, Color.Black);
}
...I am getting a border that doesn't shove the data down the sheet:
But it 86ed my beautiful formatting, which you can see here, when the range was borderless:
How can I get my border and retain my formatting, too?