예제 #1
0
        //异步执行开始函数
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            //根据EXCEL主控件标志获取其抽象化属性
            PropertyDescriptor property = context.DataContext.GetProperties()[ExcelCreate.GetExcelAppTag];
            //抽象化属性转换为可用ExcelApplication属性
            Excel::Application excelApp = property.GetValue(context.DataContext) as Excel::Application;

            try
            {
                //string sheetName = SheetName.Get(context);
                //string cellName_Begin = CellName_Begin.Get(context);
                //string cellName_End = CellName_End.Get(context);
                //int cellRow_Begin = CellRow_Begin.Get(context);
                //int cellColumn_Begin = CellColumn_Begin.Get(context);
                //int cellRow_End = CellRow_End.Get(context);
                //int cellColumn_End = CellColumn_End.Get(context);
                //Excel::_Worksheet sheet;
                //if (sheetName != null)
                //    sheet = excelApp.ActiveWorkbook.Sheets[sheetName];
                //else
                //    sheet = excelApp.ActiveSheet;

                //Excel::Range range1, range2;
                //range1 = cellName_Begin == null ? sheet.Cells[cellRow_Begin, cellColumn_Begin] : sheet.Range[cellName_Begin];
                //range2 = cellName_End == null ? sheet.Cells[cellRow_End, cellColumn_End] : sheet.Range[cellName_End];
                Excel::_Worksheet sheet;
                Excel::Range      range1, range2;
                RangeFunction.GetRange(excelApp, context, SheetName, CellName_Begin, CellName_End,
                                       CellRow_Begin, CellColumn_Begin, CellRow_End, CellColumn_End,
                                       out sheet, out range1, out range2);
                Excel::Range range3 = sheet.Range[range1, range2];
                range3.Value2 = FillData.Get(context);

                //释放资源
                System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
                sheet = null;
                //资源回收
                GC.Collect();
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "EXCEL区域填充过程出错", e.Message);
                new CommonVariable().realaseProcessExit(excelApp);
            }

            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }