Example #1
0
 protected override void Execute(NativeActivityContext context)
 {
     try
     {
         string workbookFullName = WorkbookFullName.Get(context);
         string workbookName     = string.Empty;
         ExcelHelper.Shared.GetApp().DisplayAlerts = false;
         // bool needToOpen = NeedToOpen.Get(context);
         if (File.Exists(workbookFullName))
         {
             workbookName = Path.GetFileName(workbookFullName);
         }
         else
         {
             Log.Logger.LogData("Workbook file do not exist, Error in activity CellValue_Copy", LogLevel.Error);
             context.Abort();
         }
         if (NeedToOpen == true)
         {
             ExcelHelper.Shared.GetApp().Workbooks.Open(workbookFullName);
         }
         string worksheetName = WorksheetName.Get(context);
         string cell          = Cell.Get(context);
         ExcelHelper.Shared.GetRange(workbookName, worksheetName, cell).Copy();
     }
     catch (Exception ex)
     {
         Log.Logger.LogData(ex.Message + " in activity CellValue_Copy", LogLevel.Error);
         if (!ContinueOnError)
         {
             context.Abort();
         }
     }
 }
        protected override void Execute(NativeActivityContext context)
        {
            try
            {
                object misValue         = System.Reflection.Missing.Value;
                string workbookFullName = WorkbookFullName.Get(context);
                string workbookName     = string.Empty;
                //bool needToSave = NeedToSave.Get(context);
                //bool needToClose = NeedToClose.Get(context);
                ExcelHelper.Shared.GetApp().DisplayAlerts = false;

                if (File.Exists(workbookFullName))
                {
                    workbookName = Path.GetFileName(workbookFullName);
                }
                else
                {
                    Log.Logger.LogData("Workbook file do not exist, Error in activity CellValue_Paste", LogLevel.Error);
                    context.Abort();
                }
                string worksheetName = WorksheetName.Get(context);
                string cell          = Cell.Get(context);
                ExcelHelper.Shared.GetRange(workbookName, worksheetName, cell).PasteSpecial(PasteType);



                //if (PasteValuesOnly)
                //{
                //    ExcelHelper.Shared.GetRange(WorkbookName, WorksheetName, Cell).PasteSpecial(XlPasteType.xlPasteValuesAndNumberFormats);
                //}
                //else
                //{
                //    ExcelHelper.Shared.GetRange(WorkbookName, WorksheetName, Cell).PasteSpecial();
                //}
                if (NeedToSave == true)
                {
                    ExcelHelper.Shared.GetWorkbookByName(workbookName, true).Save();
                }
                if (NeedToClose == true)
                {
                    ExcelHelper.Shared.GetWorkbookByName(workbookName, true).Close();
                }

                if (ExcelHelper.Shared.GetApp().Workbooks.Count == 0)
                {
                    ExcelHelper.Shared.Dispose();
                }
            }
            catch (Exception ex)
            {
                Log.Logger.LogData(ex.Message + " in activity Execute", LogLevel.Error);
                if (!ContinueOnError)
                {
                    context.Abort();
                }
            }
        }