当前位置: 首页>>代码示例>>C#>>正文


C# XWPFDocument.CreateParagraph方法代码示例

本文整理汇总了C#中NPOI.XWPF.UserModel.XWPFDocument.CreateParagraph方法的典型用法代码示例。如果您正苦于以下问题:C# XWPFDocument.CreateParagraph方法的具体用法?C# XWPFDocument.CreateParagraph怎么用?C# XWPFDocument.CreateParagraph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NPOI.XWPF.UserModel.XWPFDocument的用法示例。


在下文中一共展示了XWPFDocument.CreateParagraph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            XWPFDocument doc = new XWPFDocument();
            XWPFParagraph para= doc.CreateParagraph();
            XWPFRun r0 = para.CreateRun();
            r0.SetText("Title1");
            para.BorderTop = Borders.THICK;
            para.FillBackgroundColor = "EEEEEE";
            para.FillPattern = NPOI.OpenXmlFormats.Wordprocessing.ST_Shd.diagStripe;

            XWPFTable table = doc.CreateTable(3, 3);

            table.GetRow(1).GetCell(1).SetText("EXAMPLE OF TABLE");

            XWPFTableCell c1 = table.GetRow(0).GetCell(0);
            XWPFParagraph p1 = c1.AddParagraph();   //don't use doc.CreateParagraph
            XWPFRun r1 = p1.CreateRun();
            r1.SetText("The quick brown fox");
            r1.SetBold(true);

            r1.FontFamily = "Courier";
            r1.SetUnderline(UnderlinePatterns.DotDotDash);
            r1.SetTextPosition(100);
            c1.SetColor("FF0000");
            

            table.GetRow(2).GetCell(2).SetText("only text");

            FileStream out1 = new FileStream("simpleTable.docx", FileMode.Create);
            doc.Write(out1);
            out1.Close();
        }
开发者ID:JustinChangTW,项目名称:npoi,代码行数:32,代码来源:Program.cs

示例2: Bug55802

        public void Bug55802()
        {
            String blabla =
                "Bir, iki, \u00fc\u00e7, d\u00f6rt, be\u015f,\n" +
                "\nalt\u0131, yedi, sekiz, dokuz, on.\n" +
                "\nK\u0131rm\u0131z\u0131 don,\n" +
                "\ngel bizim bah\u00e7eye kon,\n" +
                "\nsar\u0131 limon";
            XWPFDocument doc = new XWPFDocument();
            XWPFRun run = doc.CreateParagraph().CreateRun();

            foreach (String str in blabla.Split("\n".ToCharArray()))
            {
                run.SetText(str);
                run.AddBreak();
            }

            run.FontFamily = (/*setter*/"Times New Roman");
            run.FontSize = (/*setter*/20);
            Assert.AreEqual(run.FontFamily, "Times New Roman");
            Assert.AreEqual(run.GetFontFamily(FontCharRange.CS), "Times New Roman");
            Assert.AreEqual(run.GetFontFamily(FontCharRange.EastAsia), "Times New Roman");
            Assert.AreEqual(run.GetFontFamily(FontCharRange.HAnsi), "Times New Roman");
            run.SetFontFamily("Arial", FontCharRange.HAnsi);
            Assert.AreEqual(run.GetFontFamily(FontCharRange.HAnsi), "Arial");
        }
开发者ID:eatage,项目名称:npoi,代码行数:26,代码来源:TestXWPFBugs.cs

示例3: SetUp

        public void SetUp()
        {
            XWPFDocument doc = new XWPFDocument();
            p = doc.CreateParagraph();

            this.ctRun = new CT_R();
        }
开发者ID:hanwangkun,项目名称:npoi,代码行数:7,代码来源:TestXWPFRun.cs

示例4: Main

 static void Main(string[] args)
 {
     XWPFDocument doc = new XWPFDocument();
     doc.CreateParagraph();
     using (FileStream sw = File.Create("blank.docx"))
     {
         doc.Write(sw);
     }
 }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:9,代码来源:Program.cs

示例5: Main

 static void Main(string[] args)
 {
     XWPFDocument doc = new XWPFDocument();
     doc.CreateParagraph();
     FileStream sw = File.OpenWrite("blank.docx");
     doc.Write(sw);
     sw.Close();
 }
开发者ID:xoposhiy,项目名称:npoi,代码行数:8,代码来源:Program.cs

示例6: NPOIWord

        static void NPOIWord()
        {
            // Word的单元是段落,所以我们在空文件中创建一个新的段落
            XWPFDocument doc = new XWPFDocument();
            XWPFParagraph ph = doc.CreateParagraph();
            ph.Alignment = ParagraphAlignment.CENTER;
            ph.BorderBottom = Borders.DOUBLE;
            ph.BorderTop = Borders.DOUBLE;
            ph.BorderRight = Borders.DOUBLE;
            ph.BorderLeft = Borders.DOUBLE;

            XWPFRun run = ph.CreateRun();
            run.SetBold(true);
            run.SetText("你这是在自寻死路");
            // 可以设置paragraph中文本的样式,包括字体,大小,粗细已经删除线等。
            // 此处都是基于XWPFRun来进行设置的,但是注意paragraph中的段落对齐方式是在
            // XWPFParagraph中设置的。
            run.FontFamily = "仿宋";
            run.FontSize = 20;
            run.IsItalic = true;
            run.SetStrike(true);

            // 在Word中创建表格
            XWPFTable table = doc.CreateTable(3, 3);
            table.GetRow(1).GetCell(1).SetText("Example of table");
            // 可以把单元格的内容设置为paragraph实例
            XWPFParagraph pCha = doc.CreateParagraph();
            
            // 注意文本的样式都是基于XWPFRun来进行设置的,除了段落的对齐方式,是paragraph为基准进行设置的
            XWPFRun r1 = pCha.CreateRun();
            r1.SetBold(true);
            r1.FontSize = 15;
            r1.SetText("The quick brown fox1");
            r1.FontFamily = "Courier";
            r1.SetUnderline(UnderlinePatterns.DotDotDash);
            r1.SetTextPosition(100);
            table.GetRow(0).GetCell(0).SetParagraph(pCha);

            table.GetRow(2).GetCell(2).SetText("Only Text");

            FileStream fs = File.Create(@"D:\blank.docx");
            pCha.AddRun(r1);
            doc.Write(fs);
            fs.Close();
        }
开发者ID:ZLLselfRedeem,项目名称:zllinmitu,代码行数:45,代码来源:Program.cs

示例7: SetHeadings

        private void SetHeadings(ref XWPFDocument doc, XWPFTable table)
        {
            XWPFParagraph p1 = doc.CreateParagraph();
            XWPFRun r1 = p1.CreateRun();
            r1.SetBold(true);
            r1.SetText("Category");
            r1.SetBold(true);
            r1.SetFontFamily("Courier");
            table.GetRow(0).GetCell(0).SetParagraph(p1);

            XWPFParagraph p2 = doc.CreateParagraph();
            XWPFRun r2 = p2.CreateRun();
            r2.SetBold(true);
            r2.SetText("Category");
            r2.SetBold(true);
            r2.SetFontFamily("Courier");
            table.GetRow(0).GetCell(1).SetParagraph(p2);


        }
开发者ID:yuyi1,项目名称:Verdezyne-Operations,代码行数:20,代码来源:FermentationOutlineTable.cs

示例8: integration

        public void integration()
        {
            XWPFDocument doc = new XWPFDocument();

            XWPFParagraph p1 = doc.CreateParagraph();

            XWPFRun r1 = p1.CreateRun();
            r1.SetText("Lorem ipsum dolor sit amet.");
            doc.IsTrackRevisions = (true);

            MemoryStream out1 = new MemoryStream();
            doc.Write(out1);

            MemoryStream inputStream = new MemoryStream(out1.ToArray());
            XWPFDocument document = new XWPFDocument(inputStream);
            inputStream.Close();

            Assert.IsTrue(document.IsTrackRevisions);
        }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:19,代码来源:TestChangeTracking.cs

示例9: Main

        static void Main(string[] args)
        {
            XWPFDocument doc = new XWPFDocument();
            XWPFParagraph p2 = doc.CreateParagraph();
            XWPFRun r2 = p2.CreateRun();
            r2.SetText("test");


            var widthEmus = (int)(400.0 * 9525);
            var heightEmus = (int)(300.0 * 9525);

            using (FileStream picData = new FileStream("../../image/HumpbackWhale.jpg", FileMode.Open, FileAccess.Read))
            {
                r2.AddPicture(picData, (int)PictureType.PNG, "image1", widthEmus, heightEmus);
            }
            using (FileStream sw = File.Create("test.docx"))
            {
                doc.Write(sw);
            }
        }
开发者ID:89sos98,项目名称:npoi,代码行数:20,代码来源:Program.cs

示例10: TestIntegration

        public void TestIntegration()
        {
            XWPFDocument doc = new XWPFDocument();

            XWPFParagraph p1 = doc.CreateParagraph();

            XWPFRun r1 = p1.CreateRun();
            r1.SetText("Lorem ipsum dolor sit amet.");
            doc.EnforceCommentsProtection();

            FileInfo tempFile = TempFile.CreateTempFile("documentProtectionFile", ".docx");
            if (File.Exists(tempFile.FullName))
                File.Delete(tempFile.FullName);
            Stream out1 = new FileStream(tempFile.FullName, FileMode.CreateNew);

            doc.Write(out1);
            out1.Close();

            FileStream inputStream = new FileStream(tempFile.FullName, FileMode.Open);
            XWPFDocument document = new XWPFDocument(inputStream);
            inputStream.Close();

            Assert.IsTrue(document.IsEnforcedCommentsProtection());
        }
开发者ID:ctddjyds,项目名称:npoi,代码行数:24,代码来源:TestDocumentProtection.cs

示例11: SimpleDocument

        public bool SimpleDocument(string filepath)
        {
            XWPFDocument doc = new XWPFDocument();
            try
            {
                XWPFParagraph p1 = doc.CreateParagraph();
                p1.SetAlignment(ParagraphAlignment.CENTER);
                p1.SetBorderBottom(Borders.DOUBLE);
                p1.SetBorderTop(Borders.DOUBLE);


                p1.SetBorderRight(Borders.DOUBLE);
                p1.SetBorderLeft(Borders.DOUBLE);
                p1.SetBorderBetween(Borders.SINGLE);


                p1.SetVerticalAlignment(TextAlignment.TOP);


                XWPFRun r1 = p1.CreateRun();
                r1.SetBold(true);
                r1.SetText("The quick brown fox");
                r1.SetBold(true);
                r1.SetFontFamily("Courier");
                r1.SetUnderline(UnderlinePatterns.DotDotDash);
                r1.SetTextPosition(100);


                XWPFParagraph p2 = doc.CreateParagraph();
                p2.SetAlignment(ParagraphAlignment.RIGHT);


                //BORDERS
                p2.SetBorderBottom(Borders.DOUBLE);
                p2.SetBorderTop(Borders.DOUBLE);
                p2.SetBorderRight(Borders.DOUBLE);
                p2.SetBorderLeft(Borders.DOUBLE);
                p2.SetBorderBetween(Borders.SINGLE);


                XWPFRun r2 = p2.CreateRun();
                r2.SetText("jumped over the lazy dog");
                r2.SetStrike(true);
                r2.SetFontSize(20);


                XWPFRun r3 = p2.CreateRun();
                r3.SetText("and went away");
                r3.SetStrike(true);
                r3.SetFontSize(20);
                r3.SetSubscript(VerticalAlign.SUPERSCRIPT);




                XWPFParagraph p3 = doc.CreateParagraph();


                p3.SetPageBreak(true);


                //p3.SetAlignment(ParagraphAlignment.DISTRIBUTE);
                p3.SetAlignment(ParagraphAlignment.BOTH);
                p3.SetSpacingLineRule(LineSpacingRule.EXACT);

                p3.IndentationFirstLine = 600;
                //p3.IndentationFirstLine(600);




                XWPFRun r4 = p3.CreateRun();
                r4.SetTextPosition(20);
                r4.SetText("To be, or not to be: that is the question: "
                        + "Whether 'tis nobler in the mind to suffer "
                        + "The slings and arrows of outrageous fortune, "
                        + "Or to take arms against a sea of troubles, "
                        + "And by opposing end them? To die: to sleep; ");
                r4.AddBreak(BreakType.PAGE);
                r4.SetText("No more; and by a sleep to say we end "
                        + "The heart-ache and the thousand natural shocks "
                        + "That flesh is heir to, 'tis a consummation "
                        + "Devoutly to be wish'd. To die, to sleep; "
                        + "To sleep: perchance to dream: ay, there's the rub; "
                        + ".......");

                //r4.SetItalic(true);
                //This would imply that this break shall be treated as a simple line break, and break the line after that word:


                XWPFRun r5 = p3.CreateRun();
                r5.SetTextPosition(-10);
                r5.SetText("For in that sleep of death what dreams may come");
                r5.AddCarriageReturn();
                r5.SetText("When we have shuffled off this mortal coil,"
                        + "Must give us pause: there's the respect"
                        + "That makes calamity of so long life;");
                r5.AddBreak();
                r5.SetText("For who would bear the whips and scorns of time,"
                        + "The oppressor's wrong, the proud man's contumely,");
//.........这里部分代码省略.........
开发者ID:yuyi1,项目名称:Verdezyne-Operations,代码行数:101,代码来源:DocxWriter.cs

示例12: CreateContractCheckResult

        public static void CreateContractCheckResult(string fileName, Model.ContractCheckResult result)
        {
            XWPFDocument doc = new XWPFDocument();
            XWPFParagraph pTitle = doc.CreateParagraph();
            pTitle.Alignment = ParagraphAlignment.CENTER;
            XWPFRun rText = pTitle.CreateRun();
            rText.IsBold = true;
            rText.FontSize = 18;
            rText.SetText("客户管理系统合同数据检查结果报告");

            XWPFParagraph pDesc = doc.CreateParagraph();
            pDesc.Alignment = ParagraphAlignment.RIGHT;
            rText = pDesc.CreateRun();
            rText.IsBold = false;
            rText.SetColor("#ff0000");
            rText.FontSize = 8;
            rText.SetText("*本报告仅供参考,实际结果以客户管理系统为准");
            XWPFParagraph pContent = doc.CreateParagraph();
            pContent.Alignment = ParagraphAlignment.BOTH;
            rText = pContent.CreateRun();
            rText.IsBold = true;
            rText.SetText("一、合同概况:");

            if (!string.IsNullOrEmpty(result.ContractSurvey))
            {
                string[] strList = result.ContractSurvey.Split(new char[] { '$' });
                foreach (string item in strList)
                {
                    pContent = doc.CreateParagraph();
                    rText = pContent.CreateRun();
                    rText.SetText("        " + item);
                }
            }

            pContent = doc.CreateParagraph();
            pContent.Alignment = ParagraphAlignment.BOTH;
            rText = pContent.CreateRun();
            rText.IsBold = true;
            rText.SetText("二、检查结果:");

            pContent = doc.CreateParagraph();
            rText = pContent.CreateRun();
            rText.SetText("        " + result.CheckResult);

            pContent = doc.CreateParagraph();
            pContent.Alignment = ParagraphAlignment.BOTH;
            rText = pContent.CreateRun();
            rText.IsBold = true;
            rText.SetText("三、检查规则:");

            if (!string.IsNullOrEmpty(result.CheckRule))
            {
                string[] strList = result.CheckRule.Split(new char[] { '$' });
                foreach (string item in strList)
                {
                    pContent = doc.CreateParagraph();
                    rText = pContent.CreateRun();
                    rText.SetText("        " + item);
                }
            }

            FileStream sw = File.Create(fileName);
            doc.Write(sw);
            sw.Close();
            try
            {
                Microsoft.Office.Interop.Word.Application wordApplication = new Microsoft.Office.Interop.Word.Application();
                Microsoft.Office.Interop.Word.Document wordDocument = new Microsoft.Office.Interop.Word.Document();
                Object nothing = System.Reflection.Missing.Value;
                Object filePath = fileName;
                wordApplication.Documents.Open(ref filePath, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref nothing, ref   nothing, ref   nothing, ref   nothing, ref   nothing, ref  nothing, ref   nothing, ref   nothing);
                wordDocument = wordApplication.ActiveDocument;
                wordApplication.Visible = true;
            }
            catch { }
        }
开发者ID:AllanHao,项目名称:MotivationManager,代码行数:76,代码来源:WordController.cs

示例13: word_insert_space

 /*
  *插入空行函数
  *@n 插入的行数
  *@m_Docx 根文档
  *@longth 空行高
  */
 private static void word_insert_space(int n, XWPFDocument m_Docx, int longth = 250)
 {
     for (int i = 0; i < n; i++)
     {
         XWPFParagraph gp_space = m_Docx.CreateParagraph(); //创建XWPFParagraph
         gp_space.SetAlignment(ParagraphAlignment.CENTER);
         gp_space.SetSpacingBefore(longth);
         gp_space.SpacingAfter = longth;
     }
 }
开发者ID:ssthouse,项目名称:NpoiTest,代码行数:16,代码来源:WordGenerator.cs

示例14: TestRuns

        public void TestRuns()
        {
            XWPFDocument doc = new XWPFDocument();
            XWPFParagraph p = doc.CreateParagraph();

            CT_R run = new CT_R();
            XWPFRun r = new XWPFRun(run, doc.CreateParagraph());
            p.AddRun(r);
            p.AddRun(r);

            Assert.IsNotNull(p.GetRun(run));
            Assert.IsNull(p.GetRun(null));
        }
开发者ID:newlysoft,项目名称:npoi,代码行数:13,代码来源:TestXWPFParagraph.cs

示例15: TestSearchTextNotFound

        public void TestSearchTextNotFound()
        {
            XWPFDocument doc = new XWPFDocument();
            XWPFParagraph p = doc.CreateParagraph();

            Assert.IsNull(p.SearchText("test", new PositionInParagraph()));
            Assert.AreEqual("", p.Text);
        }
开发者ID:newlysoft,项目名称:npoi,代码行数:8,代码来源:TestXWPFParagraph.cs


注:本文中的NPOI.XWPF.UserModel.XWPFDocument.CreateParagraph方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。