/// <summary> /// 设置数据 /// </summary> /// <param name="lst"></param> private static void ExcelSetDataRow <T>(List <T> lst) where T : class, new() { if (lst.Count <= 0) { return; } IRow row; int colIndex; T dto; var dict = ExportMappingDictFactory.CreateInstance(typeof(T)); for (int i = 0; i < lst.Count; i++) { colIndex = 0; row = Sheet.CreateRow(i + 1); dto = lst[i]; foreach (var kvp in dict) { row.CreateCell(colIndex).SetCellValue(dto.GetStringValue(kvp.Key)); colIndex++; } } }
/// <summary> /// 设置表头 /// </summary> private static void ExcelSetHeader <T>() where T : class, new() { IRow row = Sheet.CreateRow(0); int colIndex = 0; var dict = ExportMappingDictFactory.CreateInstance(typeof(T)); foreach (var kvp in dict) { row.CreateCell(colIndex).SetCellValue(kvp.Value); colIndex++; } }