Example #1
0
 /// <summary>
 /// 向表中添加行数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="sheet"></param>
 /// <param name="listSources"></param>
 /// <param name="values"></param>
 public static void AddSheetRow <T>(this ExcelWorksheet sheet, IList <T> listSources, params KeyValuePair <string, Func <T, string> >[] values)
 {
     if (values != null && values.Length > 0)
     {
         sheet.AddSheetHeadRange(values.Select(item => item.Key).ToArray());
         if (listSources != null && listSources.Count > 0)
         {
             IList <Func <T, string> > listVs = values.Select(item => item.Value).ToList();
             for (int i = 0; i < listSources.Count; i++)
             {
                 for (int j = 0; j < listVs.Count; j++)
                 {
                     sheet.Cells[(i + 2), (j + 1)].Value = listVs[j](listSources[i]);
                 }
             }
         }
     }
 }