コード例 #1
0
ファイル: Data.cs プロジェクト: regous/ReoGrid
        private void AutoFillSerialCells(List <CellPosition> fromCells, List <CellPosition> toCells)
        {
            if (!fromCells.Any() || !toCells.Any())
            {
                return;
            }

            var autoFillSequenceInput = fromCells
                                        .Select(cellPosition => this[cellPosition])
                                        .ToList();
            var          autoFillSequence           = new AutoFillSequence(autoFillSequenceInput);
            var          autoFillExtrapolatedValues = autoFillSequence.Extrapolate(toCells.Count);
            DragCellData dragCellData = new DragCellData()
            {
                FromCells = new List <CellPosition>(fromCells),
                ToCells   = new List <CellPosition>(toCells)
            };

            for (var toCellIndex = 0; toCellIndex < toCells.Count; toCellIndex++)
            {
                var fromCellIndex    = toCellIndex % fromCells.Count;
                var fromCellPosition = fromCells[fromCellIndex];
                var fromCell         = Cells[fromCellPosition];
                var toCellPosition   = toCells[toCellIndex];
                var toCell           = Cells[toCellPosition];

                if (!string.IsNullOrEmpty(fromCell?.InnerFormula))
                {
                    FormulaRefactor.Reuse(this, fromCellPosition, new RangePosition(toCellPosition));
                }
                else
                {
                    toCell.DataFormat     = fromCell.DataFormat;
                    toCell.DataFormatArgs = fromCell.DataFormatArgs;

                    //toCell.Data = autoFillExtrapolatedValues[toCellIndex];
                    dragCellData.Data = autoFillExtrapolatedValues[toCellIndex];
                    if (toCell.SetDragData(dragCellData) == false)
                    {
                        break;
                    }
                    toCell.Style = fromCell.Style;
                    //toCell.Style.HAlign = fromCell.Style.HAlign;
                    //toCell.Style.VAlign = fromCell.Style.VAlign;
                    //toCell.Style.TextColor = fromCell.Style.TextColor;
                    //toCell.Style.FontName = fromCell.Style.FontName;
                    //toCell.Style.FontSize = fromCell.Style.FontSize;
                    //toCell.Style.Bold = fromCell.Style.Bold;
                    //toCell.Style.Italic = fromCell.Style.Italic;
                    //toCell.Style.Strikethrough = fromCell.Style.Strikethrough;
                    //toCell.Style.Underline = fromCell.Style.Underline;
                    //toCell.Style.TextWrap = fromCell.Style.TextWrap;
                    //toCell.Style.Indent = fromCell.Style.Indent;
                    //toCell.Style.Padding = fromCell.Style.Padding;
                    //toCell.Style.RotationAngle = fromCell.Style.RotationAngle;
                }
            }
        }
コード例 #2
0
 internal bool SetDragData(DragCellData value)
 {
     if (this.worksheet != null)
     {
         // update cell data
         return(this.worksheet.SetDragSingleCellData(this, value));
     }
     else
     {
         this.InnerData = value.Data;
         return(true);
     }
 }
コード例 #3
0
        private bool AfterDragCellDataUpdate(Cell cell, DragCellData data, Stack <List <Cell> > dirtyCellStack = null)
        {
#if FORMULA
            if ((this.settings & WorksheetSettings.Formula_AutoUpdateReferenceCell)
                == WorksheetSettings.Formula_AutoUpdateReferenceCell)
            {
                UpdateReferencedFormulaCells(cell, dirtyCellStack);
            }
#endif // FORMULA

#if DRAWING
            if (cell.Data is Drawing.RichText)
            {
                var rt = (Drawing.RichText)cell.Data;

                rt.SuspendUpdateText();
                rt.Size     = cell.Bounds.Size;
                rt.TextWrap = cell.InnerStyle.TextWrapMode;
                rt.ResumeUpdateText();
                rt.UpdateText();
            }
            else
#endif // DRAWING
            {
                cell.FontDirty = true;
            }

            if (this.controlAdapter != null &&
                !this.viewDirty &&
                !this.suspendDataChangedEvent)
            {
                this.RequestInvalidate();
            }

            if (!this.suspendDataChangedEvent)
            {
                var header = this.cols[cell.Column];

                if (header.Body != null)
                {
                    header.Body.OnDataChange(cell.Row, cell.Row);
                }

                // raise text changed event
                if (RaiseDragCellDataChangedEvent(cell, data) == false)
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #4
0
        internal bool RaiseDragCellDataChangedEvent(Cell cell, DragCellData data)
        {
            if (DragCellDataChanged != null)
            {
                DragCellEventArgs eventargs = new DragCellEventArgs(cell)
                {
                    FromCells = data.FromCells,
                    ToCells   = data.ToCells
                };
                DragCellDataChanged(this, eventargs);
                if (eventargs.IsCancelled)
                {
                    return(false);
                }
            }
#if EX_SCRIPT
            RaiseScriptEvent("ondatachange", new RSCellObject(this, cell.InternalPos, cell));
#endif
            return(true);
        }
コード例 #5
0
        internal bool DragUpdateCellData(Cell cell, DragCellData data, Stack <List <Cell> > dirtyCellStack = null)
        {
            if (cell.body != null)
            {
                data.Data = cell.body.OnSetData(data.Data);
            }

            cell.InnerData = data.Data;

            if (this.HasSettings(WorksheetSettings.Edit_AutoFormatCell))
            {
                DataFormatterManager.Instance.FormatCell(cell);
            }
            else
            {
                cell.InnerDisplay = Convert.ToString(data.Data);
            }

#if WPF
            cell.formattedText = null;

            //if (cell.FormattedText == null || cell.FormattedText.Text != cell.InnerDisplay)
            //{
            //	float fontSize = cell.InnerStyle.FontSize * this.scaleFactor * (96f / 72f);

            //	cell.FormattedText = new System.Windows.Media.FormattedText(cell.InnerDisplay,
            //		System.Globalization.CultureInfo.CurrentCulture,
            //		System.Windows.FlowDirection.LeftToRight,
            //		ResourcePoolManager.Instance.GetTypeface(cell.InnerStyle.FontName),
            //		fontSize,
            //		ResourcePoolManager.Instance.GetBrush(cell.InnerStyle.TextColor));
            //}
#endif

            return(AfterDragCellDataUpdate(cell, data, dirtyCellStack));
        }
コード例 #6
0
        internal bool SetDragSingleCellData(Cell cell, DragCellData data)
        {
            var args = new BeforeCellDataChangedEventArgs(cell, data.Data, cell.Data);

            BeforeCellDataChanged?.Invoke(this, args);
            if (args.IsCancelled)
            {
                return(false);
            }
            // set cell body
            if (data.Data is ICellBody)
            {
                SetCellBody(cell, (ICellBody)data.Data);

                data.Data = cell.InnerData;
            }

            if (data.Data is string || data.Data is StringBuilder
#if EX_SCRIPT
                || data is StringObject
#endif // EX_SCRIPT
                )
            {
                string str = data.Data is string?(string)(data.Data) : Convert.ToString(data.Data);

                // cell data processed as plain-text
                if (str.Length > 1)
                {
                    if (str[0] == '\'')
                    {
#if FORMULA
                        // clear old references
                        ClearCellReferenceList(cell);

                        // clear dependents arrows
                        RemoveCellTraceDependents(cell);

                        // clear precedents arrow
                        RemoveCellTracePrecedents(cell);

                        // clear formula status
                        cell.formulaStatus = FormulaStatus.Normal;
#endif // FORMULA

                        cell.InnerData    = data.Data;
                        cell.InnerDisplay = str.Substring(1);

                        AfterCellDataUpdate(cell);
                        return(true);
                    }

#if FORMULA
                    if (str[0] == '=')
                    {
                        SetCellFormula(cell, str.Substring(1));

                        try
                        {
                            RecalcCell(cell);
                        }
                        catch (Exception ex)
                        {
                            this.NotifyExceptionHappen(ex);
                        }

                        return(true);
                    }
#endif // FORMULA
                }
            }

            // experimental: directly set an image as cell data
            //
            //else if (data is System.Drawing.Image)
            //{
            //	if (cell.body == null)
            //	{
            //		cell.Body = new ImageCell((System.Drawing.Image)data);
            //	}
            //	else if (cell.body is ImageCell)
            //	{
            //		((ImageCell)cell.body).Image = (System.Drawing.Image)data;
            //	}
            //}

#if FORMULA
            if (formulaRanges.Count > 0)
            {
                // clear old references
                ClearCellReferenceList(cell);
            }

            // clear cell formula
            cell.InnerFormula = null;

            // clear formula status
            cell.formulaStatus = FormulaStatus.Normal;
#endif // FORMULA

            return(DragUpdateCellData(cell, data));
        }