示例#1
0
        /// <summary>
        /// 处理excel文件
        /// </summary>
        /// <typeparam name="TImportDto">表头对应的类
        /// <para>表头名称对应 <see cref="System.ComponentModel.DataAnnotations"/> 下的 DisplayName 特性,字段验证也可使用其下的所有特性,如 Required,StringLength,Range,RegularExpression 等】</para>
        /// </typeparam>
        /// <param name="fileStream">文件流</param>
        /// <param name="optionAction">配置选项</param>
        /// <returns></returns>
        public List <ExcelSheetDataOutput <TImportDto> > ProcessExcelFile <TImportDto>(
            Stream fileStream,
            Action <ExcelImportOptions> optionAction = null
            ) where TImportDto : class, new()
        {
            try
            {
                //设置、验证 配置
                ExcelImportOptions options = new ExcelImportOptions();
                optionAction?.Invoke(options);
                options.CheckError();

                return(ProcessWorkbook <TImportDto>(fileStream, options));
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }