Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用后期绑定从C#中的excel工作表中获取单元格名称?_C#_Excel_Late Binding - Fatal编程技术网

如何使用后期绑定从C#中的excel工作表中获取单元格名称?

如何使用后期绑定从C#中的excel工作表中获取单元格名称?,c#,excel,late-binding,C#,Excel,Late Binding,我试图从excel工作表中获取单元格名称,如A1、B1、A2、B2 这是我的密码 object objCellText = Cells.GetType().InvokeMember("Item", BindingFlags.GetProperty,null,Cells, new object[] { RowIndex, ColIndex }); var CellText = objCellTex

我试图从excel工作表中获取单元格名称,如
A1、B1、A2、B2

这是我的密码

object objCellText = Cells.GetType().InvokeMember("Item", 
                        BindingFlags.GetProperty,null,Cells, 
                        new object[] { RowIndex, ColIndex });

var CellText = objCellText.GetType().InvokeMember("Value",
                        BindingFlags.GetProperty, null, objCellText, null);

var CellName = objCellText.GetType().InvokeMember("Name",
                        BindingFlags.GetProperty, null, objCellText, null);
在代码中,
Name
属性不起作用


提前感谢您的帮助

这是因为单元格的名称不是它的地址。您可以使用描述性名称命名一个或多个单元格,例如“费用”
A2
A2:B2
是单个单元格或单元格范围的地址。命名范围可以在公式中使用,例如
SUM(Expenses)
就像范围地址
SUM(A1:B2)

为什么要使用反射而不是动态键入?使用
dynamic
而不是object,这样您就可以编写
Cells.Item
cell.Value
@Panagiotis Kanavos我不仅得到一个项目或值,还需要单元格背景色、字体样式等,所以我使用object.。使用
dynamic
也可以调用它们。添加它是为了使这些场景更简单、更快。@Panagiotis Kanavos.谢谢。