3

I'm scratching my head over this one. I know how to set the background of a cell -- pretty straight-forward, but a new requirement that has come down is that the BORDER cannot be changed.

So, normally if I wanted to set the cell's background, I'd do something like...

  var interior = someCell.Interior;
  interior.Color = someColor;

That works, but the borders change as well. The idea is to change only the actual "background" of the cell. I tried using the PatternColor property on interior as well with Pattern = XlPatternSolid, also to no avail.

Is there a good way to do this, such that we ONLY change the background color -- not the borders?

Locke
  • 1,133
  • 11
  • 32
  • possible duplicate of [Cell color changing In Excel using C#](http://stackoverflow.com/questions/2452417/cell-color-changing-in-excel-using-c-sharp) –  Sep 03 '14 at 13:41
  • Not a duplicate -- that code changes the border colors as well. It is also the exact same as mine. – Locke Sep 03 '14 at 13:42
  • 1
    I think you may be facing a different problem because the code provided in the link does not paint the borders. –  Sep 03 '14 at 14:04
  • are you using Office.Interop for Excel? which version? Which Office version? because I can't reproduce your problem with 2010 office and Interop 14 –  Sep 03 '14 at 14:16
  • Oy, really? Interop for Office 2007 in VS2010. – Locke Sep 03 '14 at 14:28
  • 1
    I'm using Interop 15, Excel 2016, VS 2017 and I have the same problem. –  Apr 04 '18 at 14:28
  • interop 14 here showing in excel 2010. same issue. looking for solution now. thinking XlColorIndex; but no luck so far – NappingRabbit Aug 30 '18 at 12:47
  • I also have the same problem, only in reverse. I change the border and the interior color disappears (reverts to white) – Steve Silberberg Jan 14 '19 at 12:33
  • Steve, have you tried to reverse the order of your operations? I've found that Excel interop is very finicky. In the end, we had to render things as HTML, then reimport them into Excel. – Locke Jan 16 '19 at 21:16

0 Answers0