Replacing a text in Apache POI XWPF

前端 未结 10 2273
鱼传尺愫
鱼传尺愫 2020-11-29 18:18

I just found Apache POI library very useful for editing Word files using Java. Specifically, I want to edit a DOCX file using Apache POI\'s XWPF classes. I

10条回答
  •  孤街浪徒
    2020-11-29 18:56

    The first chunk of code is giing me a NullPointerException, anyone know what is wrong?

    run.getText(int position) - from documentation: Returns: the text of this text run or null if not set

    Just check if it is not null before calling contains() on it

    And btw if you want to replace the text you need to set it in position from which you get it, in this case r.setText(text, 0);. Otherwise text will be added not replaced

提交回复
热议问题