title: How can I add borders around a spreadsheet range (Aspose Cells)?
body: <p>I want to add borders to a range on a spreadsheet. Based on some VB code <a href="https://stackoverflow.com/questions/14834080/aspose-cells-set-border-for-range">here</a>, I tried this:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>...but it pushes most of the data down the sheet, as can be seen here:</p>
  
  <p><a href="https://i.stack.imgur.com/izNaB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/izNaB.png" alt="enter image description here"></a></p>
  
  <p>...and here:</p>
  
  <p><a href="https://i.stack.imgur.com/BE8tU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BE8tU.png" alt="enter image description here"></a></p>
  
  <p>This is what the sheet looked like prior to adding those borders.</p>
  
  <p><a href="https://i.stack.imgur.com/Uue6u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uue6u.png" alt="enter image description here"></a></p>
  
  <p>Actually, I want internal borders, too, not just around the edge, but first things first.</p>
  
  <p>BTW, it also seemed like a very "expensive" operation - the report took much longer to generate with that borderizing code added.</p>
  
  <h2>UPDATE</h2>
  
  <p>I was able to get it to work better, but it's still messing up my formatting. With this code:</p>
  
  <pre><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);
  }
  </code></pre>
  
  <p>...I am getting a border that doesn't shove the data down the sheet:</p>
  
  <p><a href="https://i.stack.imgur.com/A1Rv0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A1Rv0.png" alt="enter image description here"></a></p>
  
  <p>But it 86ed my beautiful formatting, which you can see here, when the range was borderless:</p>
  
  <p><a href="https://i.stack.imgur.com/G8Vfc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G8Vfc.png" alt="enter image description here"></a></p>
  
  <p>How can I get my border and retain my formatting, too?</p>