private void dataViewSheet_FocusPosChanged(object sender, CellPosEventArgs e) { var sheet = reoGridDataView.CurrentWorksheet; currentActiveCell = sheet.Cells[e.Position]; if (sheet[e.Position] != null) { textBox1.Text = sheet[e.Position].ToString(); } else { textBox1.Text = ""; } string temp = sheet.ColumnHeaders[e.Position.Col].Text; if (temp == "VAR") { temp = ""; } label1.Text = e.Position.Row + 1 + " : " + temp; if (sheet[e.Position] != null) { textBox1.Text = sheet[e.Position].ToString(); } else { textBox1.Text = ""; } }
private void ClearReferenceListForCell(ReoGridCell cell) { if (formulaCells.ContainsKey(cell)) formulaCells.Remove(cell); if (formulaRanges.ContainsKey(cell)) formulaRanges.Remove(cell); }
public Size MeasureTextSize(ReoGridCell cell, DrawMode drawMode, float scale) { //using (var typeface = Typeface.Create(cell.InnerStyle.FontName, GetTypefaceStyle(cell.InnerStyle.fontStyles))) //{ using (var p = new Paint()) { Rect bounds = new Rect(); p.SetTypeface(cell.renderFont); p.TextSize = cell.InnerStyle.FontSize * scale; var str = cell.DisplayText; p.GetTextBounds(str, 0, str.Length, bounds); if (str.EndsWith(" ")) { int spaceWidth = (int)Math.Round(p.MeasureText(" ")); for (int i = cell.DisplayText.Length - 1; i >= 0; i--) { if (str[i] == ' ') { bounds.Right += spaceWidth; } else { break; } } } return(new Size(bounds.Width(), bounds.Height())); } //} }
void sheet_CellMouseDown(object sender, CellMouseEventArgs e) { var sheet = reoGridDataView.CurrentWorksheet; currentActiveCell = e.Cell; string temp = sheet.ColumnHeaders[e.CellPosition.Col].Text; if (temp == "VAR") { temp = ""; } label1.Text = e.CellPosition.Row + 1 + " : " + temp; if (e.Cell != null && e.Cell.Data != null) { textBox1.Text = e.Cell.Data.ToString(); } else { textBox1.Text = ""; } if (e.CellPosition.Row == sheet.RowCount - 1) { sheet.InsertRows(sheet.RowCount - 1, 100); } }
public void UpdateCellRenderFont(ReoGridCell cell, Core.UpdateFontReason reason) { if (reason == Core.UpdateFontReason.FontChanged) { if (cell.renderFont != null) { lock (cell.renderFont) { cell.renderFont.Dispose(); } } cell.renderFont = Typeface.Create(cell.InnerStyle.FontName, GetTypefaceStyle(cell.InnerStyle.fontStyles)); } }
public void DrawCellText(ReoGridCell cell, SolidColor textColor, DrawMode drawMode, float scale) { var sheet = cell.Worksheet; if (sheet == null) { return; } var loc = cell.RenderTextBounds.Location; //using (var typeface = Typeface.Create(cell.InnerStyle.FontName, GetTypefaceStyle(cell.InnerStyle.fontStyles))) //{ using (var p = new Paint()) { p.Color = textColor; p.SetTypeface(cell.renderFont); p.TextSize = cell.InnerStyle.FontSize * scale; base.PlatformGraphics.DrawText(cell.DisplayText, loc.X, loc.Y + cell.RenderTextBounds.Height, p); } //} }
public override void OnLostFocus(ReoGridCell cell) { if (IsPressed) { IsPressed = false; } }
protected virtual void OnCellStyleChanged(ReoGridCell cell) { }
public override void OnLostFocus(ReoGridCell cell) { focused = false; }
public object Evaluate(ReoGridCell cell, ICompiledFormula cformula) { var grid = this.Workbook; if (grid == null) { return(null); } var formulaContext = (ReoScriptCompiledFormula)cformula; //var cell = formulaContext.Cell; var formula = formulaContext.Formula; List <ReferenceRange> referencedRanges = formulaContext.ReferencedCellOrRanges as List <ReferenceRange>; if (referencedRanges == null) { formulaContext.ReferencedCellOrRanges = referencedRanges = new List <ReferenceRange>(); } else { referencedRanges.Clear(); } // todo: improve: only create script context once // when set data to a range var ctx = grid.Srm.CreateContext(); // create an global variable getter ctx.ExternalVariableGetter = (id) => { #if FORMULA_CELL_INSTANCE_REF if (id.StartsWith("$")) { var address = id.Substring(1); if (ReoGridPos.IsValidAddress(address)) { var pos = new ReoGridPos(address); return(new RSCellObject(this, pos, cells[pos.Row, pos.Col])); } else { return(null); } } else #endif // FORMULA_CELL_INSTANCE_REF if (ReoGridPos.IsValidAddress(id)) { var pos = new ReoGridPos(id); referencedRanges.Add(new ReferenceRange(grid, pos)); var cell = grid.GetCell(pos); return(cell == null ? 0 : cell.InnerData); } else { NamedRange range = grid.GetNamedRange(id); if (range != null) { referencedRanges.Add(range); var referencedCell = grid.GetCell(range.StartPos); return((referencedCell == null || referencedCell.InnerData == null) ? 0 : referencedCell.InnerData); } else { return(null); } } }; try { // preprocess range syntax formula = RGUtility.RangeReferenceRegex.Replace(formula, (m) => { if (m.Groups["to_col"].Length > 0 && m.Groups["to_row"].Length > 0 && m.Groups["from_col"].Length > 0 && m.Groups["from_row"].Length > 0) { // range int fromRow = -1; if (!int.TryParse(m.Groups["from_row"].Value, out fromRow)) { return("null"); } fromRow--; int toRow = -1; if (!int.TryParse(m.Groups["to_row"].Value, out toRow)) { return("null"); } toRow--; int fromCol = RGUtility.GetNumberOfChar(m.Groups["from_col"].Value); int toCol = RGUtility.GetNumberOfChar(m.Groups["to_col"].Value); if (fromRow < 0) { fromRow = 0; } if (fromCol < 0) { fromCol = 0; } if (toRow > grid.RowCount - 1) { toRow = grid.RowCount - 1; } if (toCol > grid.RowCount - 1) { toCol = grid.ColumnCount - 1; } ReoGridRange range = new ReoGridRange(fromRow, fromCol, toRow - fromRow + 1, toCol - fromCol + 1); referencedRanges.Add(new ReferenceRange(grid, range)); return(string.Format("new Range({0},{1},{2},{3})", range.Row, range.Col, range.Rows, range.Cols)); } else { return(m.Value); } }); return(grid.Srm.CalcExpression(formula, ctx)); } catch (ReoScriptException ex) { Logger.Log("formula", string.Format("error to evaluate formula: ", ex.Message)); throw new FormulaEvalutionException(ex, "#ERR: " + ex.Message); } }
public bool FormatCell(ReoGridControl grid, ReoGridCell cell) { object data = cell.Data; // check numeric bool isNumeric = false; double value = 0; if (data is int) { value = (double)(int)data; isNumeric = true; } else if (data is double) { value = (double)data; isNumeric = true; } else if (data is string) { string strdata = (data as string).Trim(); isNumeric = double.TryParse(strdata, out value); if (isNumeric) cell.Data = value; } if (isNumeric) { if (cell.Style.HAlign == ReoGridHorAlign.General) { cell.RenderHorAlign = ReoGridRenderHorAlign.Right; } cell.Display = Convert.ToString(value); return true; } else return false; }
protected override void OnCellDataChanged(ReoGridCell cell) { }
public void DrawCellText(ReoGridCell cell, SolidColor textColor, DrawMode drawMode, RGFloat scale) { throw new NotImplementedException(); }
public override void OnSetup(ReoGridControl ctrl, ReoGridCell cell) { ImageAnimator.Animate(Gif, OnFrameChanged); }
public RGCellMouseEventArgs(ReoGridControl grid, ReoGridCell cell, Point cursorPos, MouseButtons buttons, int clicks) : this(grid, cell, cell == null ? ReoGridPos.Empty : cell.Pos, cursorPos, buttons, clicks) { }
public RGCellMouseEventArgs(ReoGridControl grid, ReoGridCell cell) : this(grid, cell, cell.Pos, Point.Empty, MouseButtons.None, 0) { }
/// <summary> /// Create instance for CellEventArgs with specified cell. /// </summary> /// <param name="cell">Cell of action performed</param> public RGCellEventArgs(ReoGridCell cell) { this.Cell = cell; }
/// <summary> /// Create instance for CellBeforeEditEventArgs with specified cell. /// </summary> /// <param name="cell">Cell edited by user</param> public RGCellBeforeEditEventArgs(ReoGridCell cell) : base(cell) { }
/// <summary> /// Create instance for CellAfterEditEventArgs /// </summary> /// <param name="cell">Cell edited by user</param> public RGCellAfterEditEventArgs(ReoGridCell cell) : base(cell) { }
public void LoadPage() { grid.IterateCells(grid.SelectionRange, (r, c, cell) => { if (backupFormat == null) { sampleCell = new ReoGridCell(); ReoGridCellUtility.CopyCellContent(sampleCell, cell); if (cell != null) originalData = cell.Data; backupFormat = cell.DataFormat; return true; } else if (backupFormat == cell.DataFormat) { return true; } else { backupFormat = null; return false; } }); currentFormat = backupFormat; backupFormatArgs = null; if (currentFormat != null) { switch (currentFormat) { case CellDataFormatFlag.Number: if (sampleCell.DataFormatArgs is NumberDataFormatter.NumberFormatArgs) { NumberDataFormatter.NumberFormatArgs nargs = (NumberDataFormatter.NumberFormatArgs)sampleCell.DataFormatArgs; numberDecimalPlaces.Value = nargs.DecimalPlaces; chkNumberUseSeparator.Checked = nargs.UseSeparator; foreach (NegativeStyleListItem item in numberNegativeStyleList.Items) { if (item.NegativeStyle == nargs.NegativeStyle) { numberNegativeStyleList.SelectedItem = item; break; } } backupFormatArgs = nargs; } break; case CellDataFormatFlag.DateTime: DateTimeDataFormatter.DateTimeFormatArgs dargs = (DateTimeDataFormatter.DateTimeFormatArgs)sampleCell.DataFormatArgs; txtDatetimeFormat.Text = dargs.Format; int dfindex =-1; for (int i = 0; i < datetimeFormatList.Items.Count; i++) { DatetimeFormatListItem item = (DatetimeFormatListItem)datetimeFormatList.Items[i]; if (item.Pattern.Equals(dargs.Format, StringComparison.CurrentCultureIgnoreCase)) { dfindex = i; break; } } datetimeFormatList.SelectedIndex = dfindex; backupFormatArgs = dargs; break; case CellDataFormatFlag.Currency: CurrencyDataFormatter.CurrencyFormatArgs cargs = (CurrencyDataFormatter.CurrencyFormatArgs)sampleCell.DataFormatArgs; currencyDecimalPlaces.Value = cargs.DecimalPlaces; int cnindex = (int)cargs.NegativeStyle; if (cnindex >= 0 && cnindex < currencyNegativeStyleList.Items.Count) currencyNegativeStyleList.SelectedIndex = cnindex; foreach (NegativeStyleListItem item in currencyNegativeStyleList.Items) { if (item.NegativeStyle == cargs.NegativeStyle) { currencyNegativeStyleList.SelectedItem = item; break; } } backupFormatArgs = cargs; break; case CellDataFormatFlag.Percent: PercentDataFormatter.PercentFormatArgs pargs = (PercentDataFormatter.PercentFormatArgs)sampleCell.DataFormatArgs; percentDecimalPlaces.Value = pargs.DecimalPlaces; backupFormatArgs = pargs; break; } for (int i = 0; i < formatList.Items.Count; i++) { var item = formatList.Items[i].ToString(); if (string.Equals(item, currentFormat.ToString(), StringComparison.CurrentCultureIgnoreCase)) { formatList.SelectedIndex = i; break; } } } else { formatList.SelectedIndex = 0; } backupFormat = currentFormat; }
public override void OnSetup(ReoGridControl ctrl, ReoGridCell cell) { cell.Style.TextColor = Color.Blue; cell.Style.Underline = true; }
public void UpdateCellRenderFont(ReoGridCell cell, UpdateFontReason reason) { throw new NotImplementedException(); }
/// <summary> /// Format given cell /// </summary> /// <param name="grid">Instance of grid control</param> /// <param name="cell">Instance of cell to be formatted</param> /// <returns></returns> public bool FormatCell(ReoGridControl grid, ReoGridCell cell) { object data = cell.Data; // check numeric bool isNumeric = false; double value = 0; if (data is int) { value = (double)(int)data; isNumeric = true; } else if (data is float) { value = (double)(float)data; isNumeric = true; } else if (data is double) { value = (double)data; isNumeric = true; } else if (data is string) { string strdata = (data as string).Trim(); isNumeric = double.TryParse(strdata, out value); if (!isNumeric) isNumeric = double.TryParse(strdata.Replace(",", ""), out value); if (isNumeric) cell.Data = value; } else if (data is DateTime) { value = ((DateTime)data - new DateTime(1900, 1, 1)).TotalDays; isNumeric = true; } if (isNumeric) { if (cell.Style.HAlign == ReoGridHorAlign.General) { cell.RenderHorAlign = ReoGridRenderHorAlign.Right; } short decimals = 2; bool useSeparator = true; NumberNegativeStyle negativeStyle = NumberNegativeStyle.Minus; if (cell.DataFormatArgs != null && cell.DataFormatArgs is NumberFormatArgs) { NumberFormatArgs args = (NumberFormatArgs)cell.DataFormatArgs; decimals = args.DecimalPlaces; negativeStyle = args.NegativeStyle; useSeparator = args.UseSeparator; } else { //cell.DataFormatArgs = new NumberFormatArgs //{ // DecimalPlaces = decimals, // NegativeStyle = negativeStyle, // UseSeparator = true //}; } if (value < 0) { if ((negativeStyle & NumberNegativeStyle.Red) == NumberNegativeStyle.Red) cell.RenderColor = Color.Red; else cell.RenderColor = Color.Empty; } // decimal places string decimalPlacePart = new string('0', decimals); // number string numberPart = (useSeparator ? "#,##0." : "0.") + decimalPlacePart; if ((negativeStyle & NumberNegativeStyle.Brackets) == NumberNegativeStyle.Brackets) { numberPart = (value < 0) ? ("(" + numberPart + ")") : numberPart; } // negative if (negativeStyle != NumberNegativeStyle.Minus) { value = Math.Abs(value); } cell.Display = value.ToString(numberPart); return true; } else return false; }
public Size MeasureTextSize(ReoGridCell cell, DrawMode drawMode, RGFloat scale) { throw new NotImplementedException(); }
protected virtual void OnCellDataChanged(ReoGridCell cell) { }
public RGCellMouseEventArgs(ReoGridControl grid, ReoGridCell cell, ReoGridPos cellPosition, Point cursorPos, MouseButtons buttons, int clicks) { this.Grid = grid; this.Cell = cell; this.CursorPosition = cursorPos; this.Buttons = buttons; this.Clicks = clicks; this.CellPosition = cellPosition; }
internal void FormatCell(ReoGridControl grid, ReoGridCell cell) { // clear cell render color // render color used for draw a negative number cell.RenderColor = Color.Empty; if (cell.DataFormat == CellDataFormatFlag.General) { bool found = false; foreach (CellDataFormatFlag flag in dataFormatters.Keys) { var formatter = dataFormatters[flag]; if (formatter.PerformTestFormat() && dataFormatters[flag].FormatCell(grid, cell)) { cell.DataFormat = flag; found = true; break; } } if (!found) { cell.Display = Convert.ToString(cell.Data); // if horizontal-align is auto self-adapt, // set the render alignment to left for string type if (cell.Style.HAlign == ReoGridHorAlign.General) { cell.RenderHorAlign = ReoGridRenderHorAlign.Left; } } } else { bool success = DataFormatters[cell.DataFormat].FormatCell(grid, cell); if (!success) { DataFormatters[CellDataFormatFlag.Text].FormatCell(grid, cell); } } }
public bool FormatCell(ReoGridControl grid, ReoGridCell cell) { bool isFormat = false; object data = cell.Data; double currency = double.NaN; if (data is double) { isFormat = true; currency = (double)data; } else if (data is DateTime) { currency = (new DateTime(1900, 1, 1) - (DateTime)data).TotalDays; isFormat = true; } else { string str = Convert.ToString(data).Trim(); string number = string.Empty; if (str.StartsWith("$")) { number = str.Substring(1); if (double.TryParse(number, out currency)) { isFormat = true; cell.Data = currency; } } else { DateTime date = new DateTime(1900, 1, 1); if (DateTime.TryParse(str, out date)) { currency = (date - new DateTime(1900, 1, 1)).TotalDays; isFormat = true; } else { isFormat = double.TryParse(str, out currency); } } } if (isFormat) { if (cell.Style.HAlign == ReoGridHorAlign.General) { cell.RenderHorAlign = ReoGridRenderHorAlign.Right; } string symbol = null; short decimals = 2; NumberDataFormatter.NumberNegativeStyle negativeStyle = NumberDataFormatter.NumberNegativeStyle.Minus; if (cell.DataFormatArgs != null && cell.DataFormatArgs is CurrencyFormatArgs) { CurrencyFormatArgs args = (CurrencyFormatArgs)cell.DataFormatArgs; symbol = args.Symbol; decimals = args.DecimalPlaces; negativeStyle = args.NegativeStyle; } else { symbol = Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol; cell.DataFormatArgs = new CurrencyFormatArgs { Symbol = symbol, DecimalPlaces = decimals }; } if (currency < 0) { if ((negativeStyle & NumberDataFormatter.NumberNegativeStyle.Red) == NumberDataFormatter.NumberNegativeStyle.Red) cell.RenderColor = Color.Red; else cell.RenderColor = Color.Empty; } // decimal places string decimalPlacePart = new string('0', decimals); // number string numberPart = symbol + "#,##0." + decimalPlacePart; if ((negativeStyle & NumberDataFormatter.NumberNegativeStyle.Brackets) == NumberDataFormatter.NumberNegativeStyle.Brackets) { numberPart = (currency < 0) ? ("(" + numberPart + ")") : numberPart; } // negative if (negativeStyle != NumberDataFormatter.NumberNegativeStyle.Minus) { currency = Math.Abs(currency); } cell.Display = currency.ToString(numberPart); //string decimalPlaceFormat = new string('0', decimalPlaces); //cell.Display = string.Format("{0}{1:#,##0." + decimalPlaceFormat + "}", symbol, currency); } return isFormat; }
public override void OnSetup(ReoGridControl ctrl, ReoGridCell cell) { // set text to center cell.Style.HAlign = ReoGridHorAlign.Center; cell.Style.VAlign = ReoGridVerAlign.Middle; }
public bool FormatCell(ReoGridControl grid, ReoGridCell cell) { object data = cell.Data; bool isFormat = false; DateTime value = new DateTime(1900, 1, 1); if (data is DateTime) { value = (DateTime)data; isFormat = true; } else if (data is double) { try { value = value.AddDays((double)data); isFormat = true; } catch { } } else { string strdata = Convert.ToString(data); double days = 0; if (double.TryParse(strdata, out days)) { try { value = value.AddDays(days); isFormat = true; } catch { } } else { isFormat = (DateTime.TryParse(strdata, out value)); } } if (isFormat) { if (cell.Style.HAlign == ReoGridHorAlign.General) { cell.RenderHorAlign = ReoGridRenderHorAlign.Right; } CultureInfo culture = null; string format = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern; if (cell.DataFormatArgs != null && cell.DataFormatArgs is DateTimeFormatArgs) { DateTimeFormatArgs dargs = (DateTimeFormatArgs)cell.DataFormatArgs; format = dargs.Format; culture = new CultureInfo(dargs.CultureName); } else { culture = System.Threading.Thread.CurrentThread.CurrentCulture; cell.DataFormatArgs = new DateTimeFormatArgs { Format = format, CultureName = culture.Name }; } cell.Display = value.ToString(format, culture); } return isFormat; }
public override void OnBoundsChanged(ReoGridCell cell) { int minButtonSize = Math.Min(Math.Min(Bounds.Width, Bounds.Height), RadioButtonSize); int x = 0, y = 0; switch (cell.Style.HAlign) { case ReoGridHorAlign.Left: x = Bounds.X + 1; break; case ReoGridHorAlign.Center: x = Bounds.X + (Bounds.Width - minButtonSize) / 2; break; case ReoGridHorAlign.Right: x = Bounds.Right - minButtonSize - 1; break; } switch (cell.Style.VAlign) { case ReoGridVerAlign.Top: y = Bounds.Y + 1; break; case ReoGridVerAlign.Middle: y = Bounds.Y + (Bounds.Height - minButtonSize) / 2; break; case ReoGridVerAlign.Bottom: y = Bounds.Bottom - minButtonSize - 1; break; } CheckRect = new Rectangle(x, y, minButtonSize, minButtonSize); }
public bool FormatCell(ReoGridControl grid, ReoGridCell cell) { object data = cell.Data; double percent = 0; bool isFormat = false; short dec = 0; if (data is double) { percent = (double)data; isFormat = true; dec = 9; } else if (data is DateTime) { percent = ((DateTime)data - new DateTime(1900, 1, 1)).TotalDays; isFormat = true; dec = 0; } else { string str = Convert.ToString(data); if (str.Length > 1 && str.EndsWith("%")) { str = str.Substring(0, str.Length - 1); isFormat = double.TryParse(str, out percent); if (isFormat) { int decimalPlaceIndex = str.LastIndexOf('.'); if (decimalPlaceIndex >= 0) { dec = (short)(str.Length - decimalPlaceIndex); } } } else { isFormat = double.TryParse(str, out percent); if (!isFormat) { DateTime date = new DateTime(1900, 1, 1); if (DateTime.TryParse(str, out date)) { percent = (date - new DateTime(1900, 1, 1)).TotalDays; isFormat = true; } } // should not use 'else' here if (isFormat) { int decimalPlaceIndex = str.LastIndexOf('.'); if (decimalPlaceIndex >= 0) { dec = (short)(str.Length - decimalPlaceIndex); } } } if (isFormat) cell.Data = percent; } if (isFormat) { if (cell.DataFormatArgs != null && cell.DataFormatArgs is PercentFormatArgs) { dec = ((PercentFormatArgs)cell.DataFormatArgs).DecimalPlaces; } else { cell.DataFormatArgs = new PercentFormatArgs { DecimalPlaces = dec }; } string decimalPlacePart = new string('0', dec); cell.Display = percent.ToString("0." + decimalPlacePart) + "%"; if (cell.Style.HAlign == ReoGridHorAlign.General) { cell.RenderHorAlign = ReoGridRenderHorAlign.Right; } } return isFormat; }
public override void OnBoundsChanged(ReoGridCell cell) { dropdownButtonRect.X = Bounds.Right - DropdownButtonSize.Width; dropdownButtonRect.Y = Bounds.Top + (Bounds.Height - DropdownButtonSize.Height) / 2; }
public bool FormatCell(ReoGridControl grid, ReoGridCell cell) { cell.Display = Convert.ToString(cell.Data); if (cell.Style.HAlign == ReoGridHorAlign.General) { cell.RenderHorAlign = ReoGridRenderHorAlign.Left; } return true; }
public override void OnLostFocus(ReoGridCell cell) { PullUp(); }
public override void OnGotFocus(ReoGridCell cell) { focused = true; }
public override void OnSetup(ReoGridControl ctrl, ReoGridCell cell) { this.GridInstance = ctrl; this.Cell = cell; }
public override bool OnStartEdit(ReoGridCell cell) { return false; }
public override bool OnStartEdit(ReoGridCell cell) { PushDown(); return false; }