文檔首頁>>Aspose中文文檔>>將項目符號或編號添加到 NPOI 中的列表
將項目符號或編號添加到 NPOI 中的列表
Aspose.Words是一種高級Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現(xiàn)和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。
Aspose API支持流行文件格式處理,并允許將各類文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
Aspose.Words
using NPOI.XWPF.UserModel; XWPFDocument doc = new XWPFDocument(); //simple bullet XWPFNumbering numbering = doc.CreateNumbering(); string abstractNumId = numbering.AddAbstractNum(); string numId = numbering.AddNum(abstractNumId); XWPFParagraph p0 = doc.CreateParagraph(); XWPFRun r0 = p0.CreateRun(); r0.SetText("simple bullet"); r0.SetBold(true); r0.FontFamily = "Courier"; r0.FontSize = 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.FontFamily = "Courier"; r1.FontSize =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"); FileStream sw = new FileStream("bullet-sample.docx", FileMode.Create); doc.Write(sw); sw.Close();
點擊復制
NPOI
using Aspose.Words; Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Font.Bold = true; builder.Font.Name = "Courier"; builder.Font.Size = 12; builder.Writeln("simple bullet"); builder.Font.ClearFormatting(); builder.ListFormat.List = doc.Lists.Add(Aspose.Words.Lists.ListTemplate.BulletSquare); builder.Writeln("first, create paragraph and run, set text"); builder.Writeln("second, call XWPFDocument.CreateNumbering() to create numbering"); builder.Writeln("third, add AbstractNum[numbering.AddAbstractNum()] and Num(numbering.AddNum(abstractNumId))"); builder.Writeln("next, call XWPFParagraph.SetNumID(numId) to set paragraph property, CT_P.pPr.numPr"); builder.ListFormat.RemoveNumbers(); builder.InsertBreak(BreakType.ParagraphBreak); //multi level builder.Font.Bold = true; builder.Font.Name = "Courier"; builder.Font.Size = 12; builder.Writeln("multi level bullet"); builder.Font.ClearFormatting(); builder.ListFormat.List = doc.Lists.Add(Aspose.Words.Lists.ListTemplate.BulletSquare); builder.Writeln("first"); builder.ListFormat.ListLevelNumber = 1; builder.Writeln("first-first"); builder.Writeln("first-second"); builder.Writeln("first-third"); builder.ListFormat.List = doc.Lists.Add(Aspose.Words.Lists.ListTemplate.BulletSquare); builder.ListFormat.ListLevelNumber = 0; builder.Writeln("second"); builder.ListFormat.ListLevelNumber = 1; builder.Writeln("second-first"); builder.Writeln("second-second"); builder.Writeln("second-third"); builder.ListFormat.ListLevelNumber = 2; builder.Writeln("second-third-first"); builder.Writeln("second-third-second"); builder.ListFormat.List = doc.Lists.Add(Aspose.Words.Lists.ListTemplate.BulletSquare); builder.ListFormat.ListLevelNumber = 0; builder.Writeln("third"); builder.ListFormat.RemoveNumbers(); doc.Save("bullet-sample.docx");
點擊復制
下載示例代碼