Excel Interop(Visual Studio C#)-“嵌入互操作类型”属性

4
在Visual Studio的C# Winform中添加了interop.excel参考后,我不再能够进行“编辑和继续”操作...错误提示为“修改包含嵌入式Interop类型/成员使用的'method'将阻止在启用Edit and Continue时继续进行调试会话。要启用“编辑和继续”功能,请尝试在调试时将COM引用的“嵌入Interop类型”属性设置为“False”。”
不幸的是,当我将“嵌入Interop类型”属性设置为“False”时,VS会给以下代码报错:
ws.Cells[2, 1].Value = xxx;
错误提示为“'object' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)”
我已经在SO上寻找答案很久了,但没有任何运气...是否有人可以帮忙?

该属性的类型是dynamic,而不是object。你所做的不仅仅是改变Embed Interop Types属性。可能是因为您忘记将Copy Local属性设置为true。请不要让我们猜测。 - Hans Passant
1个回答

1

Cells()没有Value属性(Range()有)
将此行更改为ws.Cells[2, 1]= xxx;


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接