예제 #1
0
        public static bool Export(string PluginName, string ExcelPath, string SheetName, string OutputPath)
        {
            DataTable Table = null;

            //Microsoft.Office.Interop.Excel.Worksheet Table = null;

            try
            {
                var Plugin = PluginManager.GetExportPluginWithName(PluginName);
                if (Plugin == null)
                {
                    throw new Exception($"{PluginName}格式导出插件创建失败");
                }

                Table = ExcelAceHelper.OpenExcel(ExcelPath, ref SheetName, true);
                if (Table == null)
                {
                    throw new Exception($"{ExcelPath}表{SheetName}页读取错误");
                }

                var RowCount = ExcelAceHelper.GetExcelRowCount(Table); // 表的行数

                var Data = new IExportPlugin.ExportData
                {
                    Name       = SheetName,
                    InputPath  = ExcelPath,
                    OutputPath = OutputPath,
                    Data       = new List <List <string> >()
                };

                for (var Index = 0; Index < RowCount; ++Index)
                {
                    var Line = ExcelAceHelper.GetExcelDataLine(Table, Index);
                    Data.Data.Add(Line);
                }

                var CheckCode = Plugin.Check(Data);
                if (!string.IsNullOrWhiteSpace(CheckCode))
                {
                    throw new Exception(CheckCode);
                }

                return(Plugin.Export(Data));
            }
            catch (Exception Ex)
            {
                Logger.Error(Ex.Message);
                return(false);
            }
            finally
            {
                Table?.Dispose();
            }
        }
예제 #2
0
        public static bool ExportAllSheets(string PluginName, string ExcelPath, string OutputPath)
        {
            var Sheets = ExcelAceHelper.GetExcelSheets(ExcelPath, true);

            if (Sheets == null)
            {
                Logger.Warning($"不能读取Excel的Sheets : {ExcelPath}");
                return(false);
            }

            Logger.Info($"Export File : {ExcelPath}");
            foreach (var Sheet in Sheets)
            {
                if (Sheet.StartsWith("#"))
                {
                    continue;
                }
                Logger.Info($"  Sheet : {Sheet}");
                Export(PluginName, ExcelPath, Sheet, OutputPath);
            }

            return(true);
        }