Esempio n. 1
0
 public MoeConvertControl()
 {
     ExcelReader   = new EPPlusReader();
     ConvertHandle = new MoeConvertTable();
     _loadTest     = new StringBuilder(1024);
     _configTypes  = new StringBuilder(1024);
 }
Esempio n. 2
0
        public void StartConvert(ArgsData args)
        {
            System.Console.WriteLine(string.Format("Excel Folder : {0}", args.ExcelPath));
            System.Console.WriteLine(string.Format("Des Folder : {0}", args.DesPath));

            DesFolder         = new DirectoryInfo(args.DesPath).FullName.Replace("\\", "/");
            ExcelSourceFolder = new DirectoryInfo(args.ExcelPath).FullName.Replace("\\", "/");

            if (string.IsNullOrEmpty(ExcelSourceFolder) || !Directory.Exists(ExcelSourceFolder))
            {
                throw new System.ArgumentException("excelFolder 为空!");
            }

            if (string.IsNullOrEmpty(DesFolder))
            {
                throw new System.ArgumentException("desFolder 为空!");
            }

            if (!Directory.Exists(DesFolder))
            {
                Directory.CreateDirectory(DesFolder);
            }

            //  导出选择文件,不能清理目录
            if (args.SelectFile)
            {
                args.ClearDes = false;
            }

            if (args.ClearDes && Directory.Exists(DesFolder))
            {
                var folders = Directory.GetDirectories(DesFolder);
                foreach (var fol in folders)
                {
                    if (fol.EndsWith(".svn"))
                    {
                        continue;
                    }
                    Directory.Delete(fol, true);
                }
            }
            else
            {
                Directory.CreateDirectory(DesFolder);
            }

            ConvertEvent = args.ConvertEvent;

            var srcAndDiagonal = string.Empty;

            if (ExcelSourceFolder.EndsWith("/"))
            {
                srcAndDiagonal = ExcelSourceFolder;
            }
            else
            {
                srcAndDiagonal = ExcelSourceFolder + "/";
            }

            var files          = Directory.GetFiles(ExcelSourceFolder, "*.xlsx", SearchOption.AllDirectories);
            var excelFileInfos = new List <ExcelFileInfo> ();

            foreach (var f in files)
            {
                if (f.Contains("~$"))
                {
                    continue;
                }
                excelFileInfos.Add(new ExcelFileInfo(f, srcAndDiagonal, DesFolder));
            }

            if (args.SelectFile)
            {
                excelFileInfos = UserSelect(excelFileInfos);
            }


            //  自定义转换
            CustomConvert = new Dictionary <string, IConvertTableHandle>();
            if (args.CustomConvert != null && args.CustomConvert.Count > 0)
            {
                Assembly assembly = Assembly.GetExecutingAssembly();
                foreach (var item in args.CustomConvert)
                {
                    var ins = assembly.CreateInstance(item.Value, true);
                    if (ins != null)
                    {
                        IConvertTableHandle handle = ins as IConvertTableHandle;
                        if (handle != null)
                        {
                            CustomConvert.Add(item.Key, handle);
                        }
                    }
                }
            }

            _StartConvert(excelFileInfos);

            System.Console.WriteLine(string.Format("Excel Folder : {0}", ExcelSourceFolder));
            System.Console.WriteLine(string.Format("Des Folder : {0}", DesFolder));
        }
Esempio n. 3
0
 public ConvertControl(IConvertTableHandle convertHandle, IExcelReader excelReader)
 {
     _excelReader   = excelReader;
     _convertHandle = convertHandle;
 }