列表信息存储在ApachePoi的XWPFDocument中的什么位置? [英] Where are List informations stored in ApachePoi's XWPFDocument?

查看:106
本文介绍了列表信息存储在ApachePoi的XWPFDocument中的什么位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想合并两个或多个docx文件(彼此追加)或将文档的一部分(XWPFParagraph)移动到另一位置.

I want to merge two or more docx files (append them after each other) or move one part of the document(XWPFParagraph) to other place.

问题在于,这样的操作后,列表总是会中断.假设我们在一个文件中有一个序列号的清单,然后在另一个文件中有项目符号或字母的清单.复制后,所有项目符号都变成数字(或更差的数字是从上一个列表结束处开始).

The problem is that listings always breaks after such an operation. Say we have a listing in a document which has sequence numbers then we have other listing in another document which has bullets or letters. Than after the copy all of the bullets becomes numbers (or worse numbers which starts from where the previous listing has been ended).

我尝试了几种解决方案:
-遍历BodyElements并手动复制段落和表格,例如这里

I have tried several solutions :
-traversing BodyElements and copying Paragraphs and Tables by hand like here.
-attaching a newBody into an existing one like here here

除了页面范围的样式外,它们还可以正常工作.但是清单从来没有.这是否意味着列表符号将存储为页面范围的信息(否则它将被XWPFParagraph成功复制)?如果是,那么为什么在哪里?

Aside from page scoped styles they work well. But the listings never. Is that means the listing symbols are stored as page scoped information (otherwise it would be copyied successfully with the XWPFParagraph)? If yes than why and where?

我已经深入研究Javadoc: https://poi.apache.org/apidocs/dev/org/apache/poi/xwpf/usermodel/XWPFDocument.html
但是找不到有关列表的任何信息.

I have dig myself into the javadoc: https://poi.apache.org/apidocs/dev/org/apache/poi/xwpf/usermodel/XWPFDocument.html
But couldn't find anything about the listings.

推荐答案

以Office Open XML 文件格式存储的 Word 编号(编号列表,但也包括项目符号列表)在 *.docx ZIP 存档的/word/numbering.xml 中.有描述列表格式的 abstractNum 元素和引用 abstractNum num 元素.在/word/document.xml 的段落中引用了 num 元素的 numId ,以设置在该段落中应使用的编号格式.引用相同 numId 的段落在同一列表中.引用不同的 numId 的段落位于不同的列表中.

The Word numberings (numbered lists but bullet lists also) in Office Open XML file format are stored in /word/numbering.xml of the *.docx ZIP archive. There are abstractNum elements describing the list format and num elements referencing the abstractNum. The numId of the numelements are referenced in paragraphs of /word/document.xml to set which numbering formats shall be used in that paragraph. Paragraphs referencing the same numId are in the same list. Paragraphs referencing different numId are in different lists.

apache poi 中,有

In apache poi there are XWPFNumbering representing the document part /word/numbering.xml and XWPFAbstractNum representing the abstractNum.

直到现在,如果不使用低级的 ooxml-schemas 类,就无法从头开始创建 XWPFAbstractNum .

Until now there is no way creating XWPFAbstractNum from scratch without using the low level ooxml-schemas classes.

据我所知,由于需要处理不同的 Word 文档中的/word/numbering.xml 文档部分,因此没有简单的方法来合并/word/numbering.xml 中的不同 Id ,以及它们在/word/document.xml 中的出现.这非常复杂,我不知道任何免费的库都可以正确执行此操作.

Also, as far as I know, there is no simple way to merge /word/numbering.xml document parts of different Word documents because of the need handling the different Ids in /word/numbering.xml as well as their occurrences in /word/document.xml. This is very complex and I do not know any free library which can do this properly.

据我所知,通常,没有简单的方法将不同的 Word 文档合并在一起,因为 Word 文件格式的存储很复杂.所有提供的使用自由代码的可能性只是半途而废(遍历和复制),即使没有错误也没有用处(简单地一个接一个地附加多个文档主体).

In general, as far as I know, there is no simple way to merge different Word documents together because of the complex storage in Word file formats. All provided possibilities using free code are only halfway useful (traversing and copying), if not wrong and useless (simply attaching multiple document bodys one after the other) at all.

这篇关于列表信息存储在ApachePoi的XWPFDocument中的什么位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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