计算用docx4j编辑的Word文件中的页面/行数 [英] Count pages/lines in a word file that was edited with docx4j

查看:471
本文介绍了计算用docx4j编辑的Word文件中的页面/行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里找到了一些帖子,介绍如何使用apache-poi库计算页面/行数. 但是我的代码现在已经在使用docx4j,要完全替换掉它会花费很多精力.

I found some posts here how to count pages/lines with the apache-poi library. But my code already uses docx4j right now, it would be too much work to completely replace that.

因此,我的问题是,如何从类型为WordprocessingMLPackage的对象到类型为XWPFDocument的对象,以便计算当前文档的行数和页数.

Therefore my question is, how can I get from an object of type WordprocessingMLPackage to an object of type XWPFDocument in order to count the lines and pages of my current document.

private XWPFDocument convertDocx4J(WordprocessingMLPackage wp) {
    XWPFDocument oiDoc = null;

    //TODO...

    return oiDoc;
}

推荐答案

从docx4j的WordprocessingMLPackage到POI的最简单方法是使用docx4j的API另存为docx,然后再加载POI.

Easiest way to go from docx4j's WordprocessingMLPackage to POI would be to use docx4j's API to save as docx, then POI's to load.

但是您可以从docx4j获取页面信息;参见 https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/toc/TocGenerator.java#L657

But you can get page info from docx4j; see https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/toc/TocGenerator.java#L657

这篇关于计算用docx4j编辑的Word文件中的页面/行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆