示例#1
0
        string GenerateStyleTemplate()
        {
            var r = new StringBuilder();

            r.AppendLine(@"<Style ss:ID=""[#Style.ID#]"">");
            r.AddFormattedLine(@"<Alignment ss:Horizontal=""{0}"" ss:Vertical=""{1}"" ss:Rotate=""{2}""{3}/>", Alignment, VerticalAlignment, GetCellRotation(), " ss:WrapText=\"1\"".OnlyWhen(WrapText));
            r.AddFormattedLine(@"<Font ss:FontName=""{0}"" x:Family=""Swiss"" ss:Size=""{1}"" ss:Color=""{2}"" ss:Bold=""{3}"" ss:Italic=""{4}"" />", FontName, FontSize, ForeColor, Bold ? 1 : 0, Italic ? 1 : 0);

            if (BackgroundColor.HasValue() && BackgroundColor.ToUpper() != "#FFFFFF")
            {
                r.AddFormattedLine(@"<Interior ss:Color=""{0}"" ss:Pattern=""Solid""/>", BackgroundColor);
            }

            if (BorderWidth > 0)
            {
                r.AddFormattedLine(@"<Borders>
                                  <Border ss:Position=""Bottom"" ss:LineStyle=""Continuous"" ss:Weight=""{1}"" ss:Color=""{0}""/>
                                  <Border ss:Position=""Left"" ss:LineStyle=""Continuous"" ss:Weight=""{1}"" ss:Color=""{0}""/>
                                  <Border ss:Position=""Right"" ss:LineStyle=""Continuous"" ss:Weight=""{1}"" ss:Color=""{0}""/>
                                  <Border ss:Position=""Top"" ss:LineStyle=""Continuous""  ss:Weight=""{1}"" ss:Color=""{0}""/>
                                 </Borders>", BorderColor, BorderWidth);
            }

            if (NumberFormat.HasValue())
            {
                r.AddFormattedLine(@"<NumberFormat ss:Format=""{0}"" />", NumberFormat.HtmlEncode());
            }

            r.AppendLine(@"</Style>");

            return(r.ToString());
        }
        public override XElement ToXElement()
        {
            XElement xml = base.ToXElement();

            if (BackgroundColor.HasValue())
            {
                xml.Add(NewXElement("bgColor", BackgroundColor));
            }
            if (TextColor.HasValue())
            {
                xml.Add(NewXElement("textColor", TextColor));
            }
            if (Text.HasValue())
            {
                xml.Add(NewXElement("text", new XCData(Text)));
            }
            if (DisplayMode.HasValue())
            {
                xml.Add(NewXElement("displayMode", DisplayMode));
            }

            return(xml);
        }