protected override int Execute(CodeActivityContext context)
        {
            if (UseScope)
            {
                return(ExecuteWithScope(context));
            }

            var path = WorkbookPath.Get(context);

            if (!File.Exists(path))
            {
                throw new FileNotFoundException(path);
            }

            IWorkbookAdapter workbook = null;

            try
            {
                workbook = WorkbookAdapterFactory.Create(path);
                return(Execute(context, workbook));
            }
            catch (Exception)
            {
                return(-1);
            }
            finally
            {
                workbook?.Dispose();
            }
        }
示例#2
0
        protected override string[] Execute(CodeActivityContext context)
        {
            if (UseScope)
            {
                return(ExecuteWithScope(context));
            }

            var path = WorkbookPath.Get(context);

            if (!File.Exists(path))
            {
                throw new FileNotFoundException(path);
            }

            IWorkbookAdapter workbook = null;

            try
            {
                workbook = WorkbookAdapterFactory.Create(path);
                return(Execute(context, workbook));
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e.Message);
                throw;
            }
            finally
            {
                workbook?.Dispose();
            }
        }
        protected override void Execute(CodeActivityContext context)
        {
            using (var workbook = new XLWorkbook(WorkbookPath.Get(context)))
            {
                var workSheet = workbook.Worksheet(SheetIndex.Get(context));
                if (workSheet == null)
                {
                    throw new InvalidOperationException("Worksheet is not in a valid range");
                }

                SheetName.Set(context, workSheet.Name);
            }
        }
示例#4
0
        protected override void Execute(CodeActivityContext context)
        {
            string      FilePath   = WorkbookPath.Get(context);
            Application xlApp      = new Application();
            Workbook    xlWorkBook = xlApp.Workbooks.Add(Missing.Value);

            xlWorkBook.SaveAs(FilePath);
            xlWorkBook.Close(true, Missing.Value, Missing.Value);
            xlApp.Quit();
            ExcelWorkbook.Set(context, xlWorkBook);
            Marshal.ReleaseComObject(xlApp);
            Marshal.ReleaseComObject(xlWorkBook);
        }