NPOI 2 Create Bullet

using System;
using NPOI.XWPF.UserModel;
using System.IO;

namespace Project1
{
	/// <summary>
	/// Word  Bullet 列表项
	/// </summary>
	public class CreateBullet
	{
		public CreateBullet ()
		{
		}

		public static void DoAction()
		{
			//创建word对象
			XWPFDocument doc = new XWPFDocument ();

			XWPFNumbering numbering = doc.CreateNumbering ();

			//从0开始自增,步长为1
			string abstractNumId = numbering.AddAbstractNum();
			//从1开始自增,步长为1
			string numId = numbering.AddNum (abstractNumId);
			
			//段落
			XWPFParagraph p0 = doc.CreateParagraph ();
			XWPFRun r0 = p0.CreateRun ();
			r0.SetText("简单的Bullet");
			r0.SetBold(true);
			r0.SetFontFamily("Courier");
			r0.SetFontSize(12);

			XWPFParagraph p1 = doc.CreateParagraph();
			XWPFRun r1 = p1.CreateRun();
			r1.SetText("first, create paragraph and run, set text");
			p1.SetNumID(numId);
			
			XWPFParagraph p2 = doc.CreateParagraph();
			XWPFRun r2 = p2.CreateRun();
			r2.SetText("second, call XWPFDocument.CreateNumbering() to create numbering");
			p2.SetNumID(numId);
			
			XWPFParagraph p3 = doc.CreateParagraph();
			XWPFRun r3 = p3.CreateRun();
			r3.SetText("third, add AbstractNum[numbering.AddAbstractNum()] and Num(numbering.AddNum(abstractNumId))");
			p3.SetNumID(numId);
			
			XWPFParagraph p4 = doc.CreateParagraph();
			XWPFRun r4 = p4.CreateRun();
			r4.SetText("next, call XWPFParagraph.SetNumID(numId) to set paragraph property, CT_P.pPr.numPr");
			p4.SetNumID(numId);
			
			//multi level
			abstractNumId = numbering.AddAbstractNum();
			numId = numbering.AddNum(abstractNumId);
			
			doc.CreateParagraph();
			doc.CreateParagraph();
			
			p1 = doc.CreateParagraph();
			r1 = p1.CreateRun();
			r1.SetText("multi level bullet");
			r1.SetBold(true);
			r1.SetFontFamily("Courier");
			r1.SetFontSize(12);
			
			p1 = doc.CreateParagraph();
			r1 = p1.CreateRun();
			r1.SetText("first");
			p1.SetNumID(numId, "0");
			p1 = doc.CreateParagraph();
			r1 = p1.CreateRun();
			r1.SetText("first-first");
			p1.SetNumID(numId, "1");
			p1 = doc.CreateParagraph();
			r1 = p1.CreateRun();
			r1.SetText("first-second");
			p1.SetNumID(numId, "1");
			p1 = doc.CreateParagraph();
			r1 = p1.CreateRun();
			r1.SetText("first-third");
			p1.SetNumID(numId, "1");
			p1 = doc.CreateParagraph();
			r1 = p1.CreateRun();
			r1.SetText("second");
			p1.SetNumID(numId, "0");
			p1 = doc.CreateParagraph();
			r1 = p1.CreateRun();
			r1.SetText("second-first");
			p1.SetNumID(numId, "1");
			p1 = doc.CreateParagraph();
			r1 = p1.CreateRun();
			r1.SetText("second-second");
			p1.SetNumID(numId, "1");
			p1 = doc.CreateParagraph();
			r1 = p1.CreateRun();
			r1.SetText("second-third");
			p1.SetNumID(numId, "1");
			p1 = doc.CreateParagraph();
			r1 = p1.CreateRun();
			r1.SetText("second-third-first");
			p1.SetNumID(numId, "2");
			p1 = doc.CreateParagraph();
			r1 = p1.CreateRun();
			r1.SetText("second-third-second");
			p1.SetNumID(numId, "2");
			p1 = doc.CreateParagraph();
			r1 = p1.CreateRun();
			r1.SetText("third");
			p1.SetNumID(numId, "0");

			Stream stream = new FileStream ("createbullet.docx", FileMode.OpenOrCreate);

			doc.Write (stream);
			stream.Close ();
			
			Console.WriteLine ("创建完毕");
		}

	}
}

点击查看原图

知识共享许可协议
《NPOI 2 Create Bullet》常伟华 创作。
采用 知识共享 署名-相同方式共享 3.0 中国大陆 许可协议进行许可。
相邻依据:发表时间
  • 多说评论
  • 签名
  • 新浪微博
  • 默认评论
  • Tab Header 5

0 条评论 / 点击此处发表评论

Tab Content 5

开发技术


开发平台和工具

sitemap     156.27ms