1. 测试用例类

public class ExcelData { public string name1 { get; set; } public string name2 { get; set; } public string name3 { get; set; } }

2. 第一种方式:直接通过类获取属性

Type type = typeof(ExcelData);

PropertyInfo[] property = type.GetProperties();

3. 第二种方式:通过定义一个对象获取属性

ExcelData readData = ExcelDataList[j - 1];

Type typeData = readData.GetType();

PropertyInfo[] propertyData = typeData.GetProperties();

// 获取属性值

string proValue1 = propertyData[0].GetValue(readData , null).ToString();

// 设置属性值

string strValue1="123";

propertyData [0].SetValue(readData, strValue1, null);

代码很简单,可以给新手一点启发。可以关注gzh 爱学习的兔八哥,hf消息 Excel读写, 就可以获得源代码。

相关阅读

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。