示例#1
0
        private void BtnEdit_Click(object sender, EventArgs e)
        {
            RangePosition pos = this.reoGridControl1.CurrentWorksheet.SelectionRange;

            unvell.ReoGrid.Cell cell = this.reoGridControl1.CurrentWorksheet.Cells[pos.Row, pos.Col];
            Info_link_bill_tent item = cell.Tag as Info_link_bill_tent;

            if (item == null)
            {
                return;
            }
            FmLinkBillInfo fmLinkBill = new FmLinkBillInfo(item);

            fmLinkBill.SelectValue += (obj) =>
            {
                Info_link_bill_tent info = obj as Info_link_bill_tent;
                int rowOffset            = pos.Row;

                SetItemCellValue(info, rowOffset);
            };
            fmLinkBill.ShowDialog();
        }
示例#2
0
        public void DuplicateMergedCell()
        {
            SetUp();

            var range = new RangePosition(4, 4, 4, 4);

            worksheet.MergeRange(range);

            var subgrid = worksheet.GetPartialGrid(range);

            worksheet[0, 4] = subgrid;             // top
            AssertTrue(worksheet._Debug_Validate_All());

            worksheet[4, 0] = subgrid;             // left
            AssertTrue(worksheet._Debug_Validate_All());

            worksheet[8, 4] = subgrid;             // bottom
            AssertTrue(worksheet._Debug_Validate_All());

            worksheet[4, 8] = subgrid;             // right
            AssertTrue(worksheet._Debug_Validate_All());

            AssertTrue(worksheet.IsMergedCell(0, 4));
            AssertEquals(worksheet.GetCell(0, 4).GetColspan(), (short)4);
            AssertEquals(worksheet.GetCell(0, 4).GetRowspan(), (short)4);

            AssertTrue(worksheet.IsMergedCell(4, 0));
            AssertEquals(worksheet.GetCell(4, 0).GetColspan(), (short)4);
            AssertEquals(worksheet.GetCell(4, 0).GetRowspan(), (short)4);

            AssertTrue(worksheet.IsMergedCell(8, 4));
            AssertEquals(worksheet.GetCell(8, 4).GetColspan(), (short)4);
            AssertEquals(worksheet.GetCell(8, 4).GetRowspan(), (short)4);

            AssertTrue(worksheet.IsMergedCell(4, 8));
            AssertEquals(worksheet.GetCell(4, 8).GetColspan(), (short)4);
            AssertEquals(worksheet.GetCell(4, 8).GetRowspan(), (short)4);
        }
示例#3
0
        public void BaseRange()
        {
            var r1 = new RangePosition(0, 0, 1, 1);

            AssertEquals(r1.Row, 0);
            AssertEquals(r1.Col, 0);
            AssertEquals(r1.EndRow, 0);
            AssertEquals(r1.EndCol, 0);
            AssertEquals(r1.Rows, 1);
            AssertEquals(r1.Cols, 1);

            var r2 = new RangePosition(10, 20, 5, 5);

            AssertEquals(r2.Row, 10);
            AssertEquals(r2.Col, 20);
            AssertEquals(r2.EndRow, 14);
            AssertEquals(r2.EndCol, 24);
            AssertEquals(r2.Rows, 5);
            AssertEquals(r2.Cols, 5);

            AssertTrue(r1 != r2);
            AssertEquals(r2, new RangePosition(10, 20, 5, 5));
        }
示例#4
0
        public static FormulaValue Indirect(Cell cell, FormulaValue[] args)
        {
            if (args[0].type != FormulaValueType.String)
            {
                throw new FormulaTypeMismatchException(cell);
            }

            string address = (string)args[0].value;

            if (CellPosition.IsValidAddress(address))
            {
                var pos = new CellPosition(address);
                return(cell == null || cell.Worksheet == null ? null : Evaluator.CreateFormulaValue(cell.Worksheet.GetCell(pos)));
            }
            else if (RangePosition.IsValidAddress(address))
            {
                return(new RangePosition(address));
            }
            else
            {
                throw new FormulaTypeMismatchException(cell);
            }
        }
示例#5
0
        void Cut()
        {
            var range = new RangePosition(1, 1, 3, 5);

            worksheet.SelectionRange = range;
            worksheet.Cut();
            AssertTrue(worksheet._Debug_Validate_All());

            var bi = worksheet.GetRangeBorders(range);

            AssertEquals(bi.Left, RangeBorderStyle.Empty);
            AssertEquals(bi.Right, RangeBorderStyle.Empty);
            AssertEquals(bi.Top, RangeBorderStyle.Empty);
            AssertEquals(bi.Bottom, RangeBorderStyle.Empty);

            AssertEquals(worksheet[range.StartPos], null);
            AssertEquals(worksheet[range.EndPos], null);

            /////////////////////////////////////////////////////////////////////////////////

            range = new RangePosition(10, 10, 3, 5);

            worksheet.SelectionRange = range;
            worksheet.Paste();
            AssertTrue(worksheet._Debug_Validate_All());

            var bi2 = worksheet.GetRangeBorders(range);

            AssertEquals(bi2.NonUniformPos, BorderPositions.None);
            AssertEquals(bi2.Left, new RangeBorderStyle(Color.Black, BorderLineStyle.Solid));
            AssertEquals(bi2.Right, new RangeBorderStyle(Color.Black, BorderLineStyle.Solid));
            AssertEquals(bi2.Top, new RangeBorderStyle(Color.Black, BorderLineStyle.Solid));
            AssertEquals(bi2.Bottom, new RangeBorderStyle(Color.Black, BorderLineStyle.Solid));

            AssertEquals(worksheet[range.StartPos], "A1");
            AssertEquals(worksheet[range.EndPos], "E3");
        }
示例#6
0
        public void ValidRelativeAddress()
        {
            // cell
            AssertEquals(CellPosition.IsValidAddress("x1"), false, "x1");
            AssertEquals(CellPosition.IsValidAddress("-x1"), false);
            AssertEquals(CellPosition.IsValidAddress("A"), false);
            AssertEquals(CellPosition.IsValidAddress("1"), false);

            AssertEquals(CellPosition.IsValidAddress("B1:"), false);
            AssertEquals(CellPosition.IsValidAddress(":A1"), false);

            AssertEquals(CellPosition.IsValidAddress("A1"), true);
            AssertEquals(CellPosition.IsValidAddress(" ZZZ777 "), true);
            AssertEquals(CellPosition.IsValidAddress("AZHL1048576"), true);

            // range address
            AssertEquals(RangePosition.IsValidAddress("x1:C1"), false, "x1:C1");
            AssertEquals(RangePosition.IsValidAddress("-x1:C2"), false);
            AssertEquals(RangePosition.IsValidAddress("A:B"), true);
            AssertEquals(RangePosition.IsValidAddress("1"), false);
            AssertEquals(RangePosition.IsValidAddress("1:2"), true, "1:2");
            AssertEquals(RangePosition.IsValidAddress("1:X2"), false, "1:X2");
            AssertEquals(RangePosition.IsValidAddress("-A1:X2"), false);
            AssertEquals(RangePosition.IsValidAddress("$A1:X2"), true);

            AssertEquals(RangePosition.IsValidAddress("B1:"), false);
            AssertEquals(RangePosition.IsValidAddress(":A1"), false);

            AssertEquals(RangePosition.IsValidAddress("A1:C3"), true);
            AssertEquals(RangePosition.IsValidAddress("A1:A1"), true);
            AssertEquals(RangePosition.IsValidAddress("  A1:D5  "), true);
            AssertEquals(RangePosition.IsValidAddress("A1:AZHL1048576"), true);

            AssertEquals(RangePosition.IsValidAddress("A1"), true);
            AssertEquals(RangePosition.IsValidAddress(" A1 "), true);
            AssertEquals(RangePosition.IsValidAddress("AZHL1048576 "), true);
        }
示例#7
0
        void CustomFunction_RangeReference()
        {
            FormulaExtension.CustomFunctions["CountEvenNumber"] = (cell, args) =>
            {
                if (args.Length < 1 || !(args[0] is RangePosition))
                {
                    return(null);
                }

                RangePosition range = (RangePosition)args[0];

                int count = 0;

                // iterate over cells inside a range
                cell.Worksheet.IterateCells(range, (r, c, inCell) =>
                {
                    double value;
                    if (unvell.ReoGrid.Utility.CellUtility.TryGetNumberData(inCell.Data, out value))
                    {
                        if ((value % 2) == 0)
                        {
                            count++;
                        }
                    }

                    // continue iterate
                    return(true);
                });

                return(count);
            };

            worksheet["G2:K3"] = new object[] { 1, 2, 5, 7, 8, 10, 12, 15, 16, 19 };
            worksheet["L2"]    = "=CountEvenNumber(G2:K3)";

            AssertSame(worksheet["L2"], 5);
        }
        public void AutoFillSerial_InputData_ExpectedOutputData(object[] inputData, object[] outputData)
        {
            // Arrange
            for (int r = 0; r < inputData.Length; r++)
            {
                sheet[r, 0] = inputData[r];
            }

            var outputRange = RangePosition.FromCellPosition(inputData.Length, 0, inputData.Length + outputData.Length - 1, 0);

            // Act
            sheet.AutoFillSerial(
                RangePosition.FromCellPosition(0, 0, inputData.Length - 1, 0),
                outputRange
                );

            // Assert
            Console.WriteLine("Values in input range:");
            inputData.ToList().ForEach(Console.WriteLine);
            Console.WriteLine("Expected output:");
            outputData.ToList().ForEach(Console.WriteLine);

            Console.WriteLine("Actual output:");
            sheet.IterateCells(outputRange, (r, c, cell) =>
            {
                Console.WriteLine(cell.Data);
                return(true);
            });

            var offset = inputData.Length;

            for (var r = 0; r < outputData.Length; r++)
            {
                Assert.AreEqual(outputData[r], sheet[r + offset, 0]);
            }
        }
示例#9
0
 /// <summary>
 /// Create action to set partial grid.
 /// </summary>
 /// <param name="range">target range to set partial grid.</param>
 /// <param name="data">partial grid to be set.</param>
 public SetPartialGridAction(RangePosition range, PartialGrid data)
     : base(range)
 {
     this.data = data;
 }
示例#10
0
        public static FormulaValue SumIf(Cell cell, FormulaValue[] args)
        {
            if (cell == null || cell.Worksheet == null)
            {
                return(null);
            }

            if (args[1].type != FormulaValueType.String)
            {
                // todo: support not only string
                return(null);
            }

            double val = 0;
            double data;

            RangePosition evalRange, sumRange = RangePosition.Empty;

            if (args[0].type == FormulaValueType.Range)
            {
                evalRange = (RangePosition)args[0].value;
            }
            else
            {
                throw new FormulaTypeMismatchException(cell);
            }

            if (args.Length > 2)
            {
                if (args[2].type != FormulaValueType.Range)
                {
                    throw new FormulaTypeMismatchException(cell);
                }

                sumRange = (RangePosition)(args[2].value);
            }

            string expStr = (string)args[1].value;

            STValueNode leftExp = new STValueNode(null);
            STNode      compExp = Parser.ParseInterCompareExp(cell, expStr);

            int rows = cell.Worksheet.Rows;
            int cols = cell.Worksheet.Columns;

            cell.Worksheet.IterateCells(evalRange, (r, c, inCell) =>
            {
                leftExp.Value = Evaluator.CreateFormulaValue(inCell);
                compExp[0]    = leftExp;

                var result = (Evaluator.Evaluate(cell, compExp));
                if (result.type == FormulaValueType.Boolean && ((bool)result.value))
                {
                    if (sumRange.IsEmpty)
                    {
                        if (CellUtility.TryGetNumberData(inCell.InnerData, out data))
                        {
                            val += data;
                        }
                    }
                    else
                    {
                        int tr = sumRange.Row + r - evalRange.Row;
                        int tc = sumRange.Col + c - evalRange.Col;

                        if (tr < rows && tc < cols)
                        {
                            var sumCell = cell.Worksheet.GetCell(tr, tc);

                            if (sumCell != null && sumCell.InnerData != null &&
                                CellUtility.TryGetNumberData(sumCell.InnerData, out data))
                            {
                                val += data;
                            }
                        }
                    }
                }

                return(true);
            });

            return(val);
        }
示例#11
0
 public override void SetRange(int progressBarIndex, long minimum, long maximum)
 {
   progressRange[progressBarIndex] = new RangePosition(minimum, maximum);
 }
示例#12
0
 /// <summary>
 /// Create an action that perform set styles to specified range
 /// </summary>
 /// <param name="range">Range to be appiled this action</param>
 /// <param name="style">Style to be set to specified range</param>
 public SetRangeStyleAction(RangePosition range, WorksheetRangeStyle style)
     : base(range)
 {
     this.style = new WorksheetRangeStyle(style);
 }
示例#13
0
 /// <summary>
 /// Create a copy from this action in order to apply the operation to another range.
 /// </summary>
 /// <param name="range">New range where this operation will be appiled to.</param>
 /// <returns>New action instance copied from this action.</returns>
 public override WorksheetReusableAction Clone(RangePosition range)
 {
     return(new RemoveRangeDataAction(range));
 }
示例#14
0
 /// <summary>
 /// Create a copy from this action in order to apply the operation to another range.
 /// </summary>
 /// <param name="range">New range where this operation will be appiled to.</param>
 /// <returns>New action instance copied from this action.</returns>
 public override WorksheetReusableAction Clone(RangePosition range)
 {
     return(new InsertRowsAction(range.Row, range.Rows));
 }
示例#15
0
 public STRangeNode(Worksheet worksheet, RangePosition range, int start, int len)
     : base(STNodeType.RANGE, start, len)
 {
     this.Worksheet = worksheet;
     this.Range     = range;
 }
示例#16
0
 /// <summary>
 /// Create instance for UnmergeRangeAction with specified range.
 /// </summary>
 /// <param name="range">The range to be unmerged</param>
 public UnmergeRangeAction(RangePosition range) : base(range)
 {
 }
示例#17
0
        public BorderStylesDemo()
        {
            InitializeComponent();

            // 現在表示中のワークシートを取得
            var sheet = this.grid.CurrentWorksheet;

            // グリッド線を非表示
            sheet.DisableSettings(WorksheetSettings.View_ShowGridLine);

            // 行列サイズを調整
            sheet.SetColumnsWidth(0, 15, 60);
            sheet.SetRowsHeight(0, 20, 30);

            sheet["B2"] = "罫線スタイル:";

            // 範囲を定義
            var range = new RangePosition("B4:D4");

            // 罫線スタイルを設定

            sheet[range] = "Solid";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.Solid
            });

            range.Offset(1, 0);
            sheet[range] = "Dotted";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.Dotted
            });

            range.Offset(1, 0);
            sheet[range] = "Dashed";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.Dashed
            });

            range.Offset(1, 0);
            sheet[range] = "Dashed2";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.Dashed2
            });

            range.Offset(1, 0);
            sheet[range] = "DashDot";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.DashDot
            });

            range.Offset(1, 0);
            sheet[range] = "DashDotDot";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.DashDotDot
            });

            range.Offset(1, 0);
            sheet[range] = "Bold Solid";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.BoldSolid
            });

            range.Offset(1, 0);
            sheet[range] = "Bold Dotted";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.BoldDotted
            });

            range.Offset(1, 0);
            sheet[range] = "Bold Dashed";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.BoldDashed
            });

            range.Offset(1, 0);
            sheet[range] = "Bold DashDot";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.BoldDashDot
            });

            range.Offset(1, 0);
            sheet[range] = "Bold DashDotDot";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.BoldDashDotDot
            });

            range.Offset(1, 0);
            sheet[range] = "Strong Solid";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.BoldSolidStrong
            });

            range.Offset(1, 0);
            sheet[range] = "DoubleLine";
            sheet.SetRangeBorders(range, BorderPositions.Bottom, new RangeBorderStyle {
                Color = System.Drawing.Color.Black, Style = BorderLineStyle.DoubleLine
            });

            sheet["G3"] = "外側 Outside";
            sheet.Cells["G3"].Style.HAlign = ReoGridHorAlign.Center;
            sheet.Cells["G3"].Style.VAlign = ReoGridVerAlign.Middle;
            sheet.SetRangeBorders("F2:H4", BorderPositions.Outside, RangeBorderStyle.BlackSolid);

            sheet["K3"] = "内側 Inside";
            sheet.Cells["K3"].Style.HAlign = ReoGridHorAlign.Center;
            sheet.Cells["K3"].Style.VAlign = ReoGridVerAlign.Middle;
            sheet.SetRangeBorders("J2:L4", BorderPositions.InsideAll, RangeBorderStyle.BlackDotted);

            sheet["G7"] = "左&右 Left & Right";
            sheet.Cells["G7"].Style.HAlign = ReoGridHorAlign.Center;
            sheet.Cells["G7"].Style.VAlign = ReoGridVerAlign.Middle;
            sheet.SetRangeBorders("F6:H8", BorderPositions.Left | BorderPositions.Right, RangeBorderStyle.GraySolid);

            sheet["K7"] = "上&下 Top & Bottom";
            sheet.Cells["K7"].Style.HAlign = ReoGridHorAlign.Center;
            sheet.Cells["K7"].Style.VAlign = ReoGridVerAlign.Middle;
            sheet.SetRangeBorders("J6:L8", BorderPositions.Top | BorderPositions.Bottom, RangeBorderStyle.GrayDotted);

            sheet["G11"] = "SlateBlue";
            sheet.Cells["G11"].Style.HAlign = ReoGridHorAlign.Center;
            sheet.Cells["G11"].Style.VAlign = ReoGridVerAlign.Middle;
            sheet.SetRangeBorders("F10:H12", BorderPositions.InsideHorizontal | BorderPositions.Top | BorderPositions.Bottom,
                                  new RangeBorderStyle {
                Color = Color.SlateBlue, Style = BorderLineStyle.Dashed
            });

            sheet["K11"] = "DarkGoldenrod";
            sheet.Cells["K11"].Style.HAlign = ReoGridHorAlign.Center;
            sheet.Cells["K11"].Style.VAlign = ReoGridVerAlign.Middle;
            sheet.SetRangeBorders("J10:L12", BorderPositions.InsideVertical | BorderPositions.Left | BorderPositions.Right,
                                  new RangeBorderStyle {
                Color = Color.DarkGoldenrod, Style = BorderLineStyle.Dashed
            });
        }
示例#18
0
 /// <summary>
 /// Create a copy from this action in order to apply the operation to another range.
 /// </summary>
 /// <param name="range">New range where this operation will be appiled to.</param>
 /// <returns>New action instance copied from this action.</returns>
 public override WorksheetReusableAction Clone(RangePosition range)
 {
     return(new RemoveRangeStyleAction(Range, flag));
 }
示例#19
0
        /// <summary>
        /// Given a point and a value which is either a place marker (first, 
        /// last in set) or a <see cref="DataObject"/> object, this will determine 
        /// the position in this set of the range point.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="val"></param>
        /// <remarks>
        /// For example, we may want to know the index of the last instance of 
        /// a particular number in a set of numbers which would be 
        /// <c>positionOfRangePoint(SelectableRangePoint.LastValue, [number DataObject])</c>.
        /// <para>
        /// Note how the position is determined if the value is not found in the set.
        /// </para>
        /// </remarks>
        /// <returns></returns>
        private long PositionOfRangePoint(RangePosition position, DataObject val)
        {
            int p;
            DataObject cell;

            switch (position) {

                case RangePosition.FirstValue:
                    if (val == SelectableRange.FirstInSet) {
                        return 0;
                    }
                    if (val == SelectableRange.LastInSet) {
                        // Get the last value and search for the first instance of it.
                        cell = LastInCollationOrder;
                    } else {
                        cell = val;
                    }
                    p = SearchFirst(cell);
                    // (If value not found)
                    if (p < 0) {
                        return -(p + 1);
                    }
                    return p;

                case RangePosition.LastValue:
                    if (val == SelectableRange.LastInSet) {
                        return SetSize - 1;
                    }
                    if (val == SelectableRange.FirstInSet) {
                        // Get the first value.
                        cell = FirstInCollationOrder;
                    } else {
                        cell = val;
                    }
                    p = SearchLast(cell);
                    // (If value not found)
                    if (p < 0) {
                        return -(p + 1) - 1;
                    }
                    return p;

                case RangePosition.BeforeFirstValue:
                    if (val == SelectableRange.FirstInSet)
                        return -1;

                    if (val == SelectableRange.LastInSet) {
                        // Get the last value and search for the first instance of it.
                        cell = LastInCollationOrder;
                    } else {
                        cell = val;
                    }

                    p = SearchFirst(cell);
                    // (If value not found)
                    if (p < 0) {
                        return -(p + 1) - 1;
                    }
                    return p - 1;

                case RangePosition.AfterLastValue:
                    if (val == SelectableRange.LastInSet) {
                        return SetSize;
                    }
                    if (val == SelectableRange.FirstInSet) {
                        // Get the first value.
                        cell = FirstInCollationOrder;
                    } else {
                        cell = val;
                    }
                    p = SearchLast(cell);
                    // (If value not found)
                    if (p < 0) {
                        return -(p + 1);
                    }
                    return p + 1;

                default:
                    throw new ApplicationException("Unrecognised position.");
            }
        }
示例#20
0
 public override WorksheetReusableAction Clone(RangePosition range)
 {
     return(new SetPartialGridAction(range, data));
 }
示例#21
0
 /// <summary>
 /// Create action that perform setting border to a range
 /// </summary>
 /// <param name="range">Range to be appiled this action</param>
 /// <param name="pos">Position of range to set border</param>
 /// <param name="styles">Style of border</param>
 public SetRangeBorderAction(RangePosition range, BorderPositions pos, RangeBorderStyle styles)
     : this(range, new RangeBorderInfo[] { new RangeBorderInfo(pos, styles) })
 {
 }
示例#22
0
 /// <summary>
 /// Create a copy from this action in order to apply the operation to another range.
 /// </summary>
 /// <param name="range">New range where this operation will be appiled to.</param>
 /// <returns>New action instance copied from this action.</returns>
 public override WorksheetReusableAction Clone(RangePosition range)
 {
     return(new UnmergeRangeAction(range));
 }
示例#23
0
 /// <summary>
 /// Create action that perform setting border to a range
 /// </summary>
 /// <param name="range">Range to be appiled this action</param>
 /// <param name="styles">Style of border</param>
 public SetRangeBorderAction(RangePosition range, RangeBorderInfo[] styles)
     : base(range)
 {
     this.borders = styles;
 }
示例#24
0
 /// <summary>
 /// Create action to remove data from specified range.
 /// </summary>
 /// <param name="range">data from cells in this range will be removed.</param>
 public RemoveRangeDataAction(RangePosition range)
     : base(range)
 {
 }
示例#25
0
 /// <summary>
 /// Create a copy from this action in order to apply the operation to another range.
 /// </summary>
 /// <param name="range">New range where this operation will be appiled to.</param>
 /// <returns>New action instance copied from this action.</returns>
 public override WorksheetReusableAction Clone(RangePosition range)
 {
     return(new SetRangeBorderAction(range, borders));
 }
示例#26
0
 /// <summary>
 /// Do this action
 /// </summary>
 public override void Do()
 {
     insertedRow = Row;
     Worksheet.InsertRows(Row, Count);
     Range = new RangePosition(Row, 0, Count, -1);
 }
示例#27
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)));
            });
        }
示例#28
0
        public static void Read(Stream stream, Worksheet sheet, RangePosition targetRange,
                                Encoding encoding = null, int bufferLines = DEFAULT_READ_BUFFER_LINES, bool autoSpread = true)
        {
            targetRange = sheet.FixRange(targetRange);

            string[]        lines          = new string[bufferLines];
            List <object>[] bufferLineList = new List <object> [bufferLines];

            for (int i = 0; i < bufferLineList.Length; i++)
            {
                bufferLineList[i] = new List <object>(256);
            }

#if DEBUG
            var sw = System.Diagnostics.Stopwatch.StartNew();
#endif

            int row            = targetRange.Row;
            int totalReadLines = 0;

            using (var sr = new StreamReader(stream, encoding))
            {
                sheet.SuspendDataChangedEvents();
                int maxCols = 0;

                try
                {
                    bool finished = false;
                    while (!finished)
                    {
                        int readLines = 0;

                        for (; readLines < lines.Length; readLines++)
                        {
                            var line = sr.ReadLine();
                            if (line == null)
                            {
                                finished = true;
                                break;
                            }

                            lines[readLines] = line;

                            totalReadLines++;
                            if (!autoSpread && totalReadLines > targetRange.Rows)
                            {
                                finished = true;
                                break;
                            }
                        }

                        if (autoSpread && row + readLines > sheet.RowCount)
                        {
                            int appendRows = bufferLines - (sheet.RowCount % bufferLines);
                            if (appendRows <= 0)
                            {
                                appendRows = bufferLines;
                            }
                            sheet.AppendRows(appendRows);
                        }

                        for (int i = 0; i < readLines; i++)
                        {
                            var line = lines[i];

                            var toBuffer = bufferLineList[i];
                            toBuffer.Clear();

                            foreach (Match m in lineRegex.Matches(line))
                            {
                                toBuffer.Add(m.Groups["item"].Value);

                                if (toBuffer.Count >= targetRange.Cols)
                                {
                                    break;
                                }
                            }

                            if (maxCols < toBuffer.Count)
                            {
                                maxCols = toBuffer.Count;
                            }

                            if (autoSpread && maxCols >= sheet.ColumnCount)
                            {
                                sheet.SetCols(maxCols + 1);
                            }
                        }

                        sheet.SetRangeData(row, targetRange.Col, readLines, maxCols, bufferLineList);
                        row += readLines;
                    }
                }
                finally
                {
                    sheet.ResumeDataChangedEvents();
                }

                sheet.RaiseRangeDataChangedEvent(new RangePosition(
                                                     targetRange.Row, targetRange.Col, maxCols, totalReadLines));
            }

#if DEBUG
            sw.Stop();
            System.Diagnostics.Debug.WriteLine("load csv file: " + sw.ElapsedMilliseconds + " ms, rows: " + row);
#endif
        }
示例#29
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);
            });
        }
示例#30
0
 /// <summary>
 /// Create a copy from this action in order to apply the operation to another range.
 /// </summary>
 /// <param name="range">New range where this operation will be appiled to.</param>
 /// <returns>New action instance copied from this action.</returns>
 public override WorksheetReusableAction Clone(RangePosition range)
 {
     return(new SetRangeStyleAction(range, style));
 }
示例#31
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);
            });
        }
示例#32
0
        /// <summary>
        /// Do this action
        /// </summary>
        public override void Do()
        {
            backupData = Worksheet.GetPartialGrid(Range);

            affectedRange = this.Worksheet.FixRange(this.Range);

            int r1 = Range.Row;
            int c1 = Range.Col;
            int r2 = Range.EndRow;
            int c2 = Range.EndCol;

            int rowCount = Worksheet.RowCount;
            int colCount = Worksheet.ColumnCount;

            isFullColSelected  = affectedRange.Rows == rowCount;
            isFullRowSelected  = affectedRange.Cols == colCount;
            isFullGridSelected = isFullRowSelected && isFullColSelected;

            // update default styles
            if (isFullGridSelected)
            {
                backupRootStyle = WorksheetRangeStyle.Clone(Worksheet.RootStyle);

                this.backupRowStyles = new WorksheetRangeStyle[rowCount];
                this.backupColStyles = new WorksheetRangeStyle[colCount];

                // remote styles if it is already setted in full-row
                for (int r = 0; r < rowCount; r++)
                {
                    RowHeader rowHead = Worksheet.RetrieveRowHeader(r);
                    if (rowHead != null && rowHead.InnerStyle != null)
                    {
                        this.backupRowStyles[r] = WorksheetRangeStyle.Clone(rowHead.InnerStyle);
                    }
                }

                // remote styles if it is already setted in full-col
                for (int c = 0; c < colCount; c++)
                {
                    ColumnHeader colHead = Worksheet.RetrieveColumnHeader(c);
                    if (colHead != null && colHead.InnerStyle != null)
                    {
                        this.backupColStyles[c] = WorksheetRangeStyle.Clone(colHead.InnerStyle);
                    }
                }
            }
            else if (isFullRowSelected)
            {
                backupRowStyles = new WorksheetRangeStyle[r2 - r1 + 1];
                for (int r = r1; r <= r2; r++)
                {
                    backupRowStyles[r - r1] = WorksheetRangeStyle.Clone(Worksheet.RetrieveRowHeader(r).InnerStyle);
                }
            }
            else if (isFullColSelected)
            {
                backupColStyles = new WorksheetRangeStyle[c2 - c1 + 1];
                for (int c = c1; c <= c2; c++)
                {
                    backupColStyles[c - c1] = WorksheetRangeStyle.Clone(Worksheet.RetrieveColumnHeader(c).InnerStyle);
                }
            }

            Worksheet.SetRangeStyles(affectedRange, style);
        }
示例#33
0
        ///<summary>
        ///</summary>
        ///<param name="startPosition"></param>
        ///<param name="start"></param>
        ///<param name="endPosition"></param>
        ///<param name="end"></param>
        public SelectableRange(RangePosition startPosition, DataObject start,
		                       RangePosition endPosition, DataObject end)
        {
            this.Start = start;
            this.End = end;
            this.StartPosition = startPosition;
            this.endPosition = endPosition;
        }