title: Open EXCEL (.xlsx) with password in C#
body: <p>I try to open password protected <code>.xlsx</code> files (Excel 2007 format) without typing the password manually. I have installed Excel 2003 and the <a href="https://www.microsoft.com/en-us/download/details.aspx?id=3" rel="nofollow noreferrer">Microsoft Office Compatibility Pack</a> that converts the file when opening.</p>
  
  <p>The following code works, but it prompt for the password.</p>
  
  <pre><code>Microsoft.Office.Interop.Excel.Application ExcelApp;
  Microsoft.Office.Interop.Excel.Workbook ExcelWorkbook;
  ExcelApp = new Microsoft.Office.Interop.Excel.Application();           
  Object pwd = "xxx";
  Object MissingValue = System.Reflection.Missing.Value;
  ExcelWorkbook = ExcelApp.Workbooks.Open("C:\\temp\\test.xlsx",MissingValue, MissingValue, MissingValue,pwd);
  </code></pre>
  
  <p>If I use the same code to open a <code>.xls</code> File (Excel 2003), it works without prompting for the password. Opening <code>.xlsx</code> files without password protection also works fine.</p>
  
  <p>How is it possible to open password protected <code>.xlsx</code> files without prompting for the password with Excel 2003 and the Microsoft Office Compatibility Pack?</p>
  
  <p>The trick from <a href="https://stackoverflow.com/questions/29204623/opening-password-protected-excel-file-in-c-or-c-sharp-prompts-for-password-eve">a similar problem</a> changing the readonly argument (3rd) to true </p>
  
  <pre><code>ExcelWorkbook = ExcelApp.Workbooks.Open("C:\\temp\\test.xlsx",MissingValue, true, MissingValue,pwd);
  </code></pre>
  
  <p>does not work here.</p>