对于旧的Microsoft格式(.doc),APACHE POI使用了HWPFDocument。 要知道此对象的页数,我只需要:
HWPFDocument document = new HWPFDocument(new FileInputStream(file.getAbsolutePath()));
System.out.println(document.getSummaryInformation().getPageCount());
现在,我想对XWPFDocument(对于.docx)执行相同操作,但此方法不存在。
我试过了:
XWPFWordExtractor extractor = new XWPFWordExtractor(document);
并查看它是否有类似于getPageCount()但我没有找到任何东西。
For old Microsoft formats (.doc) APACHE POI used HWPFDocument. To know the number of pages for this object, I just needed to do:
HWPFDocument document = new HWPFDocument(new FileInputStream(file.getAbsolutePath()));
System.out.println(document.getSummaryInformation().getPageCount());
Now, I want to do the same to XWPFDocument (for .docx), but this method do not exist.
I tried:
XWPFWordExtractor extractor = new XWPFWordExtractor(document);
and see if it has something similar to getPageCount() but i did not found anything.
更新时间:2022-12-16 18:12
我无法测试它,但我建议试试这个:
XWPFDocument docx = new XWPFDocument(POIXMLDocument.openPackage(DocFilePath));
int numPages = docx.getProperties().getExtendedProperties().getUnderlyingProperties().getPages();
https://poi.apache.org/apidocs/org/apache/poi/POIXMLProperties.ExtendedProperties.html
I cannot test it but I suggest try this:
XWPFDocument docx = new XWPFDocument(POIXMLDocument.openPackage(DocFilePath));
int numPages = docx.getProperties().getExtendedProperties().getUnderlyingProperties().getPages();
https://poi.apache.org/apidocs/org/apache/poi/POIXMLProperties.ExtendedProperties.html
CTx类是XMLBeans包装器 。 它们是从已发布的OOXML规范XML模式文件自动生成的。 如果文件中的xml元素是p ,那么OOXML生成的XMLBeans包装将是CTP 。 如果它是table ,那么它将是CTTable 。 xml元素的名称空间将放到类的包中,因此如果有两个具有相同本地名称但名称空间不同的不同元素,那么您将能够确定您想要的是哪一个。 如果您有选择,请不要使用CT课程。 它们是低级别的,并且需要您了解底层文件格式的结构和格式。 它们通常只用于高级用例。 使用Apache POI us ...
我会给你逻辑。 你应该能够将它转换为java 首先,输入文档文件应该落入特定文件夹。 扫描文件夹并获取文件夹中的文件数。 放一个for循环并逐个获取文件。 将所有代码逻辑放在循环中。 检查获取文件的文件类型。 如果它的.doc / .docx处理它。 以类似的方式处理所有文件。 稍后删除已处理的文件。 I will just give you the logic. you should be able to convert it to java First the input docs files shou ...
你所看到的XWPF类是一项正在进行的工作,没有真正的总体架构。 随着时间的推移,这将随着时间的推移而变化,但同时您可以尝试用这种方法为段落添加一个简单的TOC字段。 XWPFParagraph p; ... // get or create your paragraph .... CTP ctP = p.getCTP(); CTSimpleField toc = ctP.addNewFldSimple(); toc.setInstr("TOC \h"); toc.setDirty(STOnOff.TRUE ...
你不能! 由于.doc和.docx格式的工作方式,给定运行中的所有内容必须具有相同的格式 给定段落可以包含任意数量的运行,每个运行都有自己不同的样式/格式。 因此,您需要将一个运行拆分为多个运行,并根据需要设置不同的新运行样式 You can't! Due to the way that the .doc and .docx formats work, everything in a given run must have the same formatting A given paragraph may ...
表是块级项目,这意味着它将根据页面的高度和跨度占用垂直空间,无论是否使用该空间。 所以没有办法以相同的方式并排“流动”两个表,无法并排流动两个段落。 有几种方法可以实现这种效果,但在您的情况下最直接的方法可能是创建一个1行乘三列的表,并将左表放在第一个单元格中,将右表放在第三列中。 中间列可用于实现两者之间的间隔。 您可能不希望在包含表上使用任何边框,因为它用于格式化而不是显示。 A table is a block-level item, meaning it will take up vertical ...
如果要实际删除,将更改GetPageCount(),因此end将保留早期版本的值 对于Eg。 m_notebook-> GetPageCount()中有100个 所以结束= 100 在迭代10个项目之后,你将删除5个项目,所以现在列表将有95个项目但是你正在迭代到100个 - 这可能是个问题 GetPageCount() will be changed if you are deleting pragmatically so end will hold earlier versions value For ...
由于apache poi XWPF一直处于beta状态,所以只有在确切知道Word将如何将其内容存储到XML中时才能实现这些功能。 然后,人们可以解决apache poi XWPF的不足之XWPF 。 您已经使用了这样的解决方法,可以在将图片添加到页眉或页脚中的运行时更正错过的blipID 。 要发现Word如何将其内容存储到XML中并不是火箭科学。 *.docx文件只是一个ZIP文件。 如果使用Zip软件解压缩此文件,可以简单地查看XML文件。 据我所知, apache poi直接支持在Word文档中添加 ...
我无法测试它,但我建议试试这个: XWPFDocument docx = new XWPFDocument(POIXMLDocument.openPackage(DocFilePath)); int numPages = docx.getProperties().getExtendedProperties().getUnderlyingProperties().getPages(); https://poi.apache.org/apidocs/org/apache/poi/POIXMLProperti ...
我发现完成此任务的最简单方法是使用OPCPackage的“replaceContentType”方法。 OPCPackage pkg = OPCPackage.open(src.getAbsolutePath()); pkg.replaceContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml", "application/vnd.openxml ...
推荐对答案的评论...... 序列化XWPFDocument (或实际上任何POI UserModel文档)的方法是通过write(OutputStream)方法 如果需要序列化为字节数组,则可以执行以下操作: XWPFDocument doc = new XWPFDocument(); ... ByteArrayOutputStream baos = new ByteArrayOutputStream(); doc.write(baos); return baos.toByteArray(); 假设您 ...
原网址: 访问
创建于: 2023-05-08 17:26:26
目录: default
标签: 无
未标明原创文章均为采集,版权归作者所有,转载无需和我联系,请注明原出处,南摩阿彌陀佛,知识,不只知道,要得到
最新评论