title: How can I remove all gridlines on an Excel spreadsheet except those explicitly added by me after clearing them all?
body: <p>Yes, this question has been asked before, but the answer provided does not work for me. To be more specific:</p>
  
  <p>Wanting to only have gridlines where there is data (which I add myself), and remove the lighter gridlines that appear by default everywhere else altogether, I found <a href="https://stackoverflow.com/questions/497220/gridlines-in-excel-through-interop">this accepted answer</a>...but it doesn't work for me.</p>
  
  <p>Using this code to get set up:</p>
  
  <pre><code>using Excel = Microsoft.Office.Interop.Excel;
  . . .
  private Excel.Application _xlApp;
  </code></pre>
  
  <p>...this initialization of the Excel.Application <em>compiles</em> (assigning a bool to _xlApp's DisplayGridLines property <em>outside of</em> its initializer):</p>
  
  <pre><code>_xlApp = new Excel.Application
  {
      SheetsInNewWorkbook = 1,
      StandardFont = "ponceDeLeon",
      StandardFontSize = 11
  };
  _xlApp.Windows.Application.ActiveWindow.DisplayGridlines = false;
  </code></pre>
  
  <p>...but this (adding the code to the initializer) does not compile (I get, "Invalid initializer member declarator" and "The name 'Windows' does not exist in the current context"):</p>
  
  <pre><code>_xlApp = new Excel.Application
  {
      SheetsInNewWorkbook = 1,
      StandardFont = "ponceDeLeon",
      StandardFontSize = 11,
      Windows.Application.ActiveWindow.DisplayGridlines = false
  };
  </code></pre>
  
  <p>...nor does it compile with "Excel." prepended to "Windows.", even though it seems to want that (offering to import 'Microsoft.Office.Interop.Excel.Windows' and all other references in file"). The compiler's complaints are then:</p>
  
  <pre><code>An object reference is required for the non-static field, method, or property 'Microsoft.Office.Interop.Excel.Windows.Application.get'"
  </code></pre>
  
  <p>---and:</p>
  
  <pre><code>Invalid initializer member declarator
  </code></pre>
  
  <p>I already have Microsoft.Office.Interop.Excel.Windows in my project's References folder and, in fact, am successfully generating the .xlsx file. I'm to the "gingerbread/finish" part of the project now (cosmetics/formatting).</p>
  
  <p>Even in the case of the compiling code, it doesn't actually work - it fails at runtime with: "System.NullReferenceException was unhandled . . . Object reference not set to an instance of an object."</p>
  
  <p>So how can I "wipe the slate clean" of gridlines, and only let those I explicitly apply display on the sheet?</p>