internal FillXmlWrapper Copy() { FillXmlWrapper newFill = new FillXmlWrapper(); newFill.PatternType = this._FillPatternType; newFill.BackgroundColor = this._BackgroundColor.Copy(); newFill.PatternColor = this._PatternColor.Copy(); return(newFill); }
internal FillXmlWrapper Copy() { FillXmlWrapper newFill = new FillXmlWrapper(); newFill.PatternType = this._FillPatternType; newFill.BackgroundColor = this._BackgroundColor.Copy(); newFill.PatternColor = this._PatternColor.Copy(); return newFill; }
private static XElement WriteFill(FillXmlWrapper fill) { XElement root = new XElement(ExcelCommon.Schema_WorkBook_Main + "fill"); XElement fillXml = new XElement(ExcelCommon.Schema_WorkBook_Main + "patternFill", new XAttribute("patternType", FillXmlWrapper.SetPatternString(fill.PatternType))); root.Add(fillXml); if (fill.PatternType == ExcelFillStyle.None) { return root; } if (fill._PatternColor != null) { var colorXml = new XElement(ExcelCommon.Schema_WorkBook_Main + "fgColor"); if (fill._PatternColor.Rgb.IsNotEmpty()) { colorXml.Add(new XAttribute("rgb", fill._PatternColor.Rgb)); } if (fill._PatternColor.Auto) { colorXml.Add(new XAttribute("auto", fill._PatternColor.Auto)); } if (fill._PatternColor.Tint != 0) { colorXml.Add(new XAttribute("tint", fill._PatternColor.Tint.ToString(CultureInfo.InvariantCulture))); } if (fill._PatternColor.Indexed != int.MinValue) { colorXml.Add(new XAttribute("indexed", fill._PatternColor.Indexed.ToString(CultureInfo.InvariantCulture))); } if (fill._PatternColor.Theme.IsNotEmpty()) { colorXml.Add(new XAttribute("theme", fill._PatternColor.Theme)); } fillXml.Add(colorXml); } if (fill._BackgroundColor != null) { var bgColorXml = new XElement(ExcelCommon.Schema_WorkBook_Main + "bgColor"); if (fill._BackgroundColor.Rgb.IsNotEmpty()) { bgColorXml.Add(new XAttribute("rgb", fill._BackgroundColor.Rgb)); } if (fill._BackgroundColor.Auto) { bgColorXml.Add(new XAttribute("auto", "1")); } if (fill._BackgroundColor.Tint != 0) { bgColorXml.Add(new XAttribute("tint", fill._BackgroundColor.Tint.ToString(CultureInfo.InvariantCulture))); } if (fill._BackgroundColor.Indexed != int.MinValue) { bgColorXml.Add(new XAttribute("indexed", fill._BackgroundColor.Indexed.ToString(CultureInfo.InvariantCulture))); } if (fill._BackgroundColor.Theme.IsNotEmpty()) { bgColorXml.Add(new XAttribute("theme", fill._BackgroundColor.Theme)); } fillXml.Add(bgColorXml); } return root; }
public void ReadStyles_fill_Color(FillXmlWrapper target, XElement item) { foreach (XElement colorNode in item.Nodes()) { switch (colorNode.Name.LocalName) { case "bgColor": target.BackgroundColor = new ColorXmlWrapper(); if (colorNode.Attribute("indexed") != null) { target.BackgroundColor.Indexed = int.Parse(colorNode.Attribute("indexed").Value); } if (colorNode.Attribute("rgb") != null) { target.BackgroundColor.Rgb = colorNode.Attribute("rgb").Value; } if (colorNode.Attribute("theme") != null) { target.BackgroundColor.Theme = colorNode.Attribute("theme").Value; } if (colorNode.Attribute("tint") != null) { target.BackgroundColor.Tint = decimal.Parse(colorNode.Attribute("tint").Value); } break; case "fgColor": target.PatternColor = new ColorXmlWrapper(); if (colorNode.Attribute("indexed") != null) { target.PatternColor.Indexed = int.Parse(colorNode.Attribute("indexed").Value); } if (colorNode.Attribute("rgb") != null) { target.PatternColor.Rgb = colorNode.Attribute("rgb").Value; } if (colorNode.Attribute("theme") != null) { target.PatternColor.Theme = colorNode.Attribute("theme").Value; } if (colorNode.Attribute("tint") != null) { decimal decTint; if (decimal.TryParse(colorNode.Attribute("tint").Value, NumberStyles.Any, CultureInfo.InvariantCulture, out decTint) == true) { target.PatternColor.Tint = decTint; //decimal.Parse(colorNode.Attribute("tint").Value); } } break; } } }
/// <summary> /// FileName:styles.xml /// <para>NodePath:styleSheet/fills/fill</para> /// </summary> /// <param name="root"></param> /// <returns></returns> public void ReadStyles_fill(FillXmlWrapper target, XElement item) { foreach (XElement fillNode in item.Nodes()) { switch (fillNode.Name.LocalName) { case "patternFill": if (fillNode.Attribute("patternType") != null) { target.PatternType = target.GetPatternType(fillNode.Attribute("patternType").Value); ReadStyles_fill_Color(target, fillNode); } break; } } }
/// <summary> /// FileName:styles.xml /// <para>NodePath:styleSheet/fills</para> /// </summary> /// <param name="root"></param> /// <returns></returns> public void ReadStyles_fills(WorkBookStylesWrapper target, XElement item) { foreach (XElement fill in item.Nodes()) { FillXmlWrapper fillObj = new FillXmlWrapper(); ReadStyles_fill(fillObj, fill); target.Fills.Add(fillObj); } }