title: Extracting images from Excel 2007 - 2010 document
body: <p>I am writing an application that extracts images from an Excel spreadsheet using COM interop.</p>
  
  <p>It works perfectly fine if I save the file as an XLS (2003 format) from Excel 2010 however if I save it as an XLSX (2007 to 2010 format) it produces this exception "The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"</p>
  
  <p>My code is below. The exception is thrown by the line pic.Copy(); which works perfectly fine with an XLS. </p>
  
  <pre class="lang-cs prettyprint-override"><code>    public static BitmapSource[] ImportImages(string FileName)
      {
          //Create the Excel Object
          ExcelObj = new Microsoft.Office.Interop.Excel.Application();
  
          //Create the Workbooks wrapper
          Workbooks workbooks = ExcelObj.Workbooks;
  
          //Open the Excel workbook
          Workbook workbook = workbooks.Open(FileName);
  
          //Reference the worksheets in the Excel file
          Sheets sheets = workbook.Worksheets;
  
          List&lt;BitmapSource&gt; images = new List&lt;BitmapSource&gt;();
  
          List&lt;Picture&gt; pics = new List&lt;Picture&gt;();
  
          //Reference the first sheet in the workbook
          Worksheet sheet = sheets[1];
  
          for (int i = 1; i &lt; 30; i++)
          {
             pics.Add(sheet.Pictures(i));
          }
  
          foreach (Picture pic in pics)
          {
              pic.Copy();
  
              if (Clipboard.ContainsImage())
              {
                  images.Add(Clipboard.GetImage());
              }
  
              Marshal.ReleaseComObject(pic);
          }
  
          Marshal.ReleaseComObject(sheet);
          Marshal.ReleaseComObject(workbooks);
          Marshal.ReleaseComObject(workbook);
          Marshal.ReleaseComObject(sheets);
          ExcelObj.Quit();
          Marshal.ReleaseComObject(ExcelObj);
  
          return images.ToArray();
      }
  </code></pre>
  
  <p>Any ideas why this is happening? I need to be able to support 2003 and 2007/2010 with my project. </p>
  
  <p>Thanks</p>