ApachePoi 的 XWPFDocument 中存储的列表信息在哪里? [英] Where are List informations stored in ApachePoi's 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 并手动复制段落和表格,例如 此处.
- 将 newBody 附加到现有的像这里一样 这里
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 num
elements 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
中有 XWPFNumbering 表示文档部分 /word/numbering.xml
和 XWPFAbstractNum 代表abstractNum
.
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 Id
s 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屋!