/// <summary> /// import entityList to workbook sheet /// </summary> /// <typeparam name="TEntity">TEntity</typeparam> /// <param name="workbook">workbook</param> /// <param name="list">entityList</param> /// <param name="sheetIndex">sheetIndex</param> /// <returns>the sheet LastRowNum</returns> public static int ImportData<TEntity>([NotNull] this IWorkbook workbook, IEnumerable<TEntity> list, int sheetIndex) { if (sheetIndex >= InternalConstants.MaxSheetNum) { throw new ArgumentException( string.Format(Resource.IndexOutOfRange, nameof(sheetIndex), InternalConstants.MaxSheetNum), nameof(sheetIndex)); } var configuration = InternalHelper.GetExcelConfigurationMapping<TEntity>(); while (workbook.NumberOfSheets <= sheetIndex) { if (workbook.NumberOfSheets == sheetIndex) { var sheetName = typeof(TEntity).Name; if (configuration.SheetSettings.TryGetValue(sheetIndex, out var sheetSetting)) { sheetName = sheetSetting.SheetName; } workbook.CreateSheet(sheetName); } else { workbook.CreateSheet(); } } var sheet = NpoiHelper.EntityListToSheet(workbook.GetSheetAt(sheetIndex), list, sheetIndex); return sheet.LastRowNum; }
/// <summary> /// import entityList to sheet /// </summary> /// <typeparam name="TEntity">EntityType</typeparam> /// <param name="sheet">sheet</param> /// <param name="list">entityList</param> /// <param name="sheetIndex">sheetIndex</param> public static ISheet ImportData<TEntity>([NotNull] this ISheet sheet, IEnumerable<TEntity> list, int sheetIndex) => NpoiHelper.EntityListToSheet(sheet, list, sheetIndex);