C# VSTO 数据表 SetField
C# VSTO Datatable SetField
我正在尝试创建一个函数来更改数据表中的值。请参阅下面的简化视图:
public static void Heading1(DataTable TOC, Excel.Worksheet sheet, Excel.Range cell)
{
TOC.Rows[1].SetField<string>(5,cell.Value2.ToString());
}
但 C# returns 错误:
System.Data.DataRow' has no applicable method named 'SetField' but
appears to have an extension method by that name. Extension methods
cannot be dynamically dispatched. Consider casting the dynamic
arguments or calling the extension method without the extension method
syntax.
但是,如果我声明一个字符串并为其分配单元格值,它就可以正常工作:
public static void Heading1(DataTable TOC, Excel.Worksheet sheet, Excel.Range cell)
{
string s = cell.Value2;
TOC.Rows[1].SetField<string>(5,s);
}
这附近有没有?
如果列索引为5
datatable.Rows[1][5] = "Blah";
请注意,如果您这样做,您需要在 datable 中有 2 条记录。 如果table有一行,你想改变其中的值,行索引应该是0->datatable.Rows[0][5] = "Blah";
我正在尝试创建一个函数来更改数据表中的值。请参阅下面的简化视图:
public static void Heading1(DataTable TOC, Excel.Worksheet sheet, Excel.Range cell)
{
TOC.Rows[1].SetField<string>(5,cell.Value2.ToString());
}
但 C# returns 错误:
System.Data.DataRow' has no applicable method named 'SetField' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
但是,如果我声明一个字符串并为其分配单元格值,它就可以正常工作:
public static void Heading1(DataTable TOC, Excel.Worksheet sheet, Excel.Range cell)
{
string s = cell.Value2;
TOC.Rows[1].SetField<string>(5,s);
}
这附近有没有?
如果列索引为5
datatable.Rows[1][5] = "Blah";
请注意,如果您这样做,您需要在 datable 中有 2 条记录。 如果table有一行,你想改变其中的值,行索引应该是0->datatable.Rows[0][5] = "Blah";