1 XWPFDocument doc = new XWPFDocument(); 2 XWPFParagraph p0 = doc.CreateParagraph(); 3 p0.Alignment = ParagraphAlignment.LEFT; 4 5 XWPFRun r0 = p0.CreateRun(); 6 r0.FontFamily = "宋体"; 7 r0.FontSize = 18; 8 r0.IsBold = true; 9 r0.SetText("未登录过学生的账号密码"); 10 11 XWPFTable table = doc.CreateTable(4, 4); 12 table.Width = 1600;//设置表格宽度 13 table.SetColumnWidth(0, 800); 14 15 16 XWPFParagraph pIO = table.GetRow(0).GetCell(0).Paragraphs[0]; //获取第0行第0列的文本框 17 XWPFRun rIO = pIO.CreateRun();//创建编辑 18 rIO.FontFamily = "微软雅黑"; 19 rIO.FontSize = 12; 20 rIO.IsBold = true; 21 rIO.SetText("0");//复制 22 23 24 25 FileStream out1 = new FileStream("simpleTable.docx", FileMode.Create);//输出到默认位置 26 doc.Write(out1); 27 out1.Close();
以上为通过NPOI导出Word文档的基础示例。
时间: 2024-10-11 04:48:57