0

document.xml次のような DOCX ファイルから docx4j を使用してランからテキストを抽出したい:

<w:document mc:Ignorable="w14 w15 w16se wp14">
<w:body>
<w:r>
  <w:rPr>
    <w:rFonts w:ascii="TimesNewRomanRegular" w:hAnsi="TimesNewRomanRegular" w:cs="TimesNewRomanRegular"/>
    <w:b/>
    <w:sz w:val="19"/>
    <w:szCs w:val="19"/>
    <w:lang w:val="en-US"/>
  </w:rPr>
  <w:t>CEO</w:t>
</w:r>
...

実行を抽出したので、各実行のテキストを取得したいと思います。以下のコードは機能しますが、非常に冗長です。より簡潔な方法で org.docx4j.wml.R のインスタンスのテキストを取得することは可能ですか?

public static Optional<String> runText(org.docx4j.wml.R run)
{
        return run.getContent()
                .stream()
                .map(JAXBElement.class::cast)
                .map(JAXBElement::getValue)
                .filter(Text.class::isInstance)
                .map(Text.class::cast)
                .map(Text::getValue)
                .findFirst();
}

「R::getContent」と「R::getRPr」は存在するのに、なぜ「R::getText」がテキスト文書に存在しないのだろうか。

4

1 に答える 1