private void ApplyRow(Worksheet sheet, object item) { var itemObj = ((IDictionary <string, Object>)item); if (!itemObj.ContainsKey("row") || !itemObj.ContainsKey("col") || !itemObj.ContainsKey("value")) { return; } var row = (int)itemObj["row"]; var col = (int)itemObj["col"]; AutoAppend(sheet, row, col); sheet[row, col] = itemObj["value"]; sheet.Cells[row, col].Data = itemObj["value"]; if (itemObj.ContainsKey("border")) { var borderStyle = new RangeBorderStyle(unvell.ReoGrid.Graphics.SolidColor.Black, BorderLineStyle.Solid); sheet.SetRangeBorders(row, col, 1, 1, BorderPositions.All, borderStyle); } if (itemObj.ContainsKey("fontsize")) { var fontSize = (int)itemObj["fontsize"]; sheet.Cells[row, col].Style.FontSize = Convert.ToSingle(fontSize); } }
private void btnBordersClear_Click(object sender, EventArgs e) { var MyStyleBorder2 = new RangeBorderStyle(); MyStyleBorder2.Color = Color.Empty; rGrid.CurrentWorksheet.RemoveRangeBorders(rGrid.CurrentWorksheet.SelectionRange, BorderPositions.All); }
private void btnBordersInside_Click(object sender, EventArgs e) { var MyStyleBorder1 = new RangeBorderStyle(); MyStyleBorder1.Style = BorderLineStyle.BoldSolid; MyStyleBorder1.Color = Color.Black; rGrid.CurrentWorksheet.SetRangeBorders(rGrid.CurrentWorksheet.SelectionRange, BorderPositions.InsideAll, MyStyleBorder1); }
internal RGXmlBorder(int row, int col, RangeBorderStyle borderStyle, string pos) { this.row = row; this.col = col; this.pos = pos; if (borderStyle.Color != SolidColor.Black) { color = TextFormatHelper.EncodeColor(borderStyle.Color); } if (borderStyle.Style != BorderLineStyle.Solid) { style = borderStyle.Style.ToString(); } }
public void CheckBorderStyle(BorderPositions pos) { ProcessBorderStyles(pos, p => { borders[p] = new RangeBorderStyle { Style = currentBorderStlye, Color = currentColor, }; mixBorders &= ~p; }); borderAdded |= pos; borderRemoved &= ~pos; Invalidate(); }
/// <summary> /// Initialize dialog panel /// </summary> public void LoadPage() { borderSetter.ReadFromGrid(grid); btnCenter.Enabled = borderSetter.Rows > 1; btnMiddle.Enabled = borderSetter.Cols > 1; RangeBorderStyle style = borderSetter.Borders.Values.FirstOrDefault(); if (!style.IsEmpty) { borderStyleList.SelectedBorderStyle = style.Style; borderColorSelector.SolidColor = style.Color; borderColorSelector.RaiseColorPicked(); } }
/// <summary> /// Draw border at specified location /// </summary> /// <param name="g">instance for graphics object</param> /// <param name="x">x coordinate of start point</param> /// <param name="y">y coordinate of start point</param> /// <param name="x2">x coordinate of end point</param> /// <param name="y2">y coordinate of end point</param> /// <param name="style">style instance of border</param> public void DrawLine(PlatformGraphics g, RGFloat x, RGFloat y, RGFloat x2, RGFloat y2, RangeBorderStyle style) { DrawLine(g, x, y, x2, y2, style.Style, style.Color); }
internal RangePosition SetPartialGrid(RangePosition toRange, PartialGrid data, PartialGridCopyFlag flag, ExPartialGridCopyFlag exFlag) { if (toRange.IsEmpty) { return(toRange); } toRange = FixRange(toRange); int rows = data.Rows; int cols = data.Columns; if (rows + toRange.Row > this.rows.Count) { rows = this.rows.Count - toRange.Row; } if (cols + toRange.Col > this.cols.Count) { cols = this.cols.Count - toRange.Col; } if (((flag & PartialGridCopyFlag.CellData) == PartialGridCopyFlag.CellData || (flag & PartialGridCopyFlag.CellStyle) == PartialGridCopyFlag.CellStyle)) { for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { Cell fromCell = data.Cells == null ? null : data.Cells[r, c]; int tr = toRange.Row + r; int tc = toRange.Col + c; bool processed = false; if (fromCell != null) { #region Merge from right side // from cell copied as part of merged cell if ( // is part of merged cell !fromCell.MergeStartPos.IsEmpty && fromCell.MergeStartPos.Col < toRange.Col // is right side -------+-- (undo from delete column at end of merged range) && (fromCell.InternalCol - fromCell.MergeStartPos.Col > tc - toRange.Col // not inside --+----+-- && fromCell.MergeEndPos.Col <= toRange.EndCol)) { // from cell inside existed merged range // these two ranges should be merged // the original range must be expanded Cell fromMergedStart = CreateAndGetCell(fromCell.MergeStartPos); fromMergedStart.MergeEndPos = new CellPosition(fromMergedStart.MergeEndPos.Row, tc); fromMergedStart.Colspan = (short)(tc - fromMergedStart.InternalCol + 1); for (int ic = fromMergedStart.InternalCol; ic < fromMergedStart.InternalCol + fromMergedStart.Colspan; ic++) { var insideCell = cells[tr, ic]; if (insideCell != null) { insideCell.MergeEndPos = new CellPosition(insideCell.MergeEndPos.Row, tc); } } Cell tocell = CreateAndGetCell(tr, tc); tocell.MergeStartPos = fromMergedStart.InternalPos; tocell.MergeEndPos = new CellPosition(fromMergedStart.MergeEndPos.Row, tc); tocell.Colspan = 0; tocell.Rowspan = 0; if (tocell.IsEndMergedCell) { fromMergedStart.Bounds = GetRangePhysicsBounds(new RangePosition( fromMergedStart.InternalPos, fromMergedStart.MergeEndPos)); } processed = true; } #endregion #region Merge from left side // usually used when undo action: when deleting column from left side of merged cell else if ( !fromCell.MergeEndPos.IsEmpty // added 3/15/2016: check two unrelated ranges && toRange.ContainsRow(fromCell.Row) && fromCell.MergeEndPos.Col > toRange.EndCol && fromCell.MergeStartPos.Col <= toRange.EndCol ) { // target partial range will override exsited range // need to update existed range at right side int rightCol = Math.Min(fromCell.MergeEndPos.Col, this.cols.Count - 1); Cell tocell = CreateAndGetCell(tr, tc); tocell.MergeStartPos = new CellPosition(fromCell.MergeStartPos.Row, fromCell.MergeStartPos.Col + tc - fromCell.InternalCol); tocell.MergeEndPos = new CellPosition(fromCell.MergeEndPos.Row, rightCol); for (int ic = toRange.EndCol + 1; ic <= rightCol; ic++) { var existedEndCell = CreateAndGetCell(tr, ic); existedEndCell.MergeStartPos = tocell.MergeStartPos; existedEndCell.Rowspan = 0; existedEndCell.Colspan = 0; } if (tocell.IsStartMergedCell) { tocell.Rowspan = (short)(tocell.MergeEndPos.Row - tocell.MergeStartPos.Row + 1); tocell.Colspan = (short)(tocell.MergeEndPos.Col - tocell.MergeStartPos.Col + 1); tocell.Bounds = GetRangeBounds(tocell.InternalPos, tocell.MergeEndPos); // copy cell content CellUtility.CopyCellContent(tocell, fromCell); UpdateCellFont(tocell); } else { tocell.Rowspan = 0; tocell.Colspan = 0; } processed = true; } #endregion // Merge from left side #region Merge from bottom else if ( !fromCell.MergeStartPos.IsEmpty // above && fromCell.MergeStartPos.Row < toRange.Row // merged start row in the above of target fill range && fromCell.InternalRow - fromCell.MergeStartPos.Row > tr - toRange.Row // not inside current merged range && fromCell.MergeEndPos.Row <= toRange.EndRow) { var mergedStartCell = CreateAndGetCell(fromCell.MergeStartPos); mergedStartCell.Rowspan = (short)(tr - mergedStartCell.InternalRow + 1); for (int ir = fromCell.MergeStartPos.Row; ir < tr; ir++) { var existedCell = CreateAndGetCell(ir, tc); existedCell.MergeEndPos = new CellPosition(tr, fromCell.MergeEndPos.Col); } var tocell = CreateAndGetCell(tr, tc); tocell.MergeStartPos = mergedStartCell.InternalPos; tocell.MergeEndPos = new CellPosition(tr, fromCell.MergeEndPos.Col); tocell.Rowspan = 0; tocell.Colspan = 0; if (tocell.IsEndMergedCell) { mergedStartCell.Bounds = GetRangeBounds(mergedStartCell.InternalPos, mergedStartCell.MergeEndPos); } processed = true; } #endregion // Merge from bottom #region Merge from top // usually used when undo action: when deleting column from top side of merged cell else if ( !fromCell.MergeEndPos.IsEmpty // added 3/15/2016: check two unrelated ranges && toRange.ContainsColumn(fromCell.Column) && fromCell.MergeEndPos.Row > toRange.EndRow && fromCell.MergeStartPos.Row <= toRange.EndRow) { // target partial range will override exsited range // need to update existed range at right side int bottomRow = Math.Min(fromCell.MergeEndPos.Row, this.rows.Count - 1); for (int ir = toRange.EndRow + 1; ir <= bottomRow; ir++) { var existedEndCell = CreateAndGetCell(ir, tc); existedEndCell.MergeStartPos = new CellPosition(fromCell.MergeStartPos.Row, existedEndCell.MergeStartPos.Col); existedEndCell.Rowspan = 0; existedEndCell.Colspan = 0; } Cell tocell = CreateAndGetCell(tr, tc); tocell.MergeStartPos = fromCell.MergeStartPos; tocell.MergeEndPos = new CellPosition(bottomRow, fromCell.MergeEndPos.Col); if (tocell.IsStartMergedCell) { tocell.Rowspan = (short)(tocell.MergeEndPos.Row - tocell.MergeStartPos.Row + 1); tocell.Colspan = (short)(tocell.MergeEndPos.Col - tocell.MergeStartPos.Col + 1); tocell.Bounds = GetRangeBounds(tocell.InternalPos, tocell.MergeEndPos); // copy cell content CellUtility.CopyCellContent(tocell, fromCell); UpdateCellFont(tocell); } else { tocell.Rowspan = 0; tocell.Colspan = 0; } processed = true; } #endregion // Merge from top } if (!processed) { Cell toCell = CreateAndGetCell(tr, tc); if (toCell.Rowspan == 0 && toCell.Colspan == 0) { continue; } if (fromCell != null) { #region Copy Data if ((flag & PartialGridCopyFlag.CellData) == PartialGridCopyFlag.CellData) { CellUtility.CopyCellContent(toCell, fromCell); } #endregion // Copy Data #region Format Formula #if FORMULA if ((flag & PartialGridCopyFlag.CellFormula) == PartialGridCopyFlag.CellFormula) { if (fromCell.HasFormula) { if (fromCell.formulaTree == null) { try { fromCell.formulaTree = Formula.Parser.Parse(this.workbook, fromCell, fromCell.InnerFormula); } catch { fromCell.formulaStatus = FormulaStatus.SyntaxError; } } if (fromCell.formulaTree != null) { var rs = new ReplacableString(fromCell.InnerFormula); Stack <List <Cell> > dirtyCells = new Stack <List <Cell> >(); FormulaRefactor.CopyFormula(fromCell.Position, fromCell.formulaTree, toCell, rs, dirtyCells); } toCell.FontDirty = true; } } else { toCell.InnerFormula = null; } #endif // FORMULA #endregion // Formula Formula #region Copy Merged info // is single cell if (toCell.Rowspan == 1 && toCell.Colspan == 1) { // then copy span info toCell.Rowspan = fromCell.Rowspan; toCell.Colspan = fromCell.Colspan; if (!fromCell.MergeStartPos.IsEmpty) { toCell.MergeStartPos = fromCell.MergeStartPos.Offset(tr - fromCell.InternalRow, tc - fromCell.InternalCol); #if DEBUG Debug.Assert(toCell.MergeStartPos.Row >= 0 && toCell.MergeStartPos.Row < this.rows.Count); Debug.Assert(toCell.MergeStartPos.Col >= 0 && toCell.MergeStartPos.Col < this.cols.Count); #endif } if (!fromCell.MergeEndPos.IsEmpty) { toCell.MergeEndPos = fromCell.MergeEndPos.Offset(tr - fromCell.InternalRow, tc - fromCell.InternalCol); #if DEBUG Debug.Assert(toCell.MergeEndPos.Row >= 0 && toCell.MergeEndPos.Row < this.rows.Count); Debug.Assert(toCell.MergeEndPos.Col >= 0 && toCell.MergeEndPos.Col < this.cols.Count); #endif } } else { UpdateCellFont(toCell); } #endregion // Copy Merged info #region Cell Styles if (((flag & PartialGridCopyFlag.CellStyle) == PartialGridCopyFlag.CellStyle) && fromCell.InnerStyle != null) { if (fromCell.StyleParentKind == StyleParentKind.Own) { // from cell has own style, need copy the style toCell.InnerStyle = new WorksheetRangeStyle(fromCell.InnerStyle); } else { // from cell doesn't have own style, copy the reference of style toCell.InnerStyle = fromCell.InnerStyle; } // copy style parent flag toCell.StyleParentKind = fromCell.StyleParentKind; // TODO: render alignment is not contained in cell's style // copy the style may also need copy the render alignment // or we need to update the cell format again? if (fromCell.InnerStyle.HAlign == ReoGridHorAlign.General) { toCell.RenderHorAlign = fromCell.RenderHorAlign; } } #endregion // Cell Styles if (toCell.IsEndMergedCell) { Cell cell = GetCell(toCell.MergeStartPos); Debug.Assert(cell != null); UpdateCellBounds(cell); } else if (toCell.Rowspan == 1 && toCell.Colspan == 1) { UpdateCellFont(toCell); } } else { cells[tr, tc] = null; } } } } } // h-borders if ((flag & PartialGridCopyFlag.HBorder) == PartialGridCopyFlag.HBorder) { if (data.HBorders == null) { // cut left side border if (toRange.Col > 0) { for (int r = toRange.Row; r <= toRange.EndRow; r++) { this.CutBeforeHBorder(r, toRange.Col); } } // set borders to null this.hBorders.Iterate(toRange.Row, toRange.Col, rows, cols, true, (r, c, fromHBorder) => { this.hBorders[r, c] = null; return(1); } ); } else { // TODO: need to improve performance for (int r = 0; r < rows + 1; r++) { for (int c = 0; c < cols; c++) { int tr = toRange.Row + r; int tc = toRange.Col + c; this.CutBeforeHBorder(tr, tc); var fromHBorder = data.HBorders[r, c]; if (fromHBorder == null) { hBorders[tr, tc] = null; } else { RangeBorderStyle style = fromHBorder.Style; int hcols = fromHBorder.Span; if (hcols > cols - c) { hcols = cols - c; } this.GetHBorder(tr, tc).Span = hcols; if (data.HBorders[r, c].Style != null) { // in last col //if (c == cols - 1) // SetHBorders(tr, tc, hcols, style, fromHBorder.Pos); //else // hBorders[tr, tc].Border = style; SetHBorders(tr, tc, hcols, style, fromHBorder.Pos); } else { hBorders[tr, tc].Style = RangeBorderStyle.Empty; } } } } } } // v-borders if ((flag & PartialGridCopyFlag.VBorder) == PartialGridCopyFlag.VBorder) { if (data.VBorders == null) { // cut top side border if (toRange.Row > 0) { for (int c = toRange.Col; c <= toRange.EndCol; c++) { CutBeforeVBorder(toRange.Row, c); } } // set border to null this.vBorders.Iterate(toRange.Row, toRange.Col, rows, cols, true, (r, c, fromVBorder) => { this.vBorders[r, c] = null; return(1); } ); } else { // TODO: need to improve performance for (int r = 0; r < rows; r++) { for (int c = 0; c < cols + 1; c++) { int tr = toRange.Row + r; int tc = toRange.Col + c; this.CutBeforeVBorder(tr, tc); var fromVBorder = data.VBorders[r, c]; if (fromVBorder == null) { vBorders[tr, tc] = null; } else { RangeBorderStyle style = fromVBorder.Style; int vrows = fromVBorder.Span; if (vrows > rows - r) { vrows = rows - r; } GetVBorder(tr, tc).Span = vrows; if (data.VBorders[r, c].Style != null) { // is last row //if (r == rows - 1) // SetVBorders(tr, tc, vrows, style, fromVBorder.Pos); //else // vBorders[tr, tc].Border = fromVBorder.Border; this.SetVBorders(tr, tc, vrows, style, fromVBorder.Pos); } else { this.vBorders[tr, tc].Style = RangeBorderStyle.Empty; } } } } } } return(new RangePosition(toRange.Row, toRange.Col, rows, cols)); }
internal RGXmlHBorder(int row, int col, int cols, RangeBorderStyle borderStyle, HBorderOwnerPosition pos) : base(row, col, borderStyle, XmlFileFormatHelper.EncodeHBorderOwnerPos(pos)) { this.cols = cols; }
internal RGXmlVBorder(int row, int col, int rows, RangeBorderStyle borderStyle, VBorderOwnerPosition pos) : base(row, col, borderStyle, XmlFileFormatHelper.EncodeVBorderOwnerPos(pos)) { this.rows = rows; }
/// <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) }) { }
/// <summary> /// Create instance for BorderAddedEventArgs with specified range, /// position of border and style of border. /// </summary> /// <param name="range"></param> /// <param name="pos"></param> /// <param name="style"></param> public BorderAddedEventArgs(RangePosition range, BorderPositions pos, RangeBorderStyle style) : base(range) { this.Pos = pos; this.Style = style; }
private static void WriteCellBorder(StringBuilder sb, string name, RangeBorderStyle borderStyle) { WriteHtmlStyle(sb, name, string.Format("{0} {1}", ToHTMLBorderLineStyle(borderStyle.Style), TextFormatHelper.EncodeColor(borderStyle.Color))); }
/// <summary> /// [Debug Method] /// Validate whether border span is correct after border changes /// </summary> /// <returns>True if test passed</returns> public bool _Debug_Validate_BorderSpan() { bool result = true; int span = 0; RangeBorderStyle lastBorder = RangeBorderStyle.Empty; // check h-borders for (int r = this.hBorders.MaxRow; r >= 0; r--) { for (int c = this.hBorders.MaxCol; c >= 0; c--) { if (hBorders[r, c] == null || hBorders[r, c].Style == null) { span = 0; lastBorder = RangeBorderStyle.Empty; } else { if (lastBorder != null && hBorders[r, c].Style.Equals(lastBorder)) { span++; } else { lastBorder = hBorders[r, c].Style; span = 1; } if (hBorders[r, c].Span != span) { _Debug_MarkCellError(r, c, "hborder colspan", hBorders[r, c].Span, span); result = false; } //if (span == 1 && hBorders[r, c].Pos == HBorderOwnerPosition.None) //{ // _Debug_MarkCellError(r, c, "hborder has no owner pos", "none", "any pos"); // result = false; //} } } span = 0; } span = 0; lastBorder = RangeBorderStyle.Empty; // check v-borders for (int c = this.vBorders.MaxCol; c >= 0; c--) { for (int r = this.vBorders.MaxRow; r >= 0; r--) { if (vBorders[r, c] == null || vBorders[r, c].Style == null) { span = 0; lastBorder = RangeBorderStyle.Empty; } else { if (lastBorder != null && vBorders[r, c].Style.Equals(lastBorder)) { span++; } else { lastBorder = vBorders[r, c].Style; span = 1; } if (vBorders[r, c].Span != span) { _Debug_MarkCellError(r, c, "vborder rowspan", vBorders[r, c].Span, span); result = false; } //if (span == 1 && vBorders[r, c].Pos == VBorderOwnerPosition.None) //{ // _Debug_MarkCellError(r, c, "vborder has no owner pos", "none", "any pos"); // result = false; //} } } span = 0; } return(result); }