title: How to check if a cell in an excel document (.xlsx and .xls) contains images using ASP.NET and C#
body: <p>I have written the below code to check if an excel worksheet has images, its not working. I have inserted an image in cell A1 of the excel sheet.</p>
  
  <pre><code>Application MSExcelApp= new Application();
  Workbook MSExcelWB = MSExcelApp.Workbooks.Open(file);
  Worksheet MSExcelWS = MSExcelWB.Sheets[1];
  MSExcelWB.CheckCompatibility = false;
  MSExcelWB.DoNotPromptForConvert = true;
  MSExcelWB.UpdateRemoteReferences = false;
  MSExcelWB.EnableAutoRecover = false;
  MSExcelWB.SaveLinkValues = false;
  MSExcelApp.DisplayAlerts = false;
  MSExcelApp.AutoRecover.Enabled = false;
  Range MSExcelRange = MSExcelWS.UsedRange;
  int rowCount = MSExcelRange.Rows.Count;
  int colCount = MSExcelRange.Columns.Count;
  if (colCount &gt; 0 &amp;&amp; rowCount &gt; 0)
  {                   
      for (int j = 1; j &lt;= colCount; j++)
      {
          for (int k = 1; k &lt;= rowCount; k++)
          {
              Range CellRange = MSExcelRange.Cells[j, k] as Range;
              foreach (Shape wShape in MSExcelWS.Shapes)
              {
                  if (wShape.TopLeftCell == CellRange)
                  {
                      Console.WriteLine("True");
                  }
              }
          }
      }
  }
  MSExcelWB.Close();
  MSExcelApp.Quit();
  Marshal.ReleaseComObject(MSExcelRange);
  Marshal.ReleaseComObject(MSExcelWS);
  Marshal.ReleaseComObject(MSExcelWB);
  Marshal.ReleaseComObject(MSExcelApp);
  </code></pre>