コード例 #1
0
        private int Execute(ActivityContext context, IWorkbookAdapter adapter)
        {
            var sheetName = SheetName.Get(context);
            var range     = CellRange.Get(context);

            return(adapter.RemoveHyperlink(sheetName, range));
        }
コード例 #2
0
        public static IWorkbookAdapter Create(string path)
        {
            IWorkbookAdapter adapter = null;

            using (var f = File.OpenRead(path))
            {
                if (f.Length == 0)
                {
                    throw new InvalidOperationException("The file is empty (zero bytes long)");
                }

                var extension = Path.GetExtension(path);
                switch (extension.ToLowerInvariant())
                {
                case ".xlsm":     // macro enabled workbook
                case ".xltm":     // macro enabled template
                case ".xlsx":     // workbook
                case ".xltx":     // template
                    adapter = new OpenXmlWorkbookAdapter();
                    break;

                default:
                    adapter = new OLE2WorkbookAdapter();
                    break;
                }
            }

            if (adapter == null)
            {
                throw new InvalidOperationException("The file stream need be a OLE2 or OOXML stream");
            }

            adapter.Open(path);
            return(adapter);
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
        private string[] Execute(ActivityContext context, IWorkbookAdapter adapter)
        {
            var sheetName = SheetName.Get(context);
            var range     = CellRange.Get(context);

            return(adapter.GetHyperlinks(sheetName, range).ToArray());
        }
コード例 #5
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();
            }
        }
コード例 #6
0
        private bool Execute(ActivityContext context, IWorkbookAdapter adapter)
        {
            var sheetName   = SheetName.Get(context);
            var cellAddress = Cell.Get(context);
            var link        = Link.Get(context);
            var label       = Label.Get(context);
            var tooltip     = Tooltip.Get(context);

            adapter.AddHyperlink(sheetName, cellAddress, label, link, tooltip);
            return(true);
        }
コード例 #7
0
        protected override string[] Execute(CodeActivityContext context)
        {
            if (UseScope)
            {
                return(ExecuteWithScope(context));
            }

            IWorkbookAdapter workbook = null;

            try
            {
                var filePath = WorkbookPath.Get(context);
                workbook = WorkbookAdapterFactory.Create(filePath);
                return(workbook.GetSheetNames());
            }
            finally
            {
                workbook?.Dispose();
            }
        }
コード例 #8
0
        private string Execute(ActivityContext context, IWorkbookAdapter adapter)
        {
            var index = SheetIndex.Get(context);

            return(adapter.GetSheetName(index));
        }