正確地組織信息可以幫助你寫出更好的筆記。列表是結構化內容的最簡單方法之一。無論你是在制定計劃、創建待辦事項,還是快速記下要點,OneNote 中的項目符號和編號列表都能使一切變得更加清晰。在本指南中,你將學習如何使用 Java 在 OneNote 中創建項目符號列表或編號列表。我們將通過逐步的代碼示例來幫助你輕鬆實現這項技術。

這篇文章涵蓋以下主題:

Java SDK 以在 OneNote 中創建項目符號或編號列表

我們將使用 Aspose.Note for Java 來處理 OneNote 文件。它支持以編程方式讀取、寫入、編輯和轉換 .one 文件。

您可以通過 Maven 將其添加到您的項目中。以下是方法:

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-note</artifactId>
    <version>25.6</version>
    <classifier>jdk17</classifier> <!-- Or jdk18/jdk21 depending on your Java version -->
</dependency>

或從 releases 下載它。

如何在 OneNote 中使用 Java 創建項目符號列表

您可以按照以下步驟建立簡單的項目符號列表:

  1. 創建一個新的 Document 類別物件。
  2. 新增一個 Page
  3. 建立一個 Outline 並添加 OutlineElement 類別物件。
  4. 使用類似 \"\"\"•\" 的項目符號作為每個項目的前綴。
  5. 使用 RichText 來樣式化您的文本。
  6. 將所有內容加在一起並保存文檔。
// 創建 Document 類的物件
Document doc = new Document();

// 初始化 Page 類別物件
Page page = new Page();

// 初始化 Outline 類別物件
Outline outline = new Outline();

// 初始化 TextStyle 類別物件並設定格式化屬性
ParagraphStyle defaultStyle = new ParagraphStyle()
                  .setFontColor(Color.black)
                  .setFontName("Arial")
                  .setFontSize(10);

// 初始化 OutlineElement 類別物件並應用項目符號
OutlineElement outlineElem1 = new OutlineElement();
outlineElem1.setNumberList(new NumberList("*", "Arial", 10));

// 初始化 RichText 類別物件並應用文字樣式
RichText text1 = new RichText().append("First");
text1.setParagraphStyle(defaultStyle);
outlineElem1.appendChildLast(text1);

OutlineElement outlineElem2 = new OutlineElement();
outlineElem2.setNumberList(new NumberList("*", "Arial", 10));

RichText text2 = new RichText().append("Second");
text2.setParagraphStyle(defaultStyle);
outlineElem2.appendChildLast(text2);

OutlineElement outlineElem3 = new OutlineElement();
outlineElem3.setNumberList(new NumberList("*", "Arial", 10));
RichText text3 = new RichText().append("Third");
text3.setParagraphStyle(defaultStyle);
outlineElem3.appendChildLast(text3);

// 添加大綱元素
outline.appendChildLast(outlineElem1);
outline.appendChildLast(outlineElem2);
outline.appendChildLast(outlineElem3);

// 添加大綱節點
page.appendChildLast(outline);

// add Page node
doc.appendChildLast(page);

// save the document
doc.save("ApplyBulletsOnText.one");
如何在 OneNote 中使用 Java 創建項目符號列表

如何在 OneNote 中使用 Java 創建項目符號列表

在 OneNote 中使用 Java 創建編號列表

對於編號列表,只需將每行的前綴更改為包含數字(1.2. 等),並使用 NumberFormat.DecimalNumbers 來定義數字格式。

// 創建 Document 類別的物件
Document doc = new Document();

// 初始化 Page 類別物件
Page page = new Page();

// 初始化 Outline 類別物件
Outline outline = new Outline();

// 初始化 TextStyle 類別物件並設置格式化屬性
ParagraphStyle defaultStyle = new ParagraphStyle()
                    .setFontColor(Color.black)
                    .setFontName("Arial")
                    .setFontSize(10);

// 初始化 OutlineElement 類別物件並應用編號
// 相同大綱中的編號會自動遞增。
OutlineElement outlineElem1 = new OutlineElement();

outlineElem1.setNumberList(new NumberList("{0})", NumberFormat.DecimalNumbers, "Arial", 10));

RichText text1 = new RichText().append("First");
text1.setParagraphStyle(defaultStyle);
outlineElem1.appendChildLast(text1);

OutlineElement outlineElem2 = new OutlineElement();
outlineElem2.setNumberList(new NumberList("{0})", NumberFormat.DecimalNumbers, "Arial", 10));
RichText text2 = new RichText().append("Second");
text2.setParagraphStyle(defaultStyle);
outlineElem2.appendChildLast(text2);

OutlineElement outlineElem3 = new OutlineElement();
outlineElem3.setNumberList(new NumberList("{0})", NumberFormat.DecimalNumbers, "Arial", 10));
RichText text3 = new RichText().append("Third");
text3.setParagraphStyle(defaultStyle);
outlineElem3.appendChildLast(text3);

// 添加大綱元素
outline.appendChildLast(outlineElem1);
outline.appendChildLast(outlineElem2);
outline.appendChildLast(outlineElem3);

// 新增大綱節點
page.appendChildLast(outline);

// 添加頁面節點
doc.appendChildLast(page);

// 保存文件
doc.save("ApplyNumberingOnText.one");
在 OneNote 中使用 Java 創建編號列表

在 OneNote 中使用 Java 創建編號列表

插入中文編號列表

Aspose.Note for Java 也支援各種數字格式。要創建中文風格的編號列表,您可以相應地自定義文本格式,並使用 NumberFormat.ChineseCounting 來定義中文數字格式。

// 創建 Document 類的物件
Document doc = new Document();

// 初始化 Page 類別物件
Page page = new Page();

// 初始化 Outline 類別物件
Outline outline = new Outline();

// 初始化 TextStyle 類別物件並設置格式化屬性
ParagraphStyle defaultStyle = new ParagraphStyle()
                  .setFontColor(Color.black)
                  .setFontName("Arial")
                  .setFontSize(10);

// 初始化 OutlineElement 類別物件並應用編號
// 同一大綱中的編號會自動增長。
OutlineElement outlineElem1 = new OutlineElement();

outlineElem1.setNumberList(new NumberList("{0})", NumberFormat.ChineseCounting, "Arial", 10));

RichText text1 = new RichText().append("First");
text1.setParagraphStyle(defaultStyle);
outlineElem1.appendChildLast(text1);

OutlineElement outlineElem2 = new OutlineElement();
outlineElem2.setNumberList(new NumberList("{0})", NumberFormat.ChineseCounting, "Arial", 10));
RichText text2 = new RichText().append("Second");
text2.setParagraphStyle(defaultStyle);
outlineElem2.appendChildLast(text2);

OutlineElement outlineElem3 = new OutlineElement();
outlineElem3.setNumberList(new NumberList("{0})", NumberFormat.ChineseCounting, "Arial", 10));
RichText text3 = new RichText().append("Third");
text3.setParagraphStyle(defaultStyle);
outlineElem3.appendChildLast(text3);

// 添加大綱元素
outline.appendChildLast(outlineElem1);
outline.appendChildLast(outlineElem2);
outline.appendChildLast(outlineElem3);

// 添加大綱節點
page.appendChildLast(outline);

// add Page node
doc.appendChildLast(page);

// save the document
doc.save("ChineseNumberList.one");
在 OneNote 中插入一個中文數字列表

將中文數字列表插入 OneNote 中

獲取免費臨時許可證

想要無限制地嘗試 Aspose.Note 嗎?您可以 request a free temporary license 以評估所有功能,無水印或限制。

在 OneNote 中處理清單的有用資源

無論您是使用 Java 在 OneNote 中創建項目符號或編號列表,以下資源將幫助您入門並更深入了解:

這些資源是您實施結構化、專業記錄筆記的首選指南,使用 Java。

結論

使用 Aspose.Note for Java,您可以輕鬆在 OneNote 文件中創建結構化列表。無論是項目符號還是數字,您都可以完全控制格式和內容。如果您正在自動生成筆記、建立知識庫或在應用程序中集成筆記,這可能會大大提高生產力。

如果您有任何問題或需要進一步的協助,請隨時在我們的 free support forum 聯繫我們。

See Also