コード例 #1
0
        /// <summary>
        /// 设置背景着颜色(注意,当ExcelFillStyle.Solid 请不要再设置前景色PatternColor,设置为None将不会填充)
        /// </summary>
        /// <param name="color"></param>
        /// <param name="pattern"></param>
        public void SetBackgroundColor(Color color, ExcelFillStyle pattern)
        {
            if (this._BackgroundColor == null)
            {
                this._BackgroundColor = new ColorXmlWrapper();
            }

            if (pattern == ExcelFillStyle.Solid)
            {
                this._BackgroundColor.Indexed = 64;
                if (this._PatternColor == null)
                {
                    this._PatternColor = new ColorXmlWrapper();
                }
                this._PatternColor.SetColor(color);
            }
            else
            {
                this._BackgroundColor.SetColor(color);
            }

            this.PatternType = pattern;
        }
コード例 #2
0
ファイル: FillXml.cs プロジェクト: jerryshi2007/AK47Source
		/// <summary>
		/// 设置背景着颜色(注意,当ExcelFillStyle.Solid 请不要再设置前景色PatternColor,设置为None将不会填充)
		/// </summary>
		/// <param name="color"></param>
		/// <param name="pattern"></param>
		public void SetBackgroundColor(Color color, ExcelFillStyle pattern)
		{
			if (this._BackgroundColor == null)
			{
				this._BackgroundColor = new ColorXmlWrapper();
			}

			if (pattern == ExcelFillStyle.Solid)
			{
				this._BackgroundColor.Indexed =64;
				if (this._PatternColor == null)
				{
					this._PatternColor = new ColorXmlWrapper();
				}
				this._PatternColor.SetColor(color);
			}
			else
			{
				this._BackgroundColor.SetColor(color);
			}

			this.PatternType = pattern;
		}
コード例 #3
0
 /// <summary>
 /// FileName:styles.xml
 /// <para>NodePath:styleSheet/fonts/font/color</para>
 /// </summary>
 /// <param name="root"></param>
 /// <returns></returns>
 public void ReadStyles_Color(XElement root, ColorXmlWrapper target)
 {
     if (root.Attribute("auto") != null)
     {
         target.Auto = root.Attribute("auto").Value.Equals("1") ? true : false;
     }
     if (root.Attribute("indexed") == null)
     {
         if (root.Attribute("theme") != null)
         {
             target.Theme = root.Attribute("theme").Value;
         }
         if (root.Attribute("rgb") != null)
         {
             target.Rgb = root.Attribute("rgb").Value;
         }
     }
     else
     {
         target.Indexed = int.Parse(root.Attribute("indexed").Value);
     }
 }
コード例 #4
0
        private static XElement WriteColor(ColorXmlWrapper color)
        {
            XElement colorXml = null;

            if (color.Rgb.IsNotEmpty() || color.Auto || color.Indexed != int.MinValue || color.Theme.IsNotEmpty())
            {
                colorXml = new XElement(ExcelCommon.Schema_WorkBook_Main + "color");
                if (color.Rgb.IsNotEmpty())
                {
                    colorXml.Add(new XAttribute("rgb", color.Rgb));

                    if (color.Theme.IsNotEmpty())
                    {
                        colorXml.Add(new XAttribute("theme", color.Theme));
                    }
                }
                else if (color.Indexed != int.MinValue)
                {
                    colorXml.Add(new XAttribute("indexed", color.Indexed.ToString(CultureInfo.InvariantCulture)));
                }

                if (color.Tint >= 0)
                {
                    colorXml.Add(new XAttribute("tint", color.Tint.ToString(CultureInfo.InvariantCulture)));
                }

                if (color.Auto)
                {
                    colorXml.Add(new XAttribute("auto", color.Auto));
                }
            }

            return colorXml;
        }
コード例 #5
0
        internal void ReadSheetComments_Comment(List<string> authors, XElement commentMode, Comment cellComment)
        {
            if (commentMode.Attribute("authorId") != null)
            {
                cellComment.Author = authors[int.Parse(commentMode.Attribute("authorId").Value)];
            }

            XElement textPropertyNode = commentMode.Element(XName.Get("text", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
            if (textPropertyNode != null)
            {
                IEnumerable<XElement> richTextNodes = textPropertyNode.Elements(XName.Get("r", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                foreach (XElement richtextNode in richTextNodes)
                {
                    RichText rt = new RichText();
                    XElement rtnode = richtextNode.Element(XName.Get("t", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                    if (rtnode != null)
                    {
                        if (rtnode.Attribute(XName.Get("space", ExcelCommon.Schema_Xml)) != null)
                        {
                            rt.PreserveSpace = true;
                        }
                        rt.Text = rtnode.Value;
                    }

                    rtnode = richtextNode.Element(XName.Get("rPr", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                    if (rtnode != null)
                    {
                        XElement rPrNode = rtnode.Element(XName.Get("b", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Bold = true;
                        }

                        rPrNode = rtnode.Element(XName.Get("charset", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            if (rPrNode.Attribute(XName.Get("val", ExcelCommon.Schema_WorkBook_Main.NamespaceName)) != null)
                            {
                                rt.Charset = int.Parse(rPrNode.Attribute(XName.Get("val", ExcelCommon.Schema_WorkBook_Main.NamespaceName)).Value);
                            }
                        }
                        rPrNode = rtnode.Element(XName.Get("color", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            ColorXmlWrapper rtColor = new ColorXmlWrapper();
                            ReadStyles_Color(rPrNode, rtColor);
                            rt._DataBarColor = rtColor;
                        }
                        rPrNode = rtnode.Element(XName.Get("condense", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Condense = true;
                        }
                        rPrNode = rtnode.Element(XName.Get("extend", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Extend = true;
                        }

                        //todo: family
                        //rPrNode = richtextNode.Element(XName.Get("family", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        //if (rPrNode != null)
                        //{
                        //    if (rPrNode.Attribute(XName.Get("val", ExcelCommon.Schema_WorkBook_Main.NamespaceName)) != null)
                        //    {
                        //        rt.FontName = rPrNode.Attribute(XName.Get("val", ExcelCommon.Schema_WorkBook_Main.NamespaceName)).Value;
                        //    }
                        //}

                        rPrNode = rtnode.Element(XName.Get("i", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Italic = true;
                        }

                        rPrNode = rtnode.Element(XName.Get("outline", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Outline = true;
                        }

                        rPrNode = rtnode.Element(ExcelCommon.Schema_WorkBook_Main + "rFont");
                        if (rPrNode != null)
                        {
                            if (rPrNode.Attribute("val") != null)
                            {
                                rt.FontName = rPrNode.Attribute("val").Value;
                            }
                        }

                        rPrNode = rtnode.Element(XName.Get("scheme", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            if (rPrNode.Attribute("val") != null)
                            {
                                rt.Scheme = rPrNode.Attribute("val").Value;
                            }
                        }

                        rPrNode = rtnode.Element(XName.Get("shadow", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Shadow = true;
                        }

                        rPrNode = rtnode.Element(XName.Get("strike", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.Strike = true;
                        }

                        rPrNode = rtnode.Element(XName.Get("sz", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            if (rPrNode.Attribute("val") != null)
                            {
                                rt.Size = float.Parse(rPrNode.Attribute("val").Value);
                            }
                        }

                        rPrNode = rtnode.Element(XName.Get("u", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            rt.UnderLine = true;
                        }

                        rPrNode = rtnode.Element(XName.Get("vertAlign", ExcelCommon.Schema_WorkBook_Main.NamespaceName));
                        if (rPrNode != null)
                        {
                            if (rPrNode.Attribute("val") != null)
                            {
                                rt.VerticalAlign = (ExcelVerticalAlignmentFont)Enum.Parse(typeof(ExcelVerticalAlignmentFont), rPrNode.Attribute("val").Value, true); ;
                            }
                        }
                    }

                    cellComment.RichText.Add(rt);
                }
            }
        }