Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: “object”未包括“get_Range”的定义

时间:2022-10-13 14:29:26

asp.net操作Excel合并单元格时,抛出了异常:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: “object”未包括“get_Range”的定义
在 CallSite.Target(Closure , CallSite , ComObject , Object , Object )
在 System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
在 CallSite.Target(Closure , CallSite , Application , Object , Object )
在 System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)

开发环境:VS2010+Framework4.0+Microsoft.Office.Interop.Excel 11.0

解决方式:

    2.0  worksheet.get_Range(worksheet.Cells[1, 1], worksheet.Cells[1, 3]).Merge(mValue);


    4.0  Microsoft.Office.Interop.Excel.Range range = worksheet.Range[worksheet.Cells[1, i + 1], worksheet.Cells[2, i + 1]];


            range.MergeCells = true;