Example #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);
        }
Example #2
0
        public TOC(CT_SdtBlock block)
        {
            this.block = block;
            CT_SdtPr         sdtPr = block.AddNewSdtPr();
            CT_DecimalNumber id    = sdtPr.AddNewId();

            id.val = ("4844945");
            sdtPr.AddNewDocPartObj().AddNewDocPartGallery().val = ("Table of contents");
            CT_SdtEndPr sdtEndPr = block.AddNewSdtEndPr();
            CT_RPr      rPr      = sdtEndPr.AddNewRPr();
            CT_Fonts    fonts    = rPr.AddNewRFonts();

            fonts.asciiTheme    = (ST_Theme.minorHAnsi);
            fonts.eastAsiaTheme = (ST_Theme.minorHAnsi);
            fonts.hAnsiTheme    = (ST_Theme.minorHAnsi);
            fonts.cstheme       = (ST_Theme.minorBidi);
            rPr.AddNewB().val          = false;
            rPr.AddNewBCs().val        = false;
            rPr.AddNewColor().val      = ("auto");
            rPr.AddNewSz().val         = 24;
            rPr.AddNewSzCs().val       = 24;
            CT_SdtContentBlock content = block.AddNewSdtContent();
            CT_P p = content.AddNewP();

            byte[] b = Encoding.Unicode.GetBytes("00EF7E24");
            p.rsidR        = b;
            p.rsidRDefault = b;
            p.AddNewPPr().AddNewPStyle().val = ("TOCHeading");
            p.AddNewR().AddNewT().Value      = ("Table of Contents");
        }
Example #3
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;
        }
Example #4
0
        public TOC(CT_SdtBlock block)
        {
            this.block = block;
            CT_SdtPr ctSdtPr = block.AddNewSdtPr();

            ctSdtPr.AddNewId().val = "4844945";
            ctSdtPr.AddNewDocPartObj().AddNewDocPartGallery().val = "Table of contents";
            CT_RPr   ctRpr   = block.AddNewSdtEndPr().AddNewRPr();
            CT_Fonts ctFonts = ctRpr.AddNewRFonts();

            ctFonts.asciiTheme    = ST_Theme.minorHAnsi;
            ctFonts.eastAsiaTheme = ST_Theme.minorHAnsi;
            ctFonts.hAnsiTheme    = ST_Theme.minorHAnsi;
            ctFonts.cstheme       = ST_Theme.minorBidi;
            ctRpr.AddNewB().val     = ST_OnOff.off;
            ctRpr.AddNewBCs().val   = ST_OnOff.off;
            ctRpr.AddNewColor().val = "auto";
            ctRpr.AddNewSz().val    = 24UL;
            ctRpr.AddNewSzCs().val  = 24UL;
            CT_P ctP = block.AddNewSdtContent().AddNewP();

            byte[] bytes = Encoding.Unicode.GetBytes("00EF7E24");
            ctP.rsidR        = bytes;
            ctP.rsidRDefault = bytes;
            ctP.AddNewPPr().AddNewPStyle().val = "TOCHeading";
            ctP.AddNewR().AddNewT().Value      = "Table of Contents";
        }
Example #5
0
        public void TestSetGetBold()
        {
            CT_RPr rpr = ctRun.AddNewRPr();

            rpr.AddNewB().val = (ST_OnOff.True);

            XWPFRun run = new XWPFRun(ctRun, p);

            Assert.AreEqual(true, run.IsBold());

            run.SetBold(false);
            Assert.AreEqual(ST_OnOff.False, rpr.b.val);
        }
Example #6
0
        public void TestSetGetBold()
        {
            CT_RPr rpr = ctRun.AddNewRPr();

            rpr.AddNewB().val = true;

            XWPFRun run = new XWPFRun(ctRun, p);

            Assert.AreEqual(true, run.IsBold);

            run.IsBold = (false);
            Assert.AreEqual(false, run.IsBold);
            Assert.AreEqual(false, rpr.b.val);
        }
Example #7
0
        public void TestSetGetBold()
        {
            CT_RPr rpr = ctRun.AddNewRPr();

            rpr.AddNewB().val = true;

            XWPFRun run = new XWPFRun(ctRun, p);

            Assert.AreEqual(true, run.IsBold);

            run.IsBold = (false);
            // Implementation detail: POI natively prefers <w:b w:val="false"/>,
            // but should correctly read val="0" and val="off"
            Assert.AreEqual(false, run.IsBold);
            Assert.AreEqual(false, rpr.b.val);
        }
    /// <summary>
    /// 创建文档
    /// </summary>
    /// <param name="setting"></param>
    public static void ExportDocument(DocumentSetting setting)
    {
        XWPFDocument docx = new XWPFDocument();
        MemoryStream ms   = new MemoryStream();

        //设置文档
        docx.Document.body.sectPr = new CT_SectPr();
        CT_SectPr setPr = docx.Document.body.sectPr;
        //获取页面大小
        Tuple <int, int> size = GetPaperSize(setting.PaperType);

        setPr.pgSz.w = (ulong)size.Item1;
        setPr.pgSz.h = (ulong)size.Item2;
        //创建一个段落
        CT_P p = docx.Document.body.AddNewP();

        //段落水平居中
        p.AddNewPPr().AddNewJc().val = ST_Jc.center;
        XWPFParagraph gp             = new XWPFParagraph(p, docx);

        XWPFRun gr = gp.CreateRun();

        //创建标题
        if (!string.IsNullOrEmpty(setting.TitleSetting.Title))
        {
            gr.GetCTR().AddNewRPr().AddNewRFonts().ascii    = setting.TitleSetting.FontName;
            gr.GetCTR().AddNewRPr().AddNewRFonts().eastAsia = setting.TitleSetting.FontName;
            gr.GetCTR().AddNewRPr().AddNewRFonts().hint     = ST_Hint.eastAsia;
            gr.GetCTR().AddNewRPr().AddNewSz().val          = (ulong)setting.TitleSetting.FontSize; //2号字体
            gr.GetCTR().AddNewRPr().AddNewSzCs().val        = (ulong)setting.TitleSetting.FontSize;
            gr.GetCTR().AddNewRPr().AddNewB().val           = setting.TitleSetting.HasBold;         //加粗
            gr.GetCTR().AddNewRPr().AddNewColor().val       = "black";                              //字体颜色
            gr.SetText(setting.TitleSetting.Title);
        }

        //创建文档主要内容
        if (!string.IsNullOrEmpty(setting.MainContentSetting.MainContent))
        {
            p = docx.Document.body.AddNewP();
            p.AddNewPPr().AddNewJc().val = ST_Jc.both;
            gp = new XWPFParagraph(p, docx)
            {
                IndentationFirstLine = 2
            };

            //单倍为默认值(240)不需设置,1.5倍=240X1.5=360,2倍=240X2=480
            p.AddNewPPr().AddNewSpacing().line     = "400";//固定20磅
            p.AddNewPPr().AddNewSpacing().lineRule = ST_LineSpacingRule.exact;

            gr = gp.CreateRun();
            CT_RPr   rpr    = gr.GetCTR().AddNewRPr();
            CT_Fonts rfonts = rpr.AddNewRFonts();
            rfonts.ascii    = setting.MainContentSetting.FontName;
            rfonts.eastAsia = setting.MainContentSetting.FontName;
            rpr.AddNewSz().val   = (ulong)setting.MainContentSetting.FontSize;//5号字体-21
            rpr.AddNewSzCs().val = (ulong)setting.MainContentSetting.FontSize;
            rpr.AddNewB().val    = setting.MainContentSetting.HasBold;

            gr.SetText(setting.MainContentSetting.MainContent);
        }

        //开始写入
        docx.Write(ms);

        using (FileStream fs = new FileStream(setting.SavePath, FileMode.Create, FileAccess.Write))
        {
            byte[] data = ms.ToArray();
            fs.Write(data, 0, data.Length);
            fs.Flush();
        }
        ms.Close();
    }
Example #9
0
        public void SetBold(bool value)
        {
            CT_RPr ctRpr = this.run.IsSetRPr() ? this.run.rPr : this.run.AddNewRPr();

            (ctRpr.IsSetB() ? ctRpr.b : ctRpr.AddNewB()).val = value ? ST_OnOff.True : ST_OnOff.False;
        }