Пример #1
0
        public static IEnumerable <string[]> Arrayify(this IExcelsior excelsior, HttpFile httpFile, bool hasHeaderRow = false)
        {
            string fileExtension = Path.GetExtension(httpFile.FileName) ?? String.Empty;

            IWorkbook workbook;

            using (Stream stream = new MemoryStream(httpFile.Buffer))
            {
                switch (fileExtension.ToLower())
                {
                case ".xls":
                    workbook = new HSSFWorkbook(stream);
                    break;

                case ".xlsx":
                    workbook = new XSSFWorkbook(stream);
                    break;

                default:
                    throw new InvalidOperationException("Excelsior can only operate on .xsl and .xlsx files.");
                }
            }

            return(excelsior.Arrayify(workbook, hasHeaderRow));
        }
        public static IEnumerable <IValidatedRow <T> > Listify <T>(this IExcelsior excelsior, HttpPostedFileBase httpPostedFileBase, IRowValidator <T> rowValidator, bool hasHeaderRow = false)
        {
            string fileExtension = Path.GetExtension(httpPostedFileBase.FileName) ?? String.Empty;

            IWorkbook workbook;

            switch (fileExtension.ToLower())
            {
            case ".xls":
                workbook = new HSSFWorkbook(httpPostedFileBase.InputStream);
                break;

            case ".xlsx":
                workbook = new XSSFWorkbook(httpPostedFileBase.InputStream);
                break;

            default:
                throw new InvalidOperationException("Excelsior can only operate on .xsl and .xlsx files.");
            }

            return(excelsior.Listify(workbook, rowValidator, hasHeaderRow));
        }