/// <summary> /// export excel via template /// </summary> /// <typeparam name="TEntity">Entity Type</typeparam> /// <param name="entities">entities</param> /// <param name="templateSheet"></param> /// <param name="extraData">extraData</param> /// <returns>exported excel bytes</returns> public static byte[] ToExcelBytesByTemplate<TEntity>([NotNull] this IEnumerable<TEntity> entities, ISheet templateSheet, object extraData = null) { NpoiTemplateHelper.EntityListToSheetByTemplate( templateSheet, entities, extraData ); return templateSheet.Workbook.ToExcelBytes(); }
/// <summary> /// export excel via template /// </summary> /// <typeparam name="TEntity">Entity Type</typeparam> /// <param name="entities">entities</param> /// <param name="templateWorkbook">templateWorkbook</param> /// <param name="sheetIndex">sheetIndex</param> /// <param name="extraData">extraData</param> /// <returns>exported excel bytes</returns> public static byte[] ToExcelBytesByTemplate<TEntity>([NotNull] this IEnumerable<TEntity> entities, IWorkbook templateWorkbook, int sheetIndex = 0, object extraData = null) { if (null == templateWorkbook) { throw new ArgumentNullException(nameof(templateWorkbook)); } if (sheetIndex <= 0) { sheetIndex = 0; } var templateSheet = templateWorkbook.GetSheetAt(sheetIndex); NpoiTemplateHelper.EntityListToSheetByTemplate( templateSheet, entities, extraData ); return templateWorkbook.ToExcelBytes(); }
/// <summary> /// export excel via template /// </summary> /// <typeparam name="TEntity">Entity Type</typeparam> /// <param name="entities">entities</param> /// <param name="templateWorkbook">templateWorkbook</param> /// <param name="excelPath"></param> /// <param name="sheetIndex">sheetIndex</param> /// <param name="extraData">extraData</param> /// <returns>exported excel bytes</returns> public static void ToExcelFileByTemplate<TEntity>([NotNull] this IEnumerable<TEntity> entities, IWorkbook templateWorkbook, string excelPath, int sheetIndex = 0, object extraData = null) { if (null == templateWorkbook) { throw new ArgumentNullException(nameof(templateWorkbook)); } if (sheetIndex <= 0) { sheetIndex = 0; } var templateSheet = templateWorkbook.GetSheetAt(sheetIndex); NpoiTemplateHelper.EntityListToSheetByTemplate( templateSheet, entities, extraData ); templateWorkbook.WriteToFile(excelPath); }