不能将types“对象”隐式转换为“Microsoft.Office.Interop.Excel.Worksheet”。 存在明确的转换(您是否缺less演员?)

在这里我打开excel并写入excel表单。 我正在改变我的Windows应用程序到ASP网站,看到这个错误。 我已经添加了所有的参考和库。 不知道我在这里错过了什么。

获得如下所述的错误。 请帮帮我。

Excel.Application excel = new Excel.Application(); excel.Visible = false; // to hide the processing Excel.Workbook wb = excel.Workbooks.Add(); Excel.Worksheet sh = wb.Sheets.Add(); // Error at wb sh.Name = "Links"; for (int i = 1; i < list.Count; i++) { sh.Cells[i.ToString(), "A"].Value2 = list[i]; //Error at .Value2 } 

您必须通过提供WorkSheet Name来创build一个带有Sheets数组的新工作Sheets 。 也请WorkSheet新创build的工作WorkSheet

replace这个:

 Excel.Worksheet sh = wb.Sheets.Add(); 

跟随

  Excel.Worksheet sh = (Microsoft.Office.Interop.Excel.Worksheet)wb.Sheets["Sheet1"];