title: Open, save and edit embedded excel sheet inside application
body: <p>I've managed to embed an excel sheet onto my windows form application with the help of these two examples:
  <a href="https://support.microsoft.com/en-ca/help/304662/how-to-use-the-webbrowser-control-to-open-office-documents-in-visual-c" rel="nofollow noreferrer">Example 1</a> and <a href="https://www.codeproject.com/Articles/15760/How-to-Integrate-Excel-in-a-Windows-Form-Applicati" rel="nofollow noreferrer">Example 2</a>.</p>
  
  <p>The examples are copied pretty much straight off. 
  However, I have yet to understand how I can manipulate the excel application/window through code. What I mean by that is I need to be able to: </p>
  
  <ul>
  <li>Show/Hide excel toolbar (Function in Example 1 doesn't work for me.)</li>
  <li>Protect sheets</li>
  <li>Save range of cells as .csv (alt. run excel macro)</li>
  <li>Change between displaying different excel files.</li>
  </ul>
  
  <p>Things that also would be nice:</p>
  
  <ul>
  <li>When loading up an excel sheet, to not having an open/save dialog window show up every time.</li>
  <li>A good way of disposing of excel workbooks when loadin up a new one to avoid the error "Can't open an excel file when an excel file of the same name is already open."</li>
  </ul>
  
  <p>My ideas so far. <br>
  I'm pretty sure that in some way I need to attach the active worksheet/workbook to a global variabel that has the properties needed for my needs. However, thus far when I have tried something like that I usually get a reference missing error or something similar, even though I think i'm doing the right thing.</p>
  
  <pre><code>private void button2_Click(object sender, EventArgs e)
      {
          // this.excelWrapper1.GetActiveWorkbook(FileName).Protect();
          //wb.Protect();
          //this.excelWrapper1.m_Workbook.Protect();
          Microsoft.Office.Interop.Excel.Application app = (Microsoft.Office.Interop.Excel.Application)Marshal.GetActiveObject("Excel.Application");
          app.ThisWorkbook.Protect(); // Doesn't work
      }
  </code></pre>
  
  <p>With this code I get this:</p>
  
  <pre><code>'System.Runtime.InteropServices.COMException' occurred in EmbeddedExcel.exe
  Exception from HRESULT: 0x800A03EC
  </code></pre>
  
  <p>Thank you in advance!</p>
  
  <p>Note: I can't use payware to do what I need. Free is fine.</p>