Exemplo n.º 1
0
        /// <summary>
        /// 导入数据
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="className"></param>
        /// <param name="acctId"></param>
        /// <returns></returns>
        public ActionResult Import(string filePath, string className, string[] keyValue)
        {
            ExcelImportBase importApp = CreateInstance(className);
            var             data      = importApp.Scan(filePath, keyValue);

            if (data.Count > 0)
            {
                return(Error("导入数据存在未处理的错误!"));
            }
            else
            {
                importApp.Import(filePath, keyValue);
                return(Success("数据导入成功!"));
            }
        }
        public static bool LoadExcelSheet <T>(string dirPath, string sheetName, out ExcelImportBase import)
        {
            import = Activator.CreateInstance(typeof(T)) as ExcelImportBase;

            import.LoadSheetLoader(dirPath, sheetName);

            if (!import.Import())
            {
                Console.WriteLine($"Excel import failed, {import.TableName}");
                return(false);
            }
            else
            {
                Console.WriteLine("{0}.xlsx 파일을 성공적으로 로딩했습니다.", sheetName);
            }
            return(true);
        }