private void SetFill() { WorkbookColorInfo patternColor = WorkbookColorInfo.Automatic; WorkbookColorInfo backgroundColor = WorkbookColorInfo.Automatic; if (this.BackgroundColor.HasValue && this.BackgroundColor.Value != Colors.Transparent) { backgroundColor = new WorkbookColorInfo(this.BackgroundColor.Value); } if (this.PatternColor != null && this.PatternColor != Colors.Transparent) { patternColor = new WorkbookColorInfo(this.PatternColor.Value); } this.Fill = new CellFillPattern(backgroundColor, patternColor, this.FillPatternStyle); }
private void SetFill() { WorkbookColorInfo patternColorInfo = WorkbookColorInfo.Automatic; WorkbookColorInfo backgroundColorInfo = WorkbookColorInfo.Automatic; Color backgroundColor = this.cpBackColor.Color; Color patternColor = this.cpPatternColor.Color; if (backgroundColor.IsEmpty == false && backgroundColor != Color.Transparent) { backgroundColorInfo = new WorkbookColorInfo(backgroundColor); } if (patternColor.IsEmpty == false && patternColor != Color.Transparent) { patternColorInfo = new WorkbookColorInfo(patternColor); } this.fillPreviewControl1.PreviewFill = new CellFillPattern(backgroundColorInfo, patternColorInfo, (FillPatternStyle)this.cboPatternStyle.Value); }
private void CommitChanges() { var format = this.adapter.Format; var font = format.Font; WorkbookColorInfo newBackgroundColorInfo = null; WorkbookColorInfo newPatternColorInfo = null; bool updatePatternStyle = false; foreach (var propertyName in this.changedProperties.Distinct()) { switch (propertyName) { case BackgroundColorPropertyName: #region BackgroundColorPropertyName if (!this.cpBackColor.Color.IsEmpty) { try { newBackgroundColorInfo = new WorkbookColorInfo(this.cpBackColor.Color); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; #endregion //BackgroundColorPropertyName case FillPatternStylePropertyName: #region FillPatternStylePropertyName updatePatternStyle = true; break; #endregion //FillPatternStylePropertyName case FontColorPropertyName: #region FontColorPropertyName if (!this.cpFontColor.Color.IsEmpty) { try { font.ColorInfo = new WorkbookColorInfo(this.cpFontColor.Color); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; #endregion //FontColorPropertyName case FontNamePropertyName: #region FontNamePropertyName font.Name = (string)this.treeFontFamily.ActiveNode.Cells["Value"].Value; break; #endregion //FontNamePropertyName case FontSizePropertyName: #region FontSizePropertyName font.Height = (int)this.treeFontSize.ActiveNode.Cells["DataValue"].Value; break; #endregion //FontSizePropertyName case FontStylePropertyName: #region FontStylePropertyName ExcelDefaultableBoolean isBold = ExcelDefaultableBoolean.False; ExcelDefaultableBoolean isItalic = ExcelDefaultableBoolean.False; switch ((FontStylesCustom)this.treeFontStyle.ActiveNode.Cells["Value"].Value) { case FontStylesCustom.Bold: isBold = ExcelDefaultableBoolean.True; break; case FontStylesCustom.Italic: isItalic = ExcelDefaultableBoolean.True; break; case FontStylesCustom.BoldItalic: isBold = ExcelDefaultableBoolean.True; isItalic = ExcelDefaultableBoolean.True; break; } font.Bold = isBold; font.Italic = isItalic; break; #endregion //FontStylePropertyName case HorizontalCellAlignmentPropertyName: #region HorizontalCellAlignmentPropertyName format.Alignment = (HorizontalCellAlignment)this.cboHorizontal.Value; break; #endregion //HorizontalCellAlignmentPropertyName case IndentPropertyName: #region IndentPropertyName format.Indent = (int)this.nmeIndent.Value; break; #endregion //IndentPropertyName case PatternColorPropertyName: #region PatternColorPropertyName if (!this.cpPatternColor.Color.IsEmpty) { try { newPatternColorInfo = new WorkbookColorInfo(this.cpPatternColor.Color); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; #endregion //PatternColorPropertyName case ShrinkToFitPropertyName: #region ShrinkToFitPropertyName format.ShrinkToFit = (this.cbShrinkToFit.Checked) ? ExcelDefaultableBoolean.True : ExcelDefaultableBoolean.False; break; #endregion //ShrinkToFitPropertyName case StrikethroughPropertyName: #region StrikethroughPropertyName font.Strikeout = this.cbStrikethrough.Checked ? ExcelDefaultableBoolean.True : ExcelDefaultableBoolean.False; break; #endregion //StrikethroughPropertyName case SubscriptSuperscriptPropertyName: #region SubscriptSuperscriptPropertyName if (this.cbSubscript.Checked) { font.SuperscriptSubscriptStyle = FontSuperscriptSubscriptStyle.Subscript; } else if (this.cbSuperscript.Checked) { font.SuperscriptSubscriptStyle = FontSuperscriptSubscriptStyle.Superscript; } break; #endregion //SubscriptSuperscriptPropertyName case UnderlinePropertyName: #region UnderlinePropertyName font.UnderlineStyle = (FontUnderlineStyle)this.cboUnderline.Value; break; #endregion //UnderlinePropertyName case VerticalCellAlignmentPropertyName: #region VerticalCellAlignmentPropertyName format.VerticalAlignment = (VerticalCellAlignment)this.cboVertical.Value; break; #endregion //VerticalCellAlignmentPropertyName case WrapTextPropertyName: #region WrapTextPropertyName format.WrapText = (this.cbWrapText.Checked) ? ExcelDefaultableBoolean.True : ExcelDefaultableBoolean.False; break; #endregion //WrapTextPropertyName case FormatPropertyName: #region FormatPropertyName if (this.treeFormats.SelectedNodes.Count > 0) { format.FormatString = ((FormatInfo)this.treeFormats.SelectedNodes[0].ListObject).Mask; } break; #endregion //FormatPropertyName default: Debug.Fail("Unhandled " + propertyName); break; } } if (updatePatternStyle || newBackgroundColorInfo != null || newPatternColorInfo != null) { CellFillPattern oldPattern = format.Fill as CellFillPattern; format.Fill = new CellFillPattern( newBackgroundColorInfo ?? oldPattern.BackgroundColorInfo, newPatternColorInfo ?? oldPattern.PatternColorInfo, updatePatternStyle ? (FillPatternStyle)this.cboPatternStyle.Value : oldPattern.PatternStyle); } }