コード例 #1
0
        ///<summary>
        ///Creates or gets an existing font with the style information provided.
        ///</summary>
        public static UInt32 CreateFont(SpreadsheetStyle style, WorkbookStylesPart styles)
        {
            Font   fontMatch = null;
            UInt32 fontIndex = 0;

            //Loop through and see if there is a matching font style
            foreach (var fontElement in styles.Stylesheet.Fonts)
            {
                Font font = (Font)fontElement;

                //If we have a match then use this font
                if (SpreadsheetStyle.CompareFont(font, style))
                {
                    fontMatch = font;
                    break;
                }
                fontIndex += Convert.ToUInt32(1);
            }

            //Add the new font if not found
            if (fontMatch == null)
            {
                Font font = style.ToFont();
                styles.Stylesheet.Fonts.AppendChild <Font>(font); //Font index already set to new count
                styles.Stylesheet.Fonts.Count = fontIndex + Convert.ToUInt32(1);
            }

            return(fontIndex);
        }
コード例 #2
0
        public void CompareFontTest()
        {
            Font       x           = new Font();
            Font       y           = new Font();
            FontSize   size1       = new FontSize();
            FontSize   size2       = new FontSize();
            Color      color1      = new Color();
            Color      color2      = new Color();
            FontName   fontName1   = new FontName();
            FontName   fontName2   = new FontName();
            FontFamily fontFamily1 = new FontFamily();
            FontFamily fontFamily2 = new FontFamily();
            FontScheme fontScheme1 = new FontScheme();
            FontScheme fontScheme2 = new FontScheme();

            color1.Rgb      = "FFFF0000";
            color2.Rgb      = "FFFF0000";
            size1.Val       = 12;
            size2.Val       = 12;
            fontName1.Val   = "Calibri";
            fontName2.Val   = "Calibri";
            fontFamily1.Val = 2;
            fontFamily2.Val = 2;
            fontScheme1.Val = FontSchemeValues.Minor;
            fontScheme2.Val = FontSchemeValues.Minor;

            x.AppendChild <Italic>(new Italic());
            x.AppendChild <FontSize>(size1);
            x.AppendChild <Color>(color1);
            x.AppendChild <FontName>(fontName1);
            x.AppendChild <FontFamily>(fontFamily1);
            x.AppendChild <FontScheme>(fontScheme1);

            y.AppendChild <Italic>(new Italic());
            y.AppendChild <FontSize>(size2);
            y.AppendChild <Color>(color2);
            y.AppendChild <FontName>(fontName2);
            y.AppendChild <FontFamily>(fontFamily2);
            y.AppendChild <FontScheme>(fontScheme2);

            //check they match
            Assert.IsTrue(SpreadsheetStyle.CompareFont(x, y), "Equal fonts do not compare.");

            //change a value
            size2.Val = 13;
            Assert.IsFalse(SpreadsheetStyle.CompareFont(x, y), "Unequal fonts do compare.");
        }