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文檔的基礎示例。spa