翻譯|使用教程|編輯:李顯亮|2021-08-11 10:18:12.060|閱讀 516 次
概述:本文介紹使用Spire.Doc for Java在Word文檔中添加多級(jí)項(xiàng)目符號(hào)列表和多級(jí)編號(hào)列表的方法。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷售中 >>
相關(guān)鏈接:
Spire.Doc for Java 是一款專業(yè)的Java Word組件,開(kāi)發(fā)人員使用它可以輕松地將Word文檔創(chuàng)建、讀取、編輯、轉(zhuǎn)換和打印等功能集成到自己的Java應(yīng)用程序中。
本文介紹使用Spire.Doc for Java在Word文檔中添加多級(jí)項(xiàng)目符號(hào)列表和多級(jí)編號(hào)列表的方法。可點(diǎn)擊此處下載最新版測(cè)試。
代碼如下:
import com.spire.doc.*; import com.spire.doc.documents.*; public class MultiLevelList { public static void main(String[] args) { //創(chuàng)建一個(gè)Document類的實(shí)例 Document document = new Document(); //添加Section Section sec = document.addSection(); //添加段落 Paragraph paragraph = sec.addParagraph(); paragraph.appendText("Lists"); paragraph.applyStyle(BuiltinStyle.Title); paragraph = sec.addParagraph(); paragraph.appendText("Numbered List: ").getCharacterFormat().setBold(true); //創(chuàng)建編號(hào)列表樣式 ListStyle numberList = new ListStyle(document, ListType.Numbered);//編號(hào)列表 numberList.setName("numberList"); numberList.getLevels().get(1).setNumberPrefix("\u0000."); numberList.getLevels().get(1).setPatternType(ListPatternType.Arabic); numberList.getLevels().get(2).setNumberPrefix("\u0000.\u0001."); numberList.getLevels().get(2).setPatternType(ListPatternType.Arabic); //創(chuàng)建符號(hào)列表樣式 ListStyle bulletList= new ListStyle(document, ListType.Bulleted);//符號(hào)列表 bulletList.setName("bulletList"); //添加列表樣式 document.getListStyles().add(numberList); document.getListStyles().add(bulletList); //添加段落并應(yīng)用列表樣式 paragraph = sec.addParagraph(); paragraph.appendText("List Item 1"); paragraph.getListFormat().applyStyle(numberList.getName()); paragraph = sec.addParagraph(); paragraph.appendText("List Item 2"); paragraph.getListFormat().applyStyle(numberList.getName()); paragraph = sec.addParagraph(); paragraph.appendText("List Item 2.1"); paragraph.getListFormat().applyStyle(numberList.getName()); paragraph.getListFormat().setListLevelNumber(1); paragraph = sec.addParagraph(); paragraph.appendText("List Item 2.2"); paragraph.getListFormat().applyStyle(numberList.getName()); paragraph.getListFormat().setListLevelNumber(1); paragraph = sec.addParagraph(); paragraph.appendText("List Item 2.2.1"); paragraph.getListFormat().applyStyle(numberList.getName()); paragraph.getListFormat().setListLevelNumber(2); paragraph = sec.addParagraph(); paragraph.appendText("List Item 2.2.2"); paragraph.getListFormat().applyStyle(numberList.getName()); paragraph.getListFormat().setListLevelNumber(2); paragraph = sec.addParagraph(); paragraph.appendText("List Item 2.2.3"); paragraph.getListFormat().applyStyle(numberList.getName()); paragraph.getListFormat().setListLevelNumber(2); paragraph = sec.addParagraph(); paragraph.appendText("List Item 2.3"); paragraph.getListFormat().applyStyle(numberList.getName()); paragraph.getListFormat().setListLevelNumber(1); paragraph = sec.addParagraph(); paragraph.appendText("List Item 3"); paragraph.getListFormat().applyStyle(numberList.getName()); paragraph = sec.addParagraph(); paragraph.appendText("Bulleted List:").getCharacterFormat().setBold(true); paragraph = sec.addParagraph(); paragraph.appendText("List Item 1"); paragraph.getListFormat().applyStyle(bulletList.getName()); paragraph = sec.addParagraph(); paragraph.appendText("List Item 2"); paragraph.getListFormat().applyStyle(bulletList.getName()); paragraph = sec.addParagraph(); paragraph.appendText("List Item 2.1"); paragraph.getListFormat().applyStyle(bulletList.getName()); paragraph.getListFormat().setListLevelNumber(1); paragraph = sec.addParagraph(); paragraph.appendText("List Item 2.2"); paragraph.getListFormat().applyStyle(bulletList.getName()); paragraph.getListFormat().setListLevelNumber(1); paragraph = sec.addParagraph(); paragraph.appendText("List Item 3"); paragraph.getListFormat().applyStyle(bulletList.getName()); //保存文檔 document.saveToFile("MultiLevelList.docx", FileFormat.Docx); document.dispose(); } }
多級(jí)列表效果:
Spire.Doc for Java 4.8.0已發(fā)布。該版本支持檢測(cè)文檔是否被加密,增強(qiáng)了轉(zhuǎn)換Word到PDF/HTML/SVG、HTML到Word、以及WPS到PDF的功能。此外,本次更新還修復(fù)了加載和比較Word文檔時(shí)出現(xiàn)的問(wèn)題。
整合所有格式API處理套包Spire.office for Java正在慧都網(wǎng)火熱銷售中!立馬1分鐘了解全部咨詢!
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn