Worksheet get_Range throws exception

后端 未结 4 1780
一整个雨季
一整个雨季 2020-12-13 19:09

I\'m using C# to manipulate an Excel worksheet. The following two pieces of code should work the same, but one works and the other throws an exception. I wonder why.

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-13 19:23

    I had upgraded my VS C# project from .Net Framework 3.5 to 4.5. Once I had upgraded successfully, I got this "object" does not contain a definition for 'get_Range' exception when trying to generate an excel report.

    What I did is instead of using below code

    range = xlSheet.get_Range(Cells[xlRow, xlCol], Cells[xlRow, xlCol]);
    

    I rewrote to

    range = xlSheet.Range[Cells[xlRow, xlCol], xlSheet.Cells[xlRow, xlCol]];
    

    And it worked.

提交回复
热议问题