public static bool ImportExcel <T>(IEnumerable <HttpPostedFileBase> files, IteratorOption option, Func <Worksheet, int, IteratorOption, T> func, Func <Worksheet, bool> funcSetup, out List <T> list) { HttpPostedFileBase file = null; foreach (HttpPostedFileBase f in files) { file = f; break; } return(ImportExcel_Implement(file, option, func, funcSetup, out list)); }
public static bool ImportExcel_Implement <T>(HttpPostedFileBase file, IteratorOption option, Func <Worksheet, int, IteratorOption, T> func, Func <Worksheet, bool> funcSetup, out List <T> list) { list = new List <T>(); if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { try { using (var workBook = new Workbook()) { workBook.LoadDocument(file.InputStream); Worksheet sheet = workBook.Worksheets[0]; var range = sheet.GetDataRange(); int row = range.BottomRowIndex; string cp = string.Empty; funcSetup(sheet); for (int i = 1; i <= row; i++) { var ret = func(sheet, i, option); if (option.StopWhenError && (option.IsError || ret == null)) { return(false); } else { list.Add(ret); } } return(true); } } catch (Exception ex) { option.AddError(ex.Message); return(false); } } else { option.AddError("Chưa chọn file hoặc file bị lỗi"); return(false); } }
public static bool ImportExcel <T>(HttpFileCollectionBase files, IteratorOption option, Func <Worksheet, int, IteratorOption, T> func, Func <Worksheet, bool> funcSetup, out List <T> list) { return(ImportExcel_Implement(files[0], option, func, funcSetup, out list)); }