Beispiel #1
0
        /**
         * Whether the bold property shall be applied to all non-complex script
         * characters in the contents of this run.when displayed in a document.
         * <p>
         * This formatting property is a toggle property, which specifies that its
         * behavior differs between its use within a style defInition and its use as
         * direct formatting. When used as part of a style defInition, Setting this
         * property shall toggle the current state of that property as specified up
         * to this point in the hierarchy (i.e. applied to not applied, and vice
         * versa). Setting it to <code>false</code> (or an equivalent) shall
         * result in the current Setting remaining unChanged. However, when used as
         * direct formatting, Setting this property to true or false shall Set the
         * absolute state of the resulting property.
         * </p>
         * <p>
         * If this element is not present, the default value is to leave the
         * formatting applied at previous level in the style hierarchy. If this
         * element is never applied in the style hierarchy, then bold shall not be
         * applied to non-complex script characters.
         * </p>
         *
         * @param value <code>true</code> if the bold property is applied to
         *              this run
         */
        public void SetBold(bool value)
        {
            CT_RPr   pr   = run.IsSetRPr() ? run.rPr : run.AddNewRPr();
            CT_OnOff bold = pr.IsSetB() ? pr.b : pr.AddNewB();

            bold.val = (value ? ST_OnOff.True : ST_OnOff.False);
        }
Beispiel #2
0
        /**
         * Whether the bold property shall be applied to all non-complex script
         * characters in the contents of this run.when displayed in a document.
         * <p>
         * This formatting property is a toggle property, which specifies that its
         * behavior differs between its use within a style defInition and its use as
         * direct formatting. When used as part of a style defInition, Setting this
         * property shall toggle the current state of that property as specified up
         * to this point in the hierarchy (i.e. applied to not applied, and vice
         * versa). Setting it to <code>false</code> (or an equivalent) shall
         * result in the current Setting remaining unChanged. However, when used as
         * direct formatting, Setting this property to true or false shall Set the
         * absolute state of the resulting property.
         * </p>
         * <p>
         * If this element is not present, the default value is to leave the
         * formatting applied at previous level in the style hierarchy. If this
         * element is never applied in the style hierarchy, then bold shall not be
         * applied to non-complex script characters.
         * </p>
         *
         * @param value <code>true</code> if the bold property is applied to
         *              this run
         */
        public void SetBold(bool value)
        {
            CT_RPr   pr   = run.IsSetRPr() ? run.rPr : run.AddNewRPr();
            CT_OnOff bold = pr.IsSetB() ? pr.b : pr.AddNewB();

            bold.val = value;
        }
Beispiel #3
0
        /**
         * Get text color. The returned value is a string in the hex form "RRGGBB".
         */
        public String GetColor()
        {
            String color = null;

            if (run.IsSetRPr())
            {
                CT_RPr pr = run.rPr;
                if (pr.IsSetColor())
                {
                    NPOI.OpenXmlFormats.Wordprocessing.CT_Color clr = pr.color;
                    color = clr.val; //clr.xgetVal().getStringValue();
                }
            }
            return(color);
        }
        /// <summary>
        /// 设置字体大小
        /// </summary>
        /// <param name="run"></param>
        /// <param name="sizeType"></param>
        public static void SetFontSize(this XWPFRun run, FontSizeType sizeType)
        {
            ulong         fontSize = GetFontSize(sizeType);
            CT_R          r        = run.GetCTR();
            CT_RPr        rpr      = r.IsSetRPr() ? r.rPr : r.AddNewRPr();
            CT_HpsMeasure ctSize   = rpr.IsSetSz() ? rpr.sz : rpr.AddNewSz();

            ctSize.val = fontSize;
        }
        /// <summary>
        /// 设置颜色
        /// </summary>
        /// <param name="run"></param>
        /// <param name="colorType"></param>
        public static void SetRunColor(this XWPFRun run, ColorType colorType)
        {
            Tuple <string, string> temp = GetColor(colorType);
            CT_R     r     = run.GetCTR();
            CT_RPr   rpr   = r.IsSetRPr() ? r.rPr : r.AddNewRPr();
            CT_Color color = rpr.IsSetColor() ? rpr.color : rpr.AddNewColor();

            color.val = temp.Item1;
        }
        /// <summary>
        /// 设置字体
        /// </summary>
        /// <param name="run"></param>
        /// <param name="nameType"></param>
        public static void SetFontName(this XWPFRun run, FontNameType nameType)
        {
            string   fontName = GetFontName(nameType);
            CT_R     r        = run.GetCTR();
            CT_RPr   rpr      = r.IsSetRPr() ? r.rPr : r.AddNewRPr();
            CT_Fonts fonts    = rpr.IsSetRFonts() ? rpr.rFonts : rpr.AddNewRFonts();

            fonts.ascii = fontName;
            if (string.IsNullOrEmpty(fonts.eastAsia))
            {
                fonts.eastAsia = fontName;
            }
            if (string.IsNullOrEmpty(fonts.cs))
            {
                fonts.cs = fontName;
            }
            if (string.IsNullOrEmpty(fonts.hAnsi))
            {
                fonts.hAnsi = fontName;
            }
        }