internal bool Equals(WorksheetRangeStyle styleA, WorksheetRangeStyle styleB) { if (styleA == null && styleB != null || styleA != null && styleB == null || styleA.Flag != styleB.Flag) { return(false); } if (styleA.HasStyle(PlainStyleFlag.BackColor) && styleA.BackColor != styleB.BackColor) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FillPatternColor) && styleA.FillPatternColor != styleB.FillPatternColor) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FillPatternStyle) && styleA.FillPatternStyle != styleB.FillPatternStyle) { return(false); } if (styleA.HasStyle(PlainStyleFlag.TextColor) && styleA.TextColor != styleB.TextColor) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FontName) && styleA.FontName != styleB.FontName) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FontSize) && styleA.FontSize != styleB.FontSize) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FontStyleBold) && styleA.Bold != styleB.Bold) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FontStyleItalic) && styleA.Italic != styleB.Italic) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FontStyleStrikethrough) && styleA.Strikethrough != styleB.Strikethrough) { return(false); } if (styleA.HasStyle(PlainStyleFlag.FontStyleUnderline) && styleA.Underline != styleB.Underline) { return(false); } if (styleA.HasStyle(PlainStyleFlag.HorizontalAlign) && styleA.HAlign != styleB.HAlign) { return(false); } if (styleA.HasStyle(PlainStyleFlag.VerticalAlign) && styleA.VAlign != styleB.VAlign) { return(false); } if (styleA.HasStyle(PlainStyleFlag.TextWrap) && styleA.TextWrapMode != styleB.TextWrapMode) { return(false); } if (styleA.HasStyle(PlainStyleFlag.Indent) && styleA.Indent != styleB.Indent) { return(false); } if (styleA.HasStyle(PlainStyleFlag.Padding) && styleA.Padding != styleB.Padding) { return(false); } if (styleA.HasStyle(PlainStyleFlag.RotationAngle) && styleA.RotationAngle != styleB.RotationAngle) { return(false); } return(true); }
public void Initialize(WorksheetRangeStyle style) { Colors.CopyFrom(style); textColorSelected.BackColor = System.Drawing.Color.FromArgb(style.TextColor.R, style.TextColor.G, style.TextColor.B); bgColorSelected.BackColor = System.Drawing.Color.FromArgb(style.BackColor.R, style.BackColor.G, style.BackColor.B); }
internal static WorksheetRangeStyle ConvertFromXmlStyle(Worksheet grid, RGXmlCellStyle xmlStyle, CultureInfo culture) { WorksheetRangeStyle style = new WorksheetRangeStyle(); if (xmlStyle == null) { return(style); } // back color if (!string.IsNullOrEmpty(xmlStyle.backColor)) { SolidColor color; if (TextFormatHelper.DecodeColor(xmlStyle.backColor, out color)) { style.Flag |= PlainStyleFlag.BackColor; style.BackColor = color; } } // fill pattern if (xmlStyle.fillPattern != null) { SolidColor color; if (TextFormatHelper.DecodeColor(xmlStyle.fillPattern.color, out color)) { style.Flag |= PlainStyleFlag.FillPattern; style.FillPatternColor = color; style.FillPatternStyle = (HatchStyles)xmlStyle.fillPattern.patternStyleId; } } // text color if (!string.IsNullOrEmpty(xmlStyle.textColor)) { SolidColor color; if (TextFormatHelper.DecodeColor(xmlStyle.textColor, out color)) { style.Flag |= PlainStyleFlag.TextColor; style.TextColor = color; } } // horizontal align if (!string.IsNullOrEmpty(xmlStyle.hAlign)) { style.Flag |= PlainStyleFlag.HorizontalAlign; style.HAlign = XmlFileFormatHelper.DecodeHorizontalAlign(xmlStyle.hAlign); } // vertical align if (!string.IsNullOrEmpty(xmlStyle.vAlign)) { style.Flag |= PlainStyleFlag.VerticalAlign; style.VAlign = XmlFileFormatHelper.DecodeVerticalAlign(xmlStyle.vAlign); } // font name if (!string.IsNullOrEmpty(xmlStyle.font)) { style.Flag |= PlainStyleFlag.FontName; style.FontName = xmlStyle.font; } // font size if (xmlStyle.fontSize != null) { style.Flag |= PlainStyleFlag.FontSize; style.FontSize = TextFormatHelper.GetFloatValue(xmlStyle.fontSize, grid.RootStyle.FontSize, culture); } // bold if (xmlStyle.bold != null) { style.Flag |= PlainStyleFlag.FontStyleBold; style.Bold = xmlStyle.bold == "true"; } // italic if (xmlStyle.italic != null) { style.Flag |= PlainStyleFlag.FontStyleItalic; style.Italic = xmlStyle.italic == "true"; } // strikethrough if (xmlStyle.strikethrough != null) { style.Flag |= PlainStyleFlag.FontStyleStrikethrough; style.Strikethrough = xmlStyle.strikethrough == "true"; } // underline if (xmlStyle.underline != null) { style.Flag |= PlainStyleFlag.FontStyleUnderline; style.Underline = xmlStyle.underline == "true"; } // text-wrap if (!string.IsNullOrEmpty(xmlStyle.textWrap)) { style.Flag |= PlainStyleFlag.TextWrap; style.TextWrapMode = XmlFileFormatHelper.DecodeTextWrapMode(xmlStyle.textWrap); } // padding if (!string.IsNullOrEmpty(xmlStyle.indent)) { style.Flag |= PlainStyleFlag.Indent; int indent = TextFormatHelper.GetPixelValue(xmlStyle.indent, 0); if (indent > 0 && indent < 65535) { style.Indent = (ushort)indent; } } // padding if (!string.IsNullOrEmpty(xmlStyle.padding)) { style.Flag |= PlainStyleFlag.Padding; style.Padding = TextFormatHelper.DecodePadding(xmlStyle.padding); } // rotate angle int angle; if (!string.IsNullOrEmpty(xmlStyle.rotateAngle) && int.TryParse(xmlStyle.rotateAngle, out angle)) { style.Flag |= PlainStyleFlag.RotationAngle; style.RotationAngle = angle; } return(style); }
public void LoadPage() { var sheet = grid.CurrentWorksheet; WorksheetRangeStyle style = sheet.GetRangeStyles(sheet.SelectionRange); if (style.TextWrapMode == TextWrapMode.WordBreak || style.TextWrapMode == TextWrapMode.BreakAll) { backupTextWrapState = CheckState.Checked; } else { backupTextWrapState = CheckState.Unchecked; } backupHorAlign = style.HAlign; backupVerAlign = style.VAlign; switch (style.HAlign) { case ReoGridHorAlign.General: cmbHorAlign.SelectedIndex = 0; break; case ReoGridHorAlign.Left: cmbHorAlign.SelectedIndex = 1; break; case ReoGridHorAlign.Center: cmbHorAlign.SelectedIndex = 2; break; case ReoGridHorAlign.Right: cmbHorAlign.SelectedIndex = 3; break; case ReoGridHorAlign.DistributedIndent: cmbHorAlign.SelectedIndex = 4; break; } switch (style.VAlign) { case ReoGridVerAlign.General: cmbVerAlign.SelectedIndex = 0; break; case ReoGridVerAlign.Top: cmbVerAlign.SelectedIndex = 1; break; case ReoGridVerAlign.Middle: cmbVerAlign.SelectedIndex = 2; break; case ReoGridVerAlign.Bottom: cmbVerAlign.SelectedIndex = 3; break; } chkWrapText.CheckState = backupTextWrapState; backupIndent = style.Indent; numIndent.Value = backupIndent; // cell text rotate var angle = style.RotationAngle; if (angle < -90) { angle = -90; } if (angle > 90) { angle = 90; } backupRotateAngle = angle; textRotateControl.Angle = (int)angle; numRotationAngle.Value = (int)angle; }
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); }); }
/// <summary> /// Undo this action /// </summary> public override void Undo() { if (this.isFullGridSelected) { Worksheet.RootStyle = WorksheetRangeStyle.Clone(backupRootStyle); // remote styles if it is already setted in full-row for (int r = 0; r < backupRowStyles.Length; r++) { if (backupRowStyles[r] != null) { RowHeader rowHead = Worksheet.RetrieveRowHeader(r); if (rowHead != null) { rowHead.InnerStyle = WorksheetRangeStyle.Clone(backupRowStyles[r]); //rowHead.InnerStyle.Flag = PlainStyleFlag.None; //rowHead.Style.BackColor = System.Drawing.Color.Empty; } } } // remote styles if it is already setted in full-col for (int c = 0; c < backupColStyles.Length; c++) { if (backupColStyles[c] != null) { ColumnHeader colHead = Worksheet.RetrieveColumnHeader(c); if (colHead != null) { colHead.InnerStyle = WorksheetRangeStyle.Clone(backupColStyles[c]); //colHead.InnerStyle.Flag = PlainStyleFlag.None; //colHead.Style.BackColor = System.Drawing.Color.Empty; } } } } else if (isFullRowSelected) { for (int r = 0; r < backupRowStyles.Length; r++) { RowHeader rowHead = Worksheet.RetrieveRowHeader(r + affectedRange.Row); if (rowHead != null) { rowHead.InnerStyle = backupRowStyles[r]; } } } else if (isFullColSelected) { for (int c = 0; c < backupColStyles.Length; c++) { ColumnHeader colHead = Worksheet.RetrieveColumnHeader(c + affectedRange.Col); if (colHead != null) { colHead.InnerStyle = backupColStyles[c]; } } } Worksheet.SetPartialGrid(affectedRange, backupData, PartialGridCopyFlag.CellStyle); }
/// <summary> /// Do this action /// </summary> public override void Do() { backupData = Worksheet.GetPartialGrid(Range, PartialGridCopyFlag.CellStyle); 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); }
internal static void CopyStyle(WorksheetRangeStyle sourceStyle, WorksheetRangeStyle targetStyle, PlainStyleFlag flag) { if ((flag & PlainStyleFlag.BackColor) == PlainStyleFlag.BackColor) { targetStyle.BackColor = sourceStyle.BackColor; } if ((flag & PlainStyleFlag.FillPatternColor) == PlainStyleFlag.FillPatternColor) { targetStyle.FillPatternColor = sourceStyle.FillPatternColor; } if ((flag & PlainStyleFlag.FillPatternStyle) == PlainStyleFlag.FillPatternStyle) { targetStyle.FillPatternStyle = sourceStyle.FillPatternStyle; } if ((flag & PlainStyleFlag.TextColor) == PlainStyleFlag.TextColor) { targetStyle.TextColor = sourceStyle.TextColor; } if ((flag & PlainStyleFlag.FontName) == PlainStyleFlag.FontName) { targetStyle.FontName = sourceStyle.FontName; System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(targetStyle.FontName)); } if ((flag & PlainStyleFlag.FontSize) == PlainStyleFlag.FontSize) { targetStyle.FontSize = sourceStyle.FontSize; } if ((flag & PlainStyleFlag.FontStyleBold) == PlainStyleFlag.FontStyleBold) { targetStyle.Bold = sourceStyle.Bold; } if ((flag & PlainStyleFlag.FontStyleItalic) == PlainStyleFlag.FontStyleItalic) { targetStyle.Italic = sourceStyle.Italic; } if ((flag & PlainStyleFlag.FontStyleStrikethrough) == PlainStyleFlag.FontStyleStrikethrough) { targetStyle.Strikethrough = sourceStyle.Strikethrough; } if ((flag & PlainStyleFlag.FontStyleUnderline) == PlainStyleFlag.FontStyleUnderline) { targetStyle.Underline = sourceStyle.Underline; } if ((flag & PlainStyleFlag.HorizontalAlign) == PlainStyleFlag.HorizontalAlign) { targetStyle.HAlign = sourceStyle.HAlign; } if ((flag & PlainStyleFlag.VerticalAlign) == PlainStyleFlag.VerticalAlign) { targetStyle.VAlign = sourceStyle.VAlign; } if ((flag & PlainStyleFlag.TextWrap) == PlainStyleFlag.TextWrap) { targetStyle.TextWrapMode = sourceStyle.TextWrapMode; } if ((flag & PlainStyleFlag.Indent) == PlainStyleFlag.Indent) { targetStyle.Indent = sourceStyle.Indent; } if ((flag & PlainStyleFlag.Padding) == PlainStyleFlag.Padding) { targetStyle.Padding = sourceStyle.Padding; } if ((flag & PlainStyleFlag.RotationAngle) == PlainStyleFlag.RotationAngle) { targetStyle.RotationAngle = sourceStyle.RotationAngle; } targetStyle.Flag |= flag; }
internal static WorksheetRangeStyle CreateMergedStyle(WorksheetRangeStyle style1, WorksheetRangeStyle style2) { var style = new WorksheetRangeStyle() { Flag = style1.Flag | style2.Flag, }; var flag1 = style1.Flag; var flag2 = style2.Flag; if ((flag1 & PlainStyleFlag.BackColor) == PlainStyleFlag.BackColor) { style.BackColor = style1.BackColor; } else if ((flag2 & PlainStyleFlag.BackColor) == PlainStyleFlag.BackColor) { style.BackColor = style2.BackColor; } if ((flag1 & PlainStyleFlag.FillPatternColor) == PlainStyleFlag.FillPatternColor) { style.FillPatternColor = style1.FillPatternColor; } else if ((flag2 & PlainStyleFlag.FillPatternColor) == PlainStyleFlag.FillPatternColor) { style.FillPatternColor = style2.FillPatternColor; } if ((flag1 & PlainStyleFlag.FillPatternStyle) == PlainStyleFlag.FillPatternStyle) { style.FillPatternStyle = style1.FillPatternStyle; } else if ((flag2 & PlainStyleFlag.FillPatternStyle) == PlainStyleFlag.FillPatternStyle) { style.FillPatternStyle = style2.FillPatternStyle; } if ((flag1 & PlainStyleFlag.TextColor) == PlainStyleFlag.TextColor) { style.TextColor = style1.TextColor; } else if ((flag2 & PlainStyleFlag.TextColor) == PlainStyleFlag.TextColor) { style.TextColor = style2.TextColor; } if ((flag1 & PlainStyleFlag.FontName) == PlainStyleFlag.FontName) { style.FontName = style1.FontName; } else if ((flag2 & PlainStyleFlag.FontName) == PlainStyleFlag.FontName) { style.FontName = style2.FontName; } if ((flag1 & PlainStyleFlag.FontSize) == PlainStyleFlag.FontSize) { style.FontSize = style1.FontSize; } else if ((flag2 & PlainStyleFlag.FontSize) == PlainStyleFlag.FontSize) { style.FontSize = style2.FontSize; } if ((flag1 & PlainStyleFlag.FontStyleBold) == PlainStyleFlag.FontStyleBold) { style.Bold = style1.Bold; } else if ((flag2 & PlainStyleFlag.FontStyleBold) == PlainStyleFlag.FontStyleBold) { style.Bold = style2.Bold; } if ((flag1 & PlainStyleFlag.FontStyleItalic) == PlainStyleFlag.FontStyleItalic) { style.Italic = style1.Italic; } else if ((flag2 & PlainStyleFlag.FontStyleItalic) == PlainStyleFlag.FontStyleItalic) { style.Italic = style2.Italic; } if ((flag1 & PlainStyleFlag.FontStyleStrikethrough) == PlainStyleFlag.FontStyleStrikethrough) { style.Strikethrough = style1.Strikethrough; } else if ((flag2 & PlainStyleFlag.FontStyleStrikethrough) == PlainStyleFlag.FontStyleStrikethrough) { style.Strikethrough = style2.Strikethrough; } if ((flag1 & PlainStyleFlag.FontStyleUnderline) == PlainStyleFlag.FontStyleUnderline) { style.Underline = style1.Underline; } else if ((flag2 & PlainStyleFlag.FontStyleUnderline) == PlainStyleFlag.FontStyleUnderline) { style.Underline = style2.Underline; } if ((flag1 & PlainStyleFlag.HorizontalAlign) == PlainStyleFlag.HorizontalAlign) { style.HAlign = style1.HAlign; } else if ((flag2 & PlainStyleFlag.HorizontalAlign) == PlainStyleFlag.HorizontalAlign) { style.HAlign = style2.HAlign; } if ((flag1 & PlainStyleFlag.VerticalAlign) == PlainStyleFlag.VerticalAlign) { style.VAlign = style1.VAlign; } else if ((flag2 & PlainStyleFlag.VerticalAlign) == PlainStyleFlag.VerticalAlign) { style.VAlign = style2.VAlign; } if ((flag1 & PlainStyleFlag.TextWrap) == PlainStyleFlag.TextWrap) { style.TextWrapMode = style1.TextWrapMode; } else if ((flag2 & PlainStyleFlag.TextWrap) == PlainStyleFlag.TextWrap) { style.TextWrapMode = style2.TextWrapMode; } if ((flag1 & PlainStyleFlag.Indent) == PlainStyleFlag.Indent) { style.Indent = style1.Indent; } else if ((flag2 & PlainStyleFlag.Indent) == PlainStyleFlag.Indent) { style.Indent = style2.Indent; } if ((flag1 & PlainStyleFlag.Padding) == PlainStyleFlag.Padding) { style.Padding = style1.Padding; } else if ((flag2 & PlainStyleFlag.Padding) == PlainStyleFlag.Padding) { style.Padding = style2.Padding; } if ((flag1 & PlainStyleFlag.RotationAngle) == PlainStyleFlag.RotationAngle) { style.RotationAngle = style1.RotationAngle; } else if ((flag2 & PlainStyleFlag.RotationAngle) == PlainStyleFlag.RotationAngle) { style.RotationAngle = style2.RotationAngle; } return(style); }
public BuiltInTypesDemo() { InitializeComponent(); this.worksheet = grid.CurrentWorksheet; // set default sheet style worksheet.SetRangeStyles(RangePosition.EntireRange, new WorksheetRangeStyle { Flag = PlainStyleFlag.FontName | PlainStyleFlag.VerticalAlign, FontName = "Arial", VAlign = ReoGridVerAlign.Middle, }); worksheet.SetSettings(WorksheetSettings.View_ShowGridLine | WorksheetSettings.Edit_DragSelectionToMoveCells, false); worksheet.SelectionMode = WorksheetSelectionMode.Cell; worksheet.SelectionStyle = WorksheetSelectionStyle.FocusRect; var middleStyle = new WorksheetRangeStyle { Flag = PlainStyleFlag.Padding | PlainStyleFlag.HorizontalAlign, Padding = new PaddingValue(2), HAlign = ReoGridHorAlign.Center, }; var grayTextStyle = new WorksheetRangeStyle { Flag = PlainStyleFlag.TextColor, TextColor = Color.DimGray }; worksheet.MergeRange(1, 1, 1, 6); worksheet.SetRangeStyles(1, 1, 1, 6, new WorksheetRangeStyle { Flag = PlainStyleFlag.TextColor | PlainStyleFlag.FontSize, TextColor = Color.DarkGreen, FontSize = 18, }); worksheet[1, 1] = "Built-in Cell Bodies"; worksheet.SetColumnsWidth(1, 1, 100); worksheet.SetColumnsWidth(2, 1, 30); worksheet.SetColumnsWidth(3, 1, 100); worksheet.SetColumnsWidth(6, 2, 65); // button worksheet.MergeRange(3, 2, 1, 2); var btn = new ButtonCell("Hello"); worksheet[3, 1] = new object[] { "Button: ", btn }; btn.Click += (s, e) => ShowText("Button clicked."); // link worksheet.MergeRange(5, 2, 1, 3); var link = new HyperlinkCell("http://www.google.com") { AutoNavigate = false }; worksheet[5, 1] = new object[] { "Hyperlink", link }; link.Click += (s, e) => System.Diagnostics.Process.Start(worksheet.GetCellText(5, 2)); // checkbox var checkbox = new CheckBoxCell(); worksheet.SetRangeStyles(7, 2, 1, 1, middleStyle); worksheet.SetRangeStyles(8, 2, 1, 1, grayTextStyle); worksheet[7, 1] = new object[] { "Check box", checkbox, "Auto destroy after 5 minutes." }; worksheet[8, 2] = "(Keyboard is also supported to change the status of control)"; checkbox.CheckChanged += (s, e) => ShowText("Check box switch to " + checkbox.IsChecked.ToString()); // radio & radio group worksheet[10, 1] = "Radio Button"; worksheet.SetRangeStyles(10, 2, 3, 1, middleStyle); var radioGroup = new RadioButtonGroup(); worksheet[10, 2] = new object[, ] { { new RadioButtonCell() { RadioGroup = radioGroup }, "Apple" }, { new RadioButtonCell() { RadioGroup = radioGroup }, "Orange" }, { new RadioButtonCell() { RadioGroup = radioGroup }, "Banana" } }; radioGroup.RadioButtons.ForEach(rb => rb.CheckChanged += (s, e) => ShowText("Radio button selected: " + worksheet[rb.Cell.Row, rb.Cell.Column + 1])); worksheet[10, 2] = true; worksheet[13, 2] = "(By adding radio buttons into same RadioGroup to make them toggle each other automatically)"; worksheet.SetRangeStyles(13, 2, 1, 1, grayTextStyle); // dropdown worksheet.MergeRange(15, 2, 1, 3); var dropdown = new DropdownListCell("Apple", "Orange", "Banana", "Pear", "Pumpkin", "Cherry", "Coconut"); worksheet[15, 1] = new object[] { "Dropdown", dropdown }; worksheet.SetRangeBorders(15, 2, 1, 3, BorderPositions.Outside, RangeBorderStyle.GraySolid); dropdown.SelectedItemChanged += (s, e) => ShowText("Dropdown list selected: " + dropdown.SelectedItem); // image worksheet.MergeRange(2, 6, 5, 2); worksheet[2, 6] = new ImageCell(Resources.computer_laptop); // information cell worksheet.SetRangeBorders(19, 0, 1, 10, BorderPositions.Top, RangeBorderStyle.GraySolid); }
internal static void CopyStyle(WorksheetRangeStyle sourceStyle, WorksheetRangeStyle targetStyle) { CopyStyle(sourceStyle, targetStyle, sourceStyle.Flag); }
private void SetCellStyle(object row, object column, WorksheetRangeStyle style) { worksheet.SetRangeStyles(GetRangePosition(row, column), style); }
public void SetStyleByActionTest() { SetUp(); Grid.DoAction(new SetRangeStyleAction(new RangePosition(1, 1, 5, 5), new WorksheetRangeStyle() { Flag = PlainStyleFlag.BackColor, BackColor = Color.DarkBlue, })); Grid.DoAction(new SetRangeStyleAction(new RangePosition(2, 1, 1, 1), new WorksheetRangeStyle() { Flag = PlainStyleFlag.TextColor, TextColor = Color.Cyan, })); Grid.DoAction(new SetRangeStyleAction(new RangePosition(2, 2, 1, 1), new WorksheetRangeStyle() { Flag = PlainStyleFlag.HorizontalAlign, HAlign = ReoGridHorAlign.Right, })); Grid.DoAction(new SetRangeStyleAction(new RangePosition(1, 2, 1, 1), new WorksheetRangeStyle() { Flag = PlainStyleFlag.FontStyleBold, Bold = true, })); Grid.DoAction(new SetRangeStyleAction(new RangePosition(3, 1, 1, 1), new WorksheetRangeStyle() { Flag = PlainStyleFlag.TextWrap, TextWrapMode = TextWrapMode.WordBreak, })); AssertHasStyle(worksheet.GetCellStyles(1, 1).Flag, PlainStyleFlag.BackColor); AssertHasStyle(worksheet.GetCellStyles(2, 1).Flag, PlainStyleFlag.TextColor | PlainStyleFlag.BackColor); AssertHasStyle(worksheet.GetCellStyles(2, 2).Flag, PlainStyleFlag.HorizontalAlign | PlainStyleFlag.BackColor); AssertHasStyle(worksheet.GetCellStyles(1, 2).Flag, PlainStyleFlag.FontStyleBold | PlainStyleFlag.BackColor); AssertHasStyle(worksheet.GetCellStyles(3, 1).Flag, PlainStyleFlag.TextWrap | PlainStyleFlag.BackColor); AssertTrue(worksheet.GetCellStyles(1, 1).BackColor == Color.DarkBlue); AssertTrue(worksheet.GetCellStyles(2, 1).TextColor == Color.Cyan); AssertTrue(worksheet.GetCellStyles(2, 2).HAlign == ReoGridHorAlign.Right); AssertTrue(worksheet.GetCellStyles(1, 2).Bold == true); AssertTrue(worksheet.GetCellStyles(3, 1).TextWrapMode == TextWrapMode.WordBreak); // undo all while (Grid.CanUndo()) { Grid.Undo(); } // get root style WorksheetRangeStyle rootStyle = worksheet.GetRangeStyles(new RangePosition(0, 0, 1, 1)); // compare to root style AssertTrue(worksheet.GetCellStyles(1, 1).Flag == rootStyle.Flag); AssertTrue(worksheet.GetCellStyles(2, 1).Flag == rootStyle.Flag); AssertTrue(worksheet.GetCellStyles(2, 2).Flag == rootStyle.Flag); AssertTrue(worksheet.GetCellStyles(1, 2).Flag == rootStyle.Flag); AssertTrue(worksheet.GetCellStyles(3, 1).Flag == rootStyle.Flag); AssertEquals(worksheet.GetCellStyles(1, 1).BackColor, rootStyle.BackColor); AssertEquals(worksheet.GetCellStyles(2, 1).TextColor, rootStyle.TextColor); AssertEquals(worksheet.GetCellStyles(2, 2).HAlign, rootStyle.HAlign); AssertEquals(worksheet.GetCellStyles(1, 2).Bold, rootStyle.Bold); AssertEquals(worksheet.GetCellStyles(3, 1).TextWrapMode, rootStyle.TextWrapMode); }
private void AddDemoSheet3() { /****************** Sheet3 : Built-in Cell Types ********************/ var worksheet = grid.NewWorksheet("Cell Types"); // set default sheet style worksheet.SetRangeStyles(RangePosition.EntireRange, new WorksheetRangeStyle { Flag = PlainStyleFlag.FontName | PlainStyleFlag.VerticalAlign, FontName = "Arial", VAlign = ReoGridVerAlign.Middle, }); worksheet.SetSettings(WorksheetSettings.View_ShowGridLine | WorksheetSettings.Edit_DragSelectionToMoveCells, false); worksheet.SelectionMode = WorksheetSelectionMode.Cell; worksheet.SelectionStyle = WorksheetSelectionStyle.FocusRect; var middleStyle = new WorksheetRangeStyle { Flag = PlainStyleFlag.Padding | PlainStyleFlag.HorizontalAlign, Padding = new PaddingValue(2), HAlign = ReoGridHorAlign.Center, }; var grayTextStyle = new WorksheetRangeStyle { Flag = PlainStyleFlag.TextColor, TextColor = Colors.DimGray }; worksheet.MergeRange(1, 1, 1, 6); worksheet.SetRangeStyles(1, 1, 1, 6, new WorksheetRangeStyle { Flag = PlainStyleFlag.TextColor | PlainStyleFlag.FontSize, TextColor = Colors.DarkGreen, FontSize = 18, }); worksheet[1, 1] = "Built-in Cell Bodies"; worksheet.SetColumnsWidth(1, 1, 100); worksheet.SetColumnsWidth(2, 1, 30); worksheet.SetColumnsWidth(3, 1, 100); worksheet.SetColumnsWidth(6, 2, 65); // button worksheet.MergeRange(3, 2, 1, 2); var btn = new ButtonCell("Hello"); worksheet[3, 1] = new object[] { "Button: ", btn }; btn.Click += (s, e) => ShowText(worksheet, "Button clicked."); // link worksheet.MergeRange(5, 2, 1, 3); var link = new HyperlinkCell("http://www.google.com"); worksheet[5, 1] = new object[] { "Hyperlink", link }; // checkbox var checkbox = new CheckBoxCell(); worksheet.SetRangeStyles(7, 2, 1, 1, middleStyle); worksheet.SetRangeStyles(8, 2, 1, 1, grayTextStyle); worksheet[7, 1] = new object[] { "Check box", checkbox, "Auto destroy after 5 minutes." }; worksheet[8, 2] = "(Keyboard is also supported to change the status of control)"; checkbox.CheckChanged += (s, e) => ShowText(worksheet, "Check box switch to " + checkbox.IsChecked.ToString()); // radio & radio group worksheet[10, 1] = "Radio Button"; worksheet.SetRangeStyles(10, 2, 3, 1, middleStyle); var radioGroup = new RadioButtonGroup(); worksheet[10, 2] = new object[, ] { { new RadioButtonCell() { RadioGroup = radioGroup }, "Apple" }, { new RadioButtonCell() { RadioGroup = radioGroup }, "Orange" }, { new RadioButtonCell() { RadioGroup = radioGroup }, "Banana" } }; radioGroup.RadioButtons.ForEach(rb => rb.CheckChanged += (s, e) => ShowText(worksheet, "Radio button selected: " + worksheet[rb.Cell.Row, rb.Cell.Column + 1])); worksheet[10, 2] = true; worksheet[13, 2] = "(By adding radio buttons into same RadioGroup to make them toggle each other automatically)"; worksheet.SetRangeStyles(13, 2, 1, 1, grayTextStyle); // dropdown - Not available yet - Planned from next version //worksheet.MergeRange(15, 2, 1, 3); //var dropdown = new DropdownListCell("Apple", "Orange", "Banana", "Pear", "Pumpkin", "Cherry", "Coconut"); //worksheet[15, 1] = new object[] { "Dropdown", dropdown }; //worksheet.SetRangeBorders(15, 2, 1, 3, BorderPositions.Outside, RangeBorderStyle.GraySolid); // custom cell type - slide cell body worksheet.MergeRange(15, 2, 1, 2); worksheet[15, 1] = new object[] { "Brightness", new SlideCellBody() }; worksheet[15, 2] = 1; worksheet.CellDataChanged += (s, e) => { if (e.Cell.Position == new CellPosition(15, 2)) { byte val = (byte)(worksheet.GetCellData <double>(e.Cell.Position) * 255); worksheet.SetRangeStyles(RangePosition.EntireRange, new WorksheetRangeStyle { Flag = PlainStyleFlag.BackColor, BackColor = new Graphics.SolidColor(val, val, val), }); } }; // image worksheet.MergeRange(2, 6, 5, 2); var image = new System.Windows.Media.Imaging.BitmapImage(); image.BeginInit(); using (MemoryStream memory = new MemoryStream(Properties.Resources.computer_laptop_png)) { image.StreamSource = memory; image.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad; image.EndInit(); } worksheet[2, 6] = new ImageCell(image); // information cell worksheet.SetRangeBorders(19, 0, 1, 10, BorderPositions.Top, RangeBorderStyle.GraySolid); }
/// <summary> /// Export grid as html5 into specified stream /// </summary> /// <param name="s">Stream contains the exported HTML5 content</param> /// <param name="sheet">Instance of worksheet</param> /// <param name="pageTitle">Custom page title of HTML page</param> /// <param name="htmlHeader">True to export default HTML header tag; false to export table content only</param> public static void Export(Stream s, Worksheet sheet, string pageTitle, bool htmlHeader = true) { using (StreamWriter sw = new StreamWriter(s)) { StringBuilder sb = new StringBuilder(); Cell cell; if (htmlHeader) { sw.WriteLine("<!DOCTYPE html>"); sw.WriteLine("<html>"); sw.WriteLine("<head>"); sw.WriteLine(" <title>{0}</title>", pageTitle); sw.WriteLine(" <meta content=\"text/html; charset=UTF-8\">"); sw.WriteLine("</head>"); sw.WriteLine("<body>"); } sw.WriteLine(" <table style='border-collapse:collapse;border:none;'>"); int maxRow = sheet.MaxContentRow; int maxCol = sheet.MaxContentCol; for (int r = 0; r <= maxRow; r++) { var row = sheet.RetrieveRowHeader(r); sw.WriteLine(string.Format(" <tr style='height:{0}px;'>", row.InnerHeight)); for (int c = 0; c <= maxCol;) { var col = sheet.RetrieveColumnHeader(c); cell = sheet.GetCell(r, c); if (cell != null && (cell.Colspan <= 0 || cell.Rowspan <= 0)) { c++; continue; } sb.Length = 0; sb.Append(" <td"); if (cell != null && cell.Rowspan > 1) { sb.Append(" rowspan='" + cell.Rowspan + "'"); } if (cell != null && cell.Colspan > 1) { sb.Append(" colspan='" + cell.Colspan + "'"); } sb.AppendFormat(" style='width:{0}px;", cell == null ? col.Width : cell.Width); bool halignOutputted = false; if (cell != null) { // render horizontal align if (cell.RenderHorAlign == ReoGridRenderHorAlign.Right) { WriteHtmlStyle(sb, "text-align", "right"); halignOutputted = true; } else if (cell.RenderHorAlign == ReoGridRenderHorAlign.Center) { WriteHtmlStyle(sb, "text-align", "center"); halignOutputted = true; } } WorksheetRangeStyle style = sheet.GetCellStyles(r, c); if (style != null) { // back color if (style.HasStyle(PlainStyleFlag.BackColor) && style.BackColor != SolidColor.White) { WriteHtmlStyle(sb, "background-color", TextFormatHelper.EncodeColor(style.BackColor)); } // text color if (style.HasStyle(PlainStyleFlag.TextColor) && style.TextColor != SolidColor.Black) { WriteHtmlStyle(sb, "color", TextFormatHelper.EncodeColor(style.TextColor)); } // font size if (style.HasStyle(PlainStyleFlag.FontSize)) { WriteHtmlStyle(sb, "font-size", style.FontSize.ToString() + "pt"); } // horizontal align if (!halignOutputted && style.HasStyle(PlainStyleFlag.HorizontalAlign)) { WriteHtmlStyle(sb, "text-align", XmlFileFormatHelper.EncodeHorizontalAlign(style.HAlign)); } // vertical align if (style.HasStyle(PlainStyleFlag.VerticalAlign)) { WriteHtmlStyle(sb, "vertical-align", XmlFileFormatHelper.EncodeVerticalAlign(style.VAlign)); } } RangeBorderInfoSet rbi = sheet.GetRangeBorders(cell == null ? new RangePosition(r, c, 1, 1) : new RangePosition(cell.InternalRow, cell.InternalCol, cell.Rowspan, cell.Colspan)); if (!rbi.Top.IsEmpty) { WriteCellBorder(sb, "border-top", rbi.Top); } if (!rbi.Left.IsEmpty) { WriteCellBorder(sb, "border-left", rbi.Left); } if (!rbi.Right.IsEmpty) { WriteCellBorder(sb, "border-right", rbi.Right); } if (!rbi.Bottom.IsEmpty) { WriteCellBorder(sb, "border-bottom", rbi.Bottom); } sb.Append("'>"); sw.WriteLine(sb.ToString()); //cell = Grid.GetCell(r, c); string text = null; if (cell != null) { text = string.IsNullOrEmpty(cell.DisplayText) ? " " : #if !CLIENT_PROFILE HtmlEncode(cell.DisplayText) #else cell.DisplayText #endif // CLIENT_PROFILE ; } else { text = " "; } sw.WriteLine(text); sw.WriteLine(" </td>"); c += cell == null ? 1 : cell.Colspan; } sw.WriteLine(" </tr>"); } sw.WriteLine(" </table>"); if (htmlHeader) { sw.WriteLine("</body>"); sw.WriteLine("</html>"); } } }
public BuiltInCellTypesDemo() { InitializeComponent(); this.worksheet = grid.CurrentWorksheet; // ワークシート全体のスタイルを設定 worksheet.SetRangeStyles(RangePosition.EntireRange, new WorksheetRangeStyle { // フォント名と縦位置の揃え方を設定 Flag = PlainStyleFlag.FontName | PlainStyleFlag.VerticalAlign, FontName = "Arial", VAlign = ReoGridVerAlign.Middle, }); // グリッドラインを非表示 worksheet.SetSettings(WorksheetSettings.View_ShowGridLine | WorksheetSettings.Edit_DragSelectionToMoveCells, false); // 選択モードを単一セルのみに設定 worksheet.SelectionMode = WorksheetSelectionMode.Cell; // 選択スタイルを Focus に設定 worksheet.SelectionStyle = WorksheetSelectionStyle.FocusRect; var grayTextStyle = new WorksheetRangeStyle { Flag = PlainStyleFlag.TextColor, TextColor = Color.DimGray }; worksheet.MergeRange(1, 1, 1, 6); // B2:G2 worksheet.SetRangeStyles(1, 1, 1, 6, new WorksheetRangeStyle { Flag = PlainStyleFlag.TextColor | PlainStyleFlag.FontSize, TextColor = Color.DarkGreen, FontSize = 18, }); worksheet[1, 1] = "内蔵セル型"; // 列幅を調整 worksheet.SetColumnsWidth(1, 1, 100); worksheet.SetColumnsWidth(2, 1, 30); worksheet.SetColumnsWidth(3, 1, 100); worksheet.SetColumnsWidth(6, 2, 65); // ボタン worksheet.MergeRange(3, 2, 1, 2); // C4:D4 var btn = new ButtonCell("ボタン"); worksheet[3, 1] = new object[] { "ボタン: ", btn }; btn.Click += (s, e) => ShowText("ボタンがクリックされた。"); // リンク worksheet.MergeRange(5, 2, 1, 3); // C6:E6 var link = new HyperlinkCell("https://www.google.com") { AutoNavigate = false }; worksheet[5, 1] = new object[] { "ハイパーリンク", link }; link.Click += (s, e) => RGUtility.OpenFileOrLink(worksheet.GetCellText(5, 2)); // チェックボックス var checkbox = new CheckBoxCell(); worksheet.SetRangeStyles(8, 2, 1, 1, grayTextStyle); // C9:C9 worksheet[7, 1] = new object[] { "チェックボックス", checkbox, "テキストは別のセルを利用します" }; worksheet[8, 2] = "(セル型の編集はキーボードでも変更できます)"; checkbox.CheckChanged += (s, e) => ShowText("チェックステータスが変更された: " + checkbox.IsChecked.ToString()); // ラジオボタン worksheet[10, 1] = "Radio Button"; // B11 var radioGroup = new RadioButtonGroup(); // ラジオボタングループを作成 worksheet[10, 2] = new object[, ] { // C11 { new RadioButtonCell() { RadioGroup = radioGroup }, "リンゴ" }, { new RadioButtonCell() { RadioGroup = radioGroup }, "ミカン" }, { new RadioButtonCell() { RadioGroup = radioGroup }, "バナナ" } }; radioGroup.RadioButtons.ForEach(rb => rb.CheckChanged += (s, e) => ShowText("ラジオボタンのステータスが変更された:" + worksheet[rb.Cell.Row, rb.Cell.Column + 1])); worksheet[10, 2] = true; worksheet[13, 2] = "(RadioGroup に複数のラジオボタンを追加するとお互いに切り替えることができます)"; worksheet.SetRangeStyles(13, 2, 1, 1, grayTextStyle); //C14 // ドロップダウンリスト worksheet.MergeRange(15, 2, 1, 3); // C16:E16 var dropdown = new DropdownListCell("リンゴ", "ミカン", "バナナ", "ナシ", "カボチャ", "チェリー", "ココナッツ"); worksheet[15, 1] = new object[] { "ドロップダウン", dropdown }; worksheet.SetRangeBorders(15, 2, 1, 3, BorderPositions.Outside, RangeBorderStyle.GraySolid); dropdown.SelectedItemChanged += (s, e) => ShowText("ドロップダウンの項目が選択された:" + dropdown.SelectedItem); // イメージ worksheet.MergeRange(2, 6, 5, 2); // G3:H7 worksheet[2, 6] = new ImageCell(Resources.computer_laptop); // イベント情報 worksheet.SetRangeBorders("A20:J20", BorderPositions.Top, RangeBorderStyle.GraySolid); }
/// <summary> /// Compare this partial grid to another grid with specified comparison flag /// </summary> /// <param name="anotherPartialGrid">another partial grid to be compared</param> /// <param name="flag">comparison flag</param> /// <returns>true if two partial grid are same, otherwise return false</returns> public bool Equals(PartialGrid anotherPartialGrid, PartialGridCopyFlag flag) { if (anotherPartialGrid.rows != rows || anotherPartialGrid.cols != cols) { return(false); } for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { var a = cells[r, c]; var b = anotherPartialGrid.cells[r, c]; if ((flag & PartialGridCopyFlag.CellData) == PartialGridCopyFlag.CellData) { if (a == null && b != null || b == null && a != null || a.InnerData == null || b.InnerData != null || b.InnerData == null || a.InnerData != null) { return(false); } if (Convert.ToString(a.DisplayText) != Convert.ToString(b.DisplayText)) { return(false); } if (!string.Equals(a.InnerFormula, b.InnerFormula, StringComparison.CurrentCultureIgnoreCase)) { return(false); } if (a.DataFormat != b.DataFormat) { return(false); } if (a.DataFormatArgs == null && b.DataFormatArgs != null || a.DataFormatArgs != null && b.DataFormatArgs == null) { return(false); } if (!a.DataFormatArgs.Equals(b.DataFormatArgs)) { return(false); } } if ((flag & PartialGridCopyFlag.CellStyle) == PartialGridCopyFlag.CellStyle && WorksheetRangeStyle.Equals(a.InnerStyle, b.InnerStyle)) { return(false); } if ((flag & PartialGridCopyFlag.HBorder) == PartialGridCopyFlag.HBorder) { var ba = hBorders[r, c]; var bb = anotherPartialGrid.hBorders[r, c]; if (ba == null && bb != null || bb == null && ba != null) { return(false); } if (ba.Span != bb.Span || !ba.Style.Equals(bb.Style) || !ba.Pos.Equals(bb.Pos)) { return(false); } } if ((flag & PartialGridCopyFlag.VBorder) == PartialGridCopyFlag.VBorder) { var ba = vBorders[r, c]; var bb = anotherPartialGrid.vBorders[r, c]; if (ba == null && bb != null || bb == null && ba != null) { return(false); } if (ba.Span != bb.Span || !ba.Style.Equals(bb.Style) || !ba.Pos.Equals(bb.Pos)) { return(false); } } } } return(true); }
public Graphics.Size MeasureCellText(Cell cell, DrawMode drawMode, float scale) { var sheet = cell.Worksheet; if (sheet == null) { return(Graphics.Size.Zero); } WorksheetRangeStyle style = cell.InnerStyle; int fieldWidth = 0; double s = 0, c = 0; //if (sf == null) sf = new System.Drawing.StringFormat(System.Drawing.StringFormat.GenericTypographic); if (cell.Style.RotationAngle != 0) { double d = (style.RotationAngle * Math.PI / 180.0d); s = Math.Sin(d); c = Math.Cos(d); } if (sf == null) { return(new Graphics.Size()); } lock (sf) { // merged cell need word break automatically if (style.TextWrapMode == TextWrapMode.NoWrap) { // no word break fieldWidth = 9999999; // TODO: avoid magic number sf.FormatFlags |= System.Drawing.StringFormatFlags.NoWrap; } else { // get cell available width float cellWidth = 0; if (cell.Style.RotationAngle != 0) { cellWidth = (float)(Math.Abs(cell.Bounds.Width * c) + Math.Abs(cell.Bounds.Height * s)); } else { cellWidth = cell.Bounds.Width; if (cell.InnerStyle != null) { if ((cell.InnerStyle.Flag & PlainStyleFlag.Indent) == PlainStyleFlag.Indent) { cellWidth -= (int)(cell.InnerStyle.Indent * sheet.IndentSize); } } // border width cellWidth -= 2; } // word break fieldWidth = (int)Math.Round(cellWidth * scale); sf.FormatFlags &= ~System.Drawing.StringFormatFlags.NoWrap; } if (cell.FontDirty) { sheet.UpdateCellRenderFont(this, cell, drawMode, UpdateFontReason.FontChanged); } var g = this.cachedGraphics; System.Drawing.Font scaledFont; switch (drawMode) { default: case DrawMode.View: scaledFont = cell.RenderFont; break; case DrawMode.Preview: case DrawMode.Print: scaledFont = this.resourceManager.GetFont(cell.RenderFont.Name, style.FontSize * scale, cell.RenderFont.Style); g = this.PlatformGraphics; System.Diagnostics.Debug.Assert(g != null); break; } SizeF size = g.MeasureString(cell.DisplayText, scaledFont, fieldWidth, sf); size.Height++; if (style.RotationAngle != 0) { float w = (float)(Math.Abs(size.Width * c) + Math.Abs(size.Height * s)); float h = (float)(Math.Abs(size.Width * s) + Math.Abs(size.Height * c)); size = new SizeF(w + 1, h + 1); } return(size); } }
/// <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); }
internal static RGXmlCellStyle ConvertToXmlStyle(WorksheetRangeStyle style) { if (style == null || style.Flag == PlainStyleFlag.None) { return(null); } RGXmlCellStyle xmlStyle = new RGXmlCellStyle(); if (StyleUtility.HasStyle(style, PlainStyleFlag.BackColor)) { xmlStyle.backColor = TextFormatHelper.EncodeColor(style.BackColor); } if (HasStyle(style, PlainStyleFlag.FillPattern)) { RGXmlCellStyleFillPattern xmlFillPattern = new RGXmlCellStyleFillPattern() { color = TextFormatHelper.EncodeColor(style.FillPatternColor), patternStyleId = (int)style.FillPatternStyle, }; xmlStyle.fillPattern = xmlFillPattern; } if (StyleUtility.HasStyle(style, PlainStyleFlag.TextColor)) { xmlStyle.textColor = TextFormatHelper.EncodeColor(style.TextColor); } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontName)) { xmlStyle.font = style.FontName; } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontSize)) { xmlStyle.fontSize = style.FontSize.ToString(); } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontStyleBold)) { xmlStyle.bold = style.Bold.ToString().ToLower(); } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontStyleItalic)) { xmlStyle.italic = style.Italic.ToString().ToLower(); } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontStyleStrikethrough)) { xmlStyle.strikethrough = style.Strikethrough.ToString().ToLower(); } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontStyleUnderline)) { xmlStyle.underline = style.Underline.ToString().ToLower(); } if (StyleUtility.HasStyle(style, PlainStyleFlag.HorizontalAlign)) { xmlStyle.hAlign = XmlFileFormatHelper.EncodeHorizontalAlign(style.HAlign); } if (StyleUtility.HasStyle(style, PlainStyleFlag.VerticalAlign)) { xmlStyle.vAlign = XmlFileFormatHelper.EncodeVerticalAlign(style.VAlign); } if (StyleUtility.HasStyle(style, PlainStyleFlag.TextWrap)) { xmlStyle.textWrap = XmlFileFormatHelper.EncodeTextWrapMode(style.TextWrapMode); } if (StyleUtility.HasStyle(style, PlainStyleFlag.Indent)) { xmlStyle.indent = style.Indent.ToString(); } if (StyleUtility.HasStyle(style, PlainStyleFlag.Padding)) { xmlStyle.padding = TextFormatHelper.EncodePadding(style.Padding); } if (StyleUtility.HasStyle(style, PlainStyleFlag.RotationAngle)) { xmlStyle.rotateAngle = style.RotationAngle.ToString(); } return(xmlStyle); }
public WorksheetReusableAction CreateUpdateAction() { var style = new WorksheetRangeStyle(); ReoGridHorAlign halign = ReoGridHorAlign.General; ReoGridVerAlign valign = ReoGridVerAlign.Middle; switch (cmbHorAlign.SelectedIndex) { default: case 0: halign = ReoGridHorAlign.General; break; case 1: halign = ReoGridHorAlign.Left; break; case 2: halign = ReoGridHorAlign.Center; break; case 3: halign = ReoGridHorAlign.Right; break; case 4: halign = ReoGridHorAlign.DistributedIndent; break; } switch (cmbVerAlign.SelectedIndex) { default: case 0: valign = ReoGridVerAlign.General; break; case 1: valign = ReoGridVerAlign.Top; break; case 2: valign = ReoGridVerAlign.Middle; break; case 3: valign = ReoGridVerAlign.Bottom; break; } if (backupHorAlign != halign) { style.Flag |= PlainStyleFlag.HorizontalAlign; style.HAlign = halign; } if (backupVerAlign != valign) { style.Flag |= PlainStyleFlag.VerticalAlign; style.VAlign = valign; } if (backupTextWrapState != chkWrapText.CheckState) { style.Flag |= PlainStyleFlag.TextWrap; if (chkWrapText.Checked) { style.TextWrapMode = TextWrapMode.WordBreak; } else { style.TextWrapMode = TextWrapMode.NoWrap; } } if (backupIndent != numIndent.Value) { style.Flag |= PlainStyleFlag.Indent; style.Indent = (ushort)numIndent.Value; } if (backupRotateAngle != textRotateControl.Angle) { style.RotationAngle = textRotateControl.Angle; style.Flag |= PlainStyleFlag.RotationAngle; } return(style.Flag == PlainStyleFlag.None ? null : new SetRangeStyleAction(grid.CurrentWorksheet.SelectionRange, style)); }
/// <summary> /// Check whether or not the style set contains the specified item /// </summary> /// <param name="style">style set to be checked</param> /// <param name="flag">style item to be checked</param> /// <returns>true if the style set contains the specified item</returns> public static bool HasStyle(WorksheetRangeStyle style, PlainStyleFlag flag) { return((style.Flag & flag) == flag); }
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))); }); }
internal static PlainStyleFlag CheckDistinctStyle(WorksheetRangeStyle style, WorksheetRangeStyle referStyle) { if (style == null || style.Flag == PlainStyleFlag.None) { return(PlainStyleFlag.None); } if (referStyle == null || referStyle.Flag == PlainStyleFlag.None) { return(PlainStyleFlag.None); } //var returnStyle = new WorksheetRangeStyle(style); var distinctedFlag = style.Flag; if (StyleUtility.HasStyle(style, PlainStyleFlag.FillPatternColor) && style.FillPatternColor == referStyle.FillPatternColor) { distinctedFlag &= ~PlainStyleFlag.FillPatternColor; } if (StyleUtility.HasStyle(style, PlainStyleFlag.FillPatternStyle) && style.FillPatternStyle == referStyle.FillPatternStyle) { distinctedFlag &= ~PlainStyleFlag.FillPatternStyle; } if (StyleUtility.HasStyle(style, PlainStyleFlag.BackColor) && style.BackColor == referStyle.BackColor) { distinctedFlag &= ~PlainStyleFlag.BackColor; } if (StyleUtility.HasStyle(style, PlainStyleFlag.TextColor) && style.TextColor == referStyle.TextColor) { distinctedFlag &= ~PlainStyleFlag.TextColor; } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontName) && style.FontName == referStyle.FontName) { distinctedFlag &= ~PlainStyleFlag.FontName; } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontSize) && style.FontSize == referStyle.FontSize) { distinctedFlag &= ~PlainStyleFlag.FontSize; } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontStyleBold) && style.Bold == referStyle.Bold) { distinctedFlag &= ~PlainStyleFlag.FontStyleBold; } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontStyleItalic) && style.Italic == referStyle.Italic) { distinctedFlag &= ~PlainStyleFlag.FontStyleItalic; } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontStyleStrikethrough) && style.Strikethrough == referStyle.Strikethrough) { distinctedFlag &= ~PlainStyleFlag.FontStyleStrikethrough; } if (StyleUtility.HasStyle(style, PlainStyleFlag.FontStyleUnderline) && style.Underline == referStyle.Underline) { distinctedFlag &= ~PlainStyleFlag.FontStyleUnderline; } if (StyleUtility.HasStyle(style, PlainStyleFlag.HorizontalAlign) && style.HAlign == referStyle.HAlign) { distinctedFlag &= ~PlainStyleFlag.HorizontalAlign; } if (StyleUtility.HasStyle(style, PlainStyleFlag.VerticalAlign) && style.VAlign == referStyle.VAlign) { distinctedFlag &= ~PlainStyleFlag.VerticalAlign; } if (StyleUtility.HasStyle(style, PlainStyleFlag.TextWrap) && style.TextWrapMode == referStyle.TextWrapMode) { distinctedFlag &= ~PlainStyleFlag.TextWrap; } if (StyleUtility.HasStyle(style, PlainStyleFlag.Indent) && style.Indent == referStyle.Indent) { distinctedFlag &= ~PlainStyleFlag.Indent; } if (StyleUtility.HasStyle(style, PlainStyleFlag.Padding) && style.Padding == referStyle.Padding) { distinctedFlag &= ~PlainStyleFlag.Padding; } if (StyleUtility.HasStyle(style, PlainStyleFlag.RotationAngle) && style.RotationAngle == referStyle.RotationAngle) { distinctedFlag &= ~PlainStyleFlag.RotationAngle; } return(distinctedFlag); }
private void GenerateHeader(Worksheet sheet, List <MaterialClass> list_matl) { var row_pos = 1; var col_pos = 23; // Start at Column 'X' var side_style = new WorksheetRangeStyle() { Flag = PlainStyleFlag.BackColor, BackColor = Color.Aqua, }; var align = new WorksheetRangeStyle() { Flag = PlainStyleFlag.HorizontalAlign, HAlign = ReoGridHorAlign.Left, }; var header_style = new WorksheetRangeStyle() { Flag = PlainStyleFlag.BackColor, BackColor = Color.Yellow, }; sheet[row_pos + 12, 0] = "週次 week"; sheet[row_pos + 12, 1] = "投產周別 production week"; sheet[row_pos + 12, 2] = "投產日期 production date"; sheet[row_pos + 12, 3] = "出貨週別 shipment week"; sheet[row_pos + 12, 4] = "工廠預計出貨日 Factory shipment date"; sheet[row_pos + 12, 5] = "每周計劃工作時數 weekly working hours"; sheet[row_pos + 12, 6] = "每週全廠現有生產線數(中線140)"; sheet[row_pos + 12, 7] = "每週全廠現有每小時產能"; sheet[row_pos + 12, 8] = "每週全廠產能(效率100%)"; sheet[row_pos + 12, 9] = "有效每週產能 (95%)"; sheet[row_pos + 12, 10] = "累計週次有效產能 (95%)"; sheet[row_pos + 12, 11] = "PO#"; sheet[row_pos + 12, 12] = "Model No"; sheet[row_pos + 12, 13] = "楦頭(Last No)"; sheet[row_pos + 12, 14] = "Model Name"; sheet[row_pos + 12, 15] = "底模(Tooling No)"; sheet[row_pos + 12, 16] = "刀模(Upper ID)"; sheet[row_pos + 12, 17] = "MI#"; sheet[row_pos + 12, 18] = "MI Group MI 組別"; sheet[row_pos + 12, 19] = "顏色(Article)"; sheet[row_pos + 12, 20] = "Order Qty"; sheet[row_pos + 12, 21] = "累計訂單數量"; sheet[row_pos + 12, 22] = "料號"; sheet.SetRangeBorders(row_pos + 12, 0, 1, 23, BorderPositions.All, new RangeBorderStyle(Color.Black, BorderLineStyle.Solid)); var col_count = list_matl.Count * 16 + 23; if (col_count > 16384) { throw new Exception("This excel has reached the column limit, Please decrease the count of data! (This will have " + col_count + " Columns)"); } foreach (var item in list_matl) { // Group print AutoAppend(sheet, row_pos + 12, col_pos + 15); sheet[row_pos + 0, col_pos] = "料號"; sheet[row_pos + 1, col_pos] = "料名"; sheet[row_pos + 2, col_pos] = "規格"; sheet[row_pos + 3, col_pos] = "單位"; sheet[row_pos + 4, col_pos] = "供應商"; sheet[row_pos + 5, col_pos] = "MOQ"; sheet[row_pos + 6, col_pos] = "交期天數"; sheet[row_pos + 7, col_pos] = "運輸天數"; sheet[row_pos + 8, col_pos] = "提前加工天數"; sheet[row_pos + 9, col_pos] = "安心庫存天數"; sheet[row_pos + 10, col_pos] = "下單天數"; sheet[row_pos + 0, col_pos + 1] = item.MatlNo; sheet[row_pos + 1, col_pos + 1] = item.MatlNa; sheet[row_pos + 3, col_pos + 1] = item.Unit; sheet[row_pos + 4, col_pos + 1] = item.SupplierCod + " " + item.SupplierNa; sheet[row_pos + 6, col_pos + 1] = item.MatlLT; sheet[row_pos + 7, col_pos + 1] = item.TransDat; sheet.MergeRange(row_pos + 0, col_pos + 1, 1, 15); sheet.MergeRange(row_pos + 1, col_pos + 1, 1, 15); sheet.MergeRange(row_pos + 2, col_pos + 1, 1, 15); sheet.MergeRange(row_pos + 3, col_pos + 1, 1, 15); sheet.MergeRange(row_pos + 4, col_pos + 1, 1, 15); sheet.MergeRange(row_pos + 5, col_pos + 1, 1, 15); sheet.MergeRange(row_pos + 6, col_pos + 1, 1, 15); sheet.MergeRange(row_pos + 7, col_pos + 1, 1, 15); sheet.MergeRange(row_pos + 8, col_pos + 1, 1, 15); sheet.MergeRange(row_pos + 9, col_pos + 1, 1, 15); sheet.MergeRange(row_pos + 10, col_pos + 1, 1, 15); sheet[row_pos + 12, col_pos + 0] = "單位用量"; sheet[row_pos + 12, col_pos + 1] = "損耗率"; sheet[row_pos + 12, col_pos + 2] = "需求量"; sheet[row_pos + 12, col_pos + 3] = "已採購數量"; sheet[row_pos + 12, col_pos + 4] = "採購單號"; sheet[row_pos + 12, col_pos + 5] = "採購日期"; sheet[row_pos + 12, col_pos + 6] = "已發出數量"; sheet[row_pos + 12, col_pos + 7] = "領料單號"; sheet[row_pos + 12, col_pos + 8] = "領料日期"; sheet[row_pos + 12, col_pos + 9] = "採購數量(未交量)"; sheet[row_pos + 12, col_pos + 10] = "訂單號碼(採購單號)"; sheet[row_pos + 12, col_pos + 11] = "入庫日期"; sheet[row_pos + 12, col_pos + 12] = "數量"; sheet[row_pos + 12, col_pos + 13] = "單號"; sheet[row_pos + 12, col_pos + 14] = "出庫日期"; sheet[row_pos + 12, col_pos + 15] = "期末庫存"; sheet.SetRangeBorders(row_pos, col_pos, 11, 16, BorderPositions.All, new RangeBorderStyle(Color.Black, BorderLineStyle.Solid)); sheet.SetRangeBorders(row_pos + 12, col_pos, 1, 16, BorderPositions.All, new RangeBorderStyle(Color.Black, BorderLineStyle.Solid)); sheet.SetRangeStyles(row_pos, col_pos, 2, 1, side_style); sheet.SetRangeStyles(row_pos + 3, col_pos, 2, 1, side_style); sheet.SetRangeStyles(row_pos + 6, col_pos, 2, 1, side_style); sheet.SetRangeStyles(row_pos, col_pos, 11, 15, align); sheet.SetRangeStyles(row_pos + 8, col_pos + 1, 2, 15, header_style); col_pos += 16; } }
private void OnSelectionChanged(object sender, Layouts.Extended.Cairo.Events.RangeEventArgs e) { this.m_UIUpdating = true; WorksheetRangeStyle style = this.m_CurrentWorkSheet.GetRangeStyles(this.m_CurrentWorkSheet.SelectionRange); this.chkBold.Checked = style.Bold; this.chkItalic.Checked = style.Italic; this.chkUnderline.Checked = style.Underline; this.chkAlignLeft.Checked = style.HAlign == ReoGridHorAlign.Left; this.chkAlignCenter.Checked = style.HAlign == ReoGridHorAlign.Center; this.chkAlignRight.Checked = style.HAlign == ReoGridHorAlign.Right; this.chkAlignJustified.Checked = style.HAlign == ReoGridHorAlign.DistributedIndent; this.chkAlignTop.Checked = style.VAlign == ReoGridVerAlign.Top; this.chkAlignMiddle.Checked = style.VAlign == ReoGridVerAlign.Middle; this.chkAlignBottom.Checked = style.VAlign == ReoGridVerAlign.Bottom; this.chkMerge.Checked = !this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.m_CurrentWorkSheet.IsMergedCell(this.m_CurrentWorkSheet.SelectionRange.StartPos); this.cbxFont.SelectedItem = this.cbxFont.Items.Cast <FontFamily>().FirstOrDefault(f => f.Name == style.FontName); this.cbxFontSize.SelectedItem = style.FontSize.ToString(); this.rdbDataCell.Checked = this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.IsCellType(typeof(CellBody)); this.rdbButtonCell.Checked = this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.IsCellType(typeof(ButtonCell)); this.rdbCheckboxCell.Checked = this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.IsCellType(typeof(CheckBoxCell)); this.rdbDatePickerCell.Checked = this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.IsCellType(typeof(DatePickerCell)); this.rdbDropdownCell.Checked = this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.IsCellType(typeof(DropdownCell)); this.rdbImageButtonCell.Checked = this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.IsCellType(typeof(ImageButtonCell)); this.rdbImageCell.Checked = this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.IsCellType(typeof(ImageCell)); this.rdbLinkCell.Checked = this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.IsCellType(typeof(HyperlinkCell)); this.rdbProgressbarCell.Checked = this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.IsCellType(typeof(ProgressCell)); this.rdbRadioButtonCell.Checked = this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.IsCellType(typeof(RadioButtonCell)); this.rdbNegativeProgressBarCell.Checked = this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.IsCellType(typeof(NegativeProgressCell)); this.rdbSliderCell.Checked = this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.IsCellType(typeof(SliderCell)); var cell = this.m_CurrentWorkSheet.Cells[this.m_CurrentWorkSheet.SelectionRange.StartPos]; if (cell.Formula == null) { if (cell.Data != null) { this.txtFormula.Text = cell.Data.ToString(); } else { this.txtFormula.Text = ""; } } else { this.txtFormula.Text = "=" + cell.Formula; } this.m_CurrentWorkSheet.RemoveAllHighlightRanges(); if (this.m_CurrentWorkSheet.SelectionRange.IsSingleCell && this.chkShowTrace.Checked) { this.m_CurrentWorkSheet.TraceCellPrecedents(this.m_CurrentWorkSheet.SelectionRange.StartPos); this.m_CurrentWorkSheet.TraceCellDependents(this.m_CurrentWorkSheet.SelectionRange.StartPos); List <ReferenceRange> references = this.m_CurrentWorkSheet.GetCellFormulaReferenceRanges(this.m_CurrentWorkSheet.SelectionRange.StartPos); if (references != null) { foreach (ReferenceRange reference in references) { this.m_CurrentWorkSheet.AddHighlightRange(reference); } } } this.m_UIUpdating = false; }