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

后端 未结 2 1392
予麋鹿
予麋鹿 2021-01-12 06:43

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. D

相关标签:
2条回答
  • 2021-01-12 06:53

    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.
    0 讨论(0)
  • 2021-01-12 07:16

    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"];
    
    0 讨论(0)
提交回复
热议问题