Class Body

java.lang.Object
io.leandev.appfuse.document.Body
Direct Known Subclasses:
TableCell

public class Body extends Object

內容容器(共用編輯面)

Word 的文件本文、頁首、頁尾、表格儲存格在 OOXML 中都是「IBody 容器」, 因此共用同一組操作:段落/表格的列舉、附加、樣板複製、定位(locator)與文字取代。 Document.body()Document.header()Document.footer() 皆回傳 BodyTableCell 繼承自 Body

Since:
4.0.0
  • Method Details

    • paragraphs

      public List<Paragraph> paragraphs()
      取得所有段落
      Returns:
      段落列表
    • tables

      public List<Table> tables()
      取得所有表格
      Returns:
      表格列表
    • appendParagraph

      public Paragraph appendParagraph()
      在容器末端附加空段落
      Returns:
      新段落
    • appendParagraph

      public Paragraph appendParagraph(String text)
      在容器末端附加段落
      Parameters:
      text - 文字
      Returns:
      新段落
    • appendParagraph

      public Paragraph appendParagraph(String text, String styleName)
      在容器末端附加段落並套用樣板樣式
      Parameters:
      text - 文字
      styleName - 樣式名稱(樣板定義的 style ID)
      Returns:
      新段落
    • appendTable

      public Table appendTable(int rows, int cols)
      在容器末端附加表格
      Parameters:
      rows - 列數
      cols - 欄數
      Returns:
      新表格
    • appendCopyOf

      public Paragraph appendCopyOf(Paragraph template)
      附加一份樣板段落的複製(深拷貝其內容與格式)到容器末端
      Parameters:
      template - 樣板段落
      Returns:
      複製後的新段落
    • appendCopyOf

      public Table appendCopyOf(Table template)
      附加一份樣板表格的複製(深拷貝其內容與格式)到容器末端
      Parameters:
      template - 樣板表格
      Returns:
      複製後的新表格
    • appendHtml

      public void appendHtml(String html)
      以渲染後的 HTML 子集附加富文本到容器末端
      Parameters:
      html - appfuse-web RichTextEditor 輸出的 HTML 字串
    • findParagraphByText

      public Optional<Paragraph> findParagraphByText(String text)
      依文字內容定位段落
      Parameters:
      text - 要尋找的文字(部分比對)
      Returns:
      第一個包含該文字的段落
    • findParagraphByBookmark

      public Optional<Paragraph> findParagraphByBookmark(String bookmark)
      依書籤定位段落
      Parameters:
      bookmark - 書籤名稱
      Returns:
      含該書籤的段落
    • findCellByText

      public Optional<TableCell> findCellByText(String text)
      依文字內容定位儲存格
      Parameters:
      text - 要尋找的文字(部分比對)
      Returns:
      第一個包含該文字的儲存格
    • findCellByBookmark

      public Optional<TableCell> findCellByBookmark(String bookmark)
      依書籤定位儲存格
      Parameters:
      bookmark - 書籤名稱
      Returns:
      含該書籤的儲存格
    • replaceText

      public void replaceText(String target, String replacement)
      跨段落、跨儲存格的文字取代(保留各段首個 run 的格式)
      Parameters:
      target - 目標字串
      replacement - 取代字串