private void bgwProc_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) { // This method runs on the main thread. VBAState c = (VBAState)e.UserState; log.WriteLog("编译进度:" + e.ProgressPercentage.ToString() + "%, " + ",编译信息:" + c.info, LogLevel.Info); // 此处以为托盘化是便利的,但是调试期间不见得,所以先不要这样子处理 if (e.ProgressPercentage == 0) { // 启动后处理到托盘 if (this.WindowState == FormWindowState.Normal) { this.WindowState = FormWindowState.Minimized; this.Hide(); nfnMake.ShowBalloonTip(1000, "提示", "后台处理已启动", ToolTipIcon.Info); } } else if (e.ProgressPercentage == 100) { // 编译完成恢复到桌面区 if (this.WindowState == FormWindowState.Minimized) { this.Show(); this.WindowState = FormWindowState.Normal; this.Activate(); nfnMake.ShowBalloonTip(1000, "提示", "后台处理已完成", ToolTipIcon.Info); } } }
public ExcelMacroHelper(string ExcelFile) { SrcDir = @"C:\src"; ExcelFilePath = ExcelFile; ShowExcel = true; state = new VBAState(); }
/// <summary> /// 执行 Excel 宏 /// </summary> /// <param name="worker"></param> /// <param name="e"></param> public void RunExcelMacro(System.ComponentModel.BackgroundWorker worker, System.ComponentModel.DoWorkEventArgs e) { int count = 0, num = 0, percent = 0; // 根据不同功能调用对应的宏 ExArg ExA = (ExArg)e.Argument; VBAState state = new VBAState(); state.cstate = CState.Start; state.info = "启动"; worker.ReportProgress(0, state); try { if (RunExcelMacro((int)(ExA.MType), SrcDir, ExA.ModuleNo, ExA.ModuleNo) == 0) { ++num; percent = (int)(num * 100.0 / count); state.cstate = CState.Success; state.info = Enum.GetName(typeof(CState), state.cstate); worker.ReportProgress(percent, state); } else { ++num; percent = (int)(num * 100.0 / count); state.cstate = CState.Fail; state.info = Enum.GetName(typeof(CState), state.cstate); worker.ReportProgress(percent, state); } } catch (Exception ex) { ++num; percent = (int)(num * 100.0 / count); state.cstate = CState.FailEx; state.info = ex.Message; worker.ReportProgress(percent, state); } // 标记所有完成 state.cstate = CState.End; state.info = "编译完成"; worker.ReportProgress(100, state); }
/// <summary> /// ִ�� Excel �� /// </summary> /// <param name="worker"></param> /// <param name="e"></param> public void RunExcelMacro(System.ComponentModel.BackgroundWorker worker, System.ComponentModel.DoWorkEventArgs e) { int count = 0, num = 0, percent = 0; // ���ݲ�ͬ���ܵ��ö�Ӧ�ĺ� ExArg ExA = (ExArg)e.Argument; VBAState state = new VBAState(); state.cstate = CState.Start; state.info = "���"; worker.ReportProgress(0, state); try { if (RunExcelMacro((int)(ExA.MType), SrcDir, ExA.ModuleNo, ExA.ModuleNo) == 0) { ++num; percent = (int)(num * 100.0 / count); state.cstate = CState.Success; state.info = Enum.GetName(typeof(CState), state.cstate); worker.ReportProgress(percent, state); } else { ++num; percent = (int)(num * 100.0 / count); state.cstate = CState.Fail; state.info = Enum.GetName(typeof(CState), state.cstate); worker.ReportProgress(percent, state); } } catch (Exception ex) { ++num; percent = (int)(num * 100.0 / count); state.cstate = CState.FailEx; state.info = ex.Message; worker.ReportProgress(percent, state); } // ���������� state.cstate = CState.End; state.info = "�������"; worker.ReportProgress(100, state); }