Esempio n. 1
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            PropertyDescriptor property = context.DataContext.GetProperties()[ExcelCreate.GetExcelAppTag];
            Excel::Application excelApp = property.GetValue(context.DataContext) as Excel::Application;

            try
            {
                m_Delegate = new runDelegate(Run);
                string            sheetName = SheetName.Get(context);
                Excel::_Worksheet sheet;
                if (sheetName == null)
                {
                    sheet = excelApp.ActiveSheet;
                }
                else
                {
                    sheet = excelApp.ActiveWorkbook.Sheets[sheetName];
                }

                object      data           = new object();
                Excel.Range xCopyFromRange = null;
                Int32       rowColNum      = RowColNum.Get(context);
                if (CurrReadType == ReadType.读取行)
                {
                    data           = sheet.Rows[rowColNum].Value;
                    xCopyFromRange = sheet.Rows[rowColNum] as Excel.Range;
                    xCopyFromRange.Copy();
                }
                else
                {
                    data           = sheet.Columns[rowColNum].Value;
                    xCopyFromRange = sheet.Columns[rowColNum] as Excel.Range;
                    xCopyFromRange.Copy();
                }

                //Collection<object> _data = new Collection<object>();

                //foreach (object cell in ((object[,])data))
                //{
                //    if (cell != null)
                //    {
                //        _data.Add(cell);
                //    }
                //    else
                //        break;
                //}

                RolColData.Set(context, data);
                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);
            }
            return(m_Delegate.BeginInvoke(callback, state));
        }
Esempio n. 2
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            PropertyDescriptor property = context.DataContext.GetProperties()[ExcelCreate.GetExcelAppTag];
            Excel::Application excelApp = property.GetValue(context.DataContext) as Excel::Application;

            try
            {
                m_Delegate = new runDelegate(Run);
                string            sheetName = SheetName.Get(context);
                Excel::_Worksheet sheet;
                if (sheetName == null)
                {
                    sheet = excelApp.ActiveSheet;
                }
                else
                {
                    sheet = excelApp.ActiveWorkbook.Sheets[sheetName];
                }

                object data = new object();

                Int32 rowColNum = RowColNum.Get(context);
                if (CurrInsertType == InsertType.制行)
                {
                    sheet.Rows[rowColNum].Value = RolColData.Get(context);
                }
                else
                {
                    sheet.Columns[rowColNum].Value = RolColData.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);
            }
            return(m_Delegate.BeginInvoke(callback, state));
        }