예제 #1
0
        /// <summary>
        /// 导出表格按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (!button1.Enabled)
            {
                return;
            }

            string error = Facade.ParseExportUserInput();

            if (error != null)
            {
                ShowMessageBox(error);
                return;
            }

            ExprotCallbackArgv argv = new ExprotCallbackArgv();

            argv.OnProgressChanged = OnProgressChanged;
            argv.OnRunChanged      = OnRunExporterChanged;

            Facade.BeforeExporterOptionForm();
            this.BeforeExporterForm();
            Facade.RunXlsxForm(argv);
            this.AfterExporterForm();
            Facade.AfterExporterOptionForm();
        }
예제 #2
0
        /// <summary>
        /// 根据窗口参数,执行Excel数据导出工作
        /// </summary>
        /// <param name="options">命令行参数</param>
        public static void RunXlsxForm(ExprotCallbackArgv argv)
        {
            if (argv == null)
            {
                throw new Exception("Run xlsx form argv is null.");
            }

            if (argv.OnRunChanged != null)
            {
                argv.OnRunChanged("=================开始导出=================");
            }

            int curreExportCount       = 0;
            List <ExportType> typeList = DataMemory.GetOptionsFromTypes();

            foreach (ExportType type in typeList)
            {
                List <Options> optionList = DataMemory.GetExportOptions(type);
                foreach (Options option in optionList)
                {
                    Options result = CmdXlsx(type, option);
                    if (argv.OnRunChanged != null)
                    {
                        argv.OnRunChanged(Options.ConvertToString(type, result));
                    }
                    curreExportCount++;
                    if (argv.OnProgressChanged != null)
                    {
                        argv.OnProgressChanged(curreExportCount);
                    }
                    Thread.Sleep(1);
                }
            }

            RunExporterAll();

            if (argv.OnRunChanged != null)
            {
                argv.OnRunChanged("=================导出完毕=================");
            }
        }
예제 #3
0
        /// <summary>
        /// 命令行模式
        /// </summary>
        /// <param name="args"></param>
        private static void ConsoleMode(string[] args)
        {
            DateTime   startTime = DateTime.Now;
            OptionCmmd options   = new OptionCmmd();

            CommandLine.Parser parser = new CommandLine.Parser((with) => {
                with.HelpWriter = Console.Error;
            });

            if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-1)))
            {
                try {
                    OptionsForm optionForm = new OptionsForm();
                    optionForm.XlsxSrcPath = options.InputPath;
                    optionForm.XlsxDstPath = options.OutputPath;

                    optionForm.SetExportType(ExportType.cs);
                    optionForm.SetExportType(ExportType.txt);
                    DataMemory.SetOptionForm(optionForm);

                    ExprotCallbackArgv argv = new ExprotCallbackArgv();
                    argv.OnProgressChanged = (int progress) => {
                        //Console.WriteLine(string.Format("Export progress {0}", progress));
                    };
                    argv.OnRunChanged      = (string message) => {
                        Console.WriteLine(string.Format("Export message {0}", message));
                    };

                    Facade.BeforeExporterOptionForm();
                    Facade.RunXlsxForm(argv);
                    Facade.AfterExporterOptionForm();
                } catch (Exception ex) {
                    Console.WriteLine("Error: " + ex.Message);
                }
            }
            TimeSpan expend = DateTime.Now - startTime;

            Console.WriteLine(string.Format("Expend time [{0} millisecond].", expend.Milliseconds));
        }