/// <summary>
/// 遍历类所有字段
/// </summary>
/// <param name="designer">aspose.cell中WorkbookDesigner对象</param>
/// <param name="jObject">Newtonsoft.Json 中 JObject.FromObject(entity)</param>
/// <param name="className">当前jObject名称,默认 t</param>
public static void ForeachEntityProperties(WorkbookDesigner designer, JObject jObject, string className = "t")
{

foreach (var item in jObject)
{
string propertyName = item.Key;
var propertyValue = item.Value;
if (item.Value.Type == JTokenType.String)
{
designer.SetDataSource(className + "." + propertyName, propertyValue);
}
else if (item.Value.Type == JTokenType.Array)
{
var arr = propertyValue as JArray;
designer.SetDataSource(ToDataTable(arr, propertyName));
}
else if (item.Value.Type == JTokenType.Object)
{
ForeachEntityProperties(designer, propertyValue as JObject, propertyName);
}

}

}
/// <summary>
/// 将JArray转换为DataTable
/// </summary>
/// <param name="jArray"></param>
/// <param name="tableName">DataTable表名称 默认 dt</param>
/// <returns></returns>
public static DataTable ToDataTable(JArray jArray, string tableName = "dt")

{
DataTable result = new DataTable(tableName);
if (jArray != null && jArray.Count > 0)
{
var jObject = jArray[0] as JObject;
if (jObject != null)
foreach (var item in jObject)
{
result.Columns.Add(item.Key, typeof(string));
}
foreach (var t in jArray)
{
ArrayList tempList = new ArrayList();
var items = t as JObject;
if (items != null)
foreach (var item in items)
{
object obj = item.Value;
tempList.Add(obj);
}
object[] array = tempList.ToArray();
result.LoadDataRow(array, true);
}
}
return result;

}