How to get the line number, page number of a particular word in a doc,docx file using apache poi?

你。 提交于 2019-12-05 13:01:55

I am afraid there is no easy way to do this. Line and page number aren't stored but calculated on fly based on text layout according to page size specified. The page widht defines wrapping positions in the text.

You can try to implement the feature yourself loading the document in a JEditorPane with appropriate EditorKit (see for example the attempt of DocxEditorKit implementation http://java-sl.com/docx_editor_kit.html It provides basic functionality and you can try to implement your own EditorKit here based on the source code and ideas).

The kit should support pagination to render page (See articles about pagination here http://java-sl.com/articles.html)

After the pagination done you can find position of the word (caret offset) and get the row/column (See http://java-sl.com/tip_row_column.html).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!