示例#1
0
 void worksheet_BeforeSelectionRangeChange(object sender, Events.BeforeSelectionChangeEventArgs e)
 {
     if (chkLimitSelection.Checked)
     {
         // Check the start and end position of the new selection range
         // Abort operations if any selection position not be included in the list defined above
         e.IsCancelled = !validRanges.Any(vr =>
         {
             var range = new RangePosition(vr);
             return(range.Contains(e.SelectionStart) && range.Contains(e.SelectionEnd));
         });
     }
 }
示例#2
0
 void worksheet_BeforeSelectionRangeChange(object sender, Events.BeforeSelectionChangeEventArgs e)
 {
     // 選択範囲を制御する場合
     if (chkLimitSelection.Checked)
     {
         // 選択範囲が変更された場合、選択可能な範囲に囲まれるかどうかをチェックする
         // 選択可能な範囲からはみ出る場合、IsCancelledプロパティをtrueに設定して選択操作を禁止
         e.IsCancelled = !validRanges.Any(vr =>
         {
             var range = new RangePosition(vr);
             return(range.Contains(e.SelectionStart) && range.Contains(e.SelectionEnd));
         });
     }
 }
示例#3
0
        void worksheet_CellDataChanged(object sender, Events.CellEventArgs e)
        {
            var pos = e.Cell.Position;

            if (dataRange.Contains(pos) || this.LabelAddress == pos)
            {
                this.dataSource.OnDataChanged();
            }
        }
示例#4
0
        private void btnSetEditableRange_Click(object sender, EventArgs ee)
        {
            var editableRange = new RangePosition("B5:E6");

            var worksheet = grid.CurrentWorksheet;

            worksheet.SetRangeBorders(editableRange, BorderPositions.Outside, RangeBorderStyle.BlackSolid);

            worksheet["B4"]           = "Edit only be allowed in this range:";
            worksheet.BeforeCellEdit += (s, e) => e.IsCancelled = !editableRange.Contains(e.Cell.Position);
        }
示例#5
0
        internal static void Reuse(Worksheet sheet, CellPosition fromPosition, RangePosition toRange)
        {
            fromPosition = sheet.FixPos(fromPosition);
            toRange      = sheet.FixRange(toRange);

            var cell = sheet.cells[fromPosition.Row, fromPosition.Col];

            #region Arguments Check
            if (cell == null ||
                string.IsNullOrEmpty(cell.InnerFormula) ||
                cell.FormulaTree == null)
            {
                throw new InvalidOperationException("cannot found formula from specified position, try reset formula for the cell again");
            }

            if (cell.formulaStatus != Formula.FormulaStatus.Normal)
            {
                throw new InvalidOperationException("formula in specified cell contains errors, correct the formula firstly");
            }

            if (toRange.Contains(fromPosition))
            {
                throw new ArgumentException("toRange should not contain the position of the formula to be reused");
            }
            #endregion             // Arguments Check

            var    rs   = new ReplacableString(cell.InnerFormula);
            STNode node = cell.FormulaTree;

            Stack <List <Cell> > dirtyCells = new Stack <List <Cell> >();

            for (int r = toRange.Row; r <= toRange.EndRow; r++)
            {
                for (int c = toRange.Col; c <= toRange.EndCol;)
                {
                    var toCell = sheet.CreateAndGetCell(r, c);

                    if (toCell.Colspan <= 0)
                    {
                        c++;
                        continue;
                    }

                    FormulaRefactor.CopyFormula(fromPosition, node, toCell, rs, dirtyCells);

                    c += cell.Colspan;
                }
            }
        }