利用npoi生成word

需要下载npoi

添加引用文件:NPOI.OOXML.dll   和  NPOI.dll

 static void Main(string[] args)
        {
            //创建document对象
            XWPFDocument doc = new XWPFDocument();


            //创建段落对象
            XWPFParagraph p1 = doc.CreateParagraph();
            //段落对其方式为居中
            p1.Alignment = ParagraphAlignment.CENTER;
            XWPFRun r1 = p1.CreateRun();//段落中添加文字
            r1.FontSize = 22;//设置大小
            r1.FontFamily = "宋体"; //设置字体
            r1.SetText("段落一");


            XWPFParagraph p2 = doc.CreateParagraph();
            //段落对其方式为居中
            p2.Alignment = ParagraphAlignment.RIGHT;
            XWPFRun r2 = p2.CreateRun();//向该段落中添加文字
            r2.FontSize = 15;//设置大小
            r2.FontFamily = "宋体"; //设置字体
            r2.SetText("段落二");


            string filePath ="C://Users//Administrator//Desktop//dotnet2//";;
            FileStream out1 = new FileStream(filePath+"simpleTable.docx", FileMode.Create);
            doc.Write(out1);
            out1.Close();
        }


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值