无法将类型“对象”隐式转换为“ Microsoft.Office.Interop.Excel.Worksheet”。存在显式转换(您是否缺少演员表?) [英] Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Excel.Worksheet'. An explicit conversion exists (are you missing a cast?)
本文介绍了无法将类型“对象”隐式转换为“ Microsoft.Office.Interop.Excel.Worksheet”。存在显式转换(您是否缺少演员表?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里,我要打开excel并写入excel工作表。我将Windows应用程序更改为ASP网站,并看到此错误。我添加了所有参考和库。不知道我在这里想念的是什么。
Here I'm opening excel and writing to excel sheet. I'm changing my windows application to asp website and seen this error. I have added all the references and libraries. Don't know what I am missing here.
出现以下错误。
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
名称来创建具有 Sheets
数组的新工作表。
,还请投射新创建的 WorkSheet
。
you have to create a new Worksheet with Sheets
array by providing WorkSheet
Name.
and also please Cast The Newly Created WorkSheet
.
替换此内容:
Excel.Worksheet sh = wb.Sheets.Add();
以下
Excel.Worksheet sh = (Microsoft.Office.Interop.Excel.Worksheet)wb.Sheets["Sheet1"];
这篇关于无法将类型“对象”隐式转换为“ Microsoft.Office.Interop.Excel.Worksheet”。存在显式转换(您是否缺少演员表?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文