Example #1
0
        public RSRangeObject(Worksheet sheet, RangePosition range)
            : base(sheet)
        {
            this.Range = range;

            this["style"] = new ExternalProperty(
                () =>
            {
                if (Style == null)
                {
                    Style = sheet.GetRangeStyles(this.Range);
                }
                return(Style);
            },
                (v) =>
            {
                sheet.SetRangeStyles(this.Range, RSUtility.GetRangeStyleObject(v));
            }
                );

            this["pos"] = new ExternalProperty(
                () => sheet.SelectionRange.StartPos,
                (v) =>
            {
                range.StartPos = RSUtility.GetPosFromValue(sheet, v);
                sheet.SelectRange(range);
            });

            this["range"] = new ExternalProperty(
                () => sheet.SelectionRange,
                (v) =>
            {
                sheet.SelectRange(RSUtility.GetRangeFromValue(sheet, v));
            });

            this["row"] = new ExternalProperty(() => sheet.SelectionRange.Row,
                                               (v) => this.Range = new RangePosition(CellUtility.ConvertData <int>(v), this.Range.Col,
                                                                                     this.Range.Rows, this.Range.Cols));

            this["col"] = new ExternalProperty(() => sheet.SelectionRange.Col,
                                               (v) => this.Range = new RangePosition(this.Range.Row, CellUtility.ConvertData <int>(v),
                                                                                     this.Range.Rows, this.Range.Cols));

            this["rows"] = new ExternalProperty(() => sheet.SelectionRange.Row,
                                                (v) => this.Range = new RangePosition(this.Range.Row, this.Range.Col,
                                                                                      CellUtility.ConvertData <int>(v), this.Range.Cols));

            this["cols"] = new ExternalProperty(() => sheet.SelectionRange.Col,
                                                (v) => this.Range = new RangePosition(this.Range.Row, this.Range.Col,
                                                                                      this.Range.Rows, CellUtility.ConvertData <int>(v)));

            this["toString"] = new NativeFunctionObject("toString", (ctx, owner, args) => this.Range.ToString());

            this["toAddress"] = new NativeFunctionObject("toAddress", (ctx, owner, args) => this.Range.ToAddress());

            this["toSpans"] = new NativeFunctionObject("toSpans", (ctx, owner, args) => this.Range.ToStringSpans());

            this["merge"] = new NativeFunctionObject("merge", (ctx, owner, args) => {
                sheet.MergeRange(this.Range); return(null);
            });

            this["unmerge"] = new NativeFunctionObject("unmerge", (ctx, owner, args) => {
                sheet.UnmergeRange(this.Range); return(null);
            });
        }
Example #2
0
        public RSSelectionObject(Worksheet sheet)
            : base(sheet)
        {
            this["moveUp"] = new NativeFunctionObject("moveUp", (srm, owner, args) =>
            {
                sheet.MoveSelectionUp(); return(null);
            });
            this["moveDown"] = new NativeFunctionObject("moveDown", (srm, owner, args) =>
            {
                sheet.MoveSelectionDown(); return(null);
            });
            this["moveLeft"] = new NativeFunctionObject("moveLeft", (srm, owner, args) =>
            {
                sheet.MoveSelectionLeft(); return(null);
            });
            this["moveRight"] = new NativeFunctionObject("moveRight", (srm, owner, args) =>
            {
                sheet.MoveSelectionRight(); return(null);
            });

            this["pos"] = new ExternalProperty(
                () => sheet.SelectionRange.StartPos,
                (v) =>
            {
                RangePosition range = sheet.SelectionRange;
                range.StartPos      = RSUtility.GetPosFromValue(sheet, v);
                sheet.SelectRange(range);
            });

            this["range"] = new ExternalProperty(
                () => sheet.SelectionRange,
                (v) =>
            {
                sheet.SelectRange(RSUtility.GetRangeFromValue(sheet, v));
            });

            this["row"] = new ExternalProperty(() => sheet.SelectionRange.Row,
                                               (v) =>
            {
                RangePosition range = sheet.SelectionRange;
                range.Row           = CellUtility.ConvertData <int>(v);
                sheet.SelectRange(range);
            });

            this["col"] = new ExternalProperty(() => sheet.SelectionRange.Col,
                                               (v) =>
            {
                RangePosition range = sheet.SelectionRange;
                range.Col           = CellUtility.ConvertData <int>(v);
                sheet.SelectRange(range);
            });

            this["toString"]  = new NativeFunctionObject("toString", (ctx, owner, args) => sheet.SelectionRange.ToString());
            this["toAddress"] = new NativeFunctionObject("toAddress", (ctx, owner, args) => sheet.SelectionRange.ToAddress());
            this["toSpans"]   = new NativeFunctionObject("toSpans", (ctx, owner, args) => sheet.SelectionRange.ToStringSpans());

            this["merge"] = new NativeFunctionObject("merge", (ctx, owner, args) =>
            {
                sheet.MergeRange(sheet.SelectionRange); return(null);
            });

            this["unmerge"] = new NativeFunctionObject("unmerge", (ctx, owner, args) =>
            {
                sheet.UnmergeRange(sheet.SelectionRange); return(null);
            });
        }
Example #3
0
        public RSWorksheet(Worksheet sheet)
        {
            this.sheet         = sheet;
            sheet.worksheetObj = this;

            #region Attributes
            this["readonly"] = new ExternalProperty(
                () => { return(sheet.HasSettings(WorksheetSettings.Edit_Readonly)); },
                (v) => { sheet.SetSettings(WorksheetSettings.Edit_Readonly, (v as bool?) ?? false); });
            #endregion

            #region Selection
            this["selection"] = new ExternalProperty(() =>
            {
                if (this.selection == null)
                {
                    this.selection = new RSSelectionObject(sheet);
                }
                return(this.selection);
            }, (obj) =>
            {
                sheet.SelectionRange = RSUtility.GetRangeFromValue(sheet, obj);
            });

            this["selectRange"] = new NativeFunctionObject("selectRange", (srm, owner, args) =>
            {
                RangePosition range = RSUtility.GetRangeFromArgs(sheet, args);
                if (range.IsEmpty)
                {
                    return(false);
                }

                try
                {
                    sheet.SelectRange(range);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            });

            this["selectionMode"] = new ExternalProperty(() => null);
            #endregion

            #region Rows & Cols
            this["rows"]   = new ExternalProperty(() => { return(sheet.RowCount); }, (v) => { sheet.SetRows(ScriptRunningMachine.GetIntValue(v)); });
            this["cols"]   = new ExternalProperty(() => { return(sheet.ColumnCount); }, (v) => { sheet.SetCols(ScriptRunningMachine.GetIntValue(v)); });
            this["getRow"] = new NativeFunctionObject("getRow", (srm, owner, args) =>
            {
                return(args.Length == 0 ? null : new RSRowObject(sheet, sheet.GetRowHeader(ScriptRunningMachine.GetIntValue(args[0]))));
            });
            this["getCol"] = new NativeFunctionObject("getCol", (srm, owner, args) =>
            {
                return(args.Length == 0 ? null : new RSColumnObject(sheet, sheet.GetColumnHeader(ScriptRunningMachine.GetIntValue(args[0]))));
            });
            #endregion

            #region Cell & Style
            this["setRangeStyle"] = new NativeFunctionObject("setRangeStyle", (ctx, owner, args) =>
            {
                if (args.Length < 1)
                {
                    return(false);
                }

                RangePosition range          = RSUtility.GetRangeFromValue(sheet, args[0]);
                WorksheetRangeStyle styleObj = RSUtility.GetRangeStyleObject(args[0]);

                sheet.SetRangeStyles(range, styleObj);

                return(styleObj);
            });

            this["getCell"] = new NativeFunctionObject("getCell", (srm, owner, args) =>
            {
                if (args.Length < 1)
                {
                    return(null);
                }

                CellPosition pos = RSUtility.GetPosFromValue(sheet, args);

                return(new RSCellObject(sheet, pos, sheet.GetCell(pos)));
            });

            #endregion

            #region Range
            this["mergeRange"] = new NativeFunctionObject("mergeRange", (srm, owner, args) =>
            {
                RangePosition range = RSUtility.GetRangeFromArgs(sheet, args);
                if (range.IsEmpty)
                {
                    return(false);
                }

                try
                {
                    sheet.MergeRange(range);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            });

            this["unmergeRange"] = new NativeFunctionObject("unmergeRange", (srm, owner, args) =>
            {
                RangePosition range = RSUtility.GetRangeFromArgs(sheet, args);
                if (range.IsEmpty)
                {
                    return(false);
                }

                try
                {
                    sheet.UnmergeRange(range);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            });
            #endregion

            this["reset"] = new NativeFunctionObject("reset", (ctx, owner, args) =>
            {
                if (args.Length == 2)
                {
                    sheet.Reset(ScriptRunningMachine.GetIntParam(args, 0, 1),
                                ScriptRunningMachine.GetIntParam(args, 1, 1));
                }
                else
                {
                    sheet.Reset();
                }
                return(null);
            });

            this["focuspos"] = new ExternalProperty(() => sheet.FocusPos,
                                                    (focuspos) => sheet.FocusPos = RSUtility.GetPosFromValue(sheet, focuspos));

            this["fixPos"] = new NativeFunctionObject("fixPos", (ctx, own, args) =>
            {
                var pos = RSUtility.GetPosFromArgs(this.sheet, args);
                return(RSUtility.CreatePosObject(this.sheet.FixPos(pos)));
            });

            this["fixRange"] = new NativeFunctionObject("fixRange", (ctx, own, args) =>
            {
                var range = RSUtility.GetRangeFromArgs(this.sheet, args);
                return(new RSRangeObject(this.sheet, this.sheet.FixRange(range)));
            });
        }