Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Excel.Worksheet'. An explicit conversion exists (are you missing a cast?)

强颜欢笑 提交于 2019-12-01 04:23:15

you have to create a new Worksheet with Sheets array by providing WorkSheet Name. and also please Cast The Newly Created WorkSheet.

Replace this :

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

with following

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

To resolve your second error,

//Error at .Value2

  1. Go to project properties. (Click Project in Menu, Click properties)
  2. Set the Target Framework as .NET Framework 4
  3. This should resolve your .Value2 error.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!