我编写了下面的代码来检查excel工作表是否有图像,它不起作用。我在excel表的单元格A1中插入了一个图像。
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 > 0 && rowCount > 0)
{
for (int j = 1; j <= colCount; j++)
{
for (int k = 1; k <= 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);