如何生成RSID在使用Apache POI的Word .DOCX文件正确属性? [英] How to generate RSID attributes correctly in Word .docx files using Apache POI?
问题描述
我一直在使用Apache POI操纵的Microsoft Word .DOCX文件 - 即开最初在Microsoft Word中创建的文档,修改它,将它保存到一个新的文档
I have been using Apache POI to manipulate Microsoft Word .docx files — ie open a document that was originally created in Microsoft Word, modify it, save it to a new document.
我注意到,被Apache POI创建的新段落缺少的修订保存ID 的,通常被称为一个的 RSID 或 rsidR 的。这是使用Word来标识一个会话中对文档所做的更改,说节约之间。它是可选的 - 用户可以关闭它在Microsoft Word中,如果他们想要的 - 但在现实中,几乎每个人都有它使几乎每一个文档是RSIDs的充盈。读<一个href=\"http://blogs.msdn.com/b/brian_jones/archive/2006/12/11/what-s-up-with-all-those-rsids.aspx\">this RSIDs优秀的解释了解这一点。
I notice that new paragraphs created by Apache POI are missing a Revision Save ID, often known as an RSID or rsidR. This is used by Word to identify changes made to a document in one session, say between saves. It is optional — users could turn it off in Microsoft Word if they want — but in reality almost everyone has it on so almost every document is fulls of RSIDs. Read this excellent explanation of RSIDs for more about that.
在Microsoft Word文档,字/ document.xml
包含这样的段落:
In a Microsoft Word document, word/document.xml
contains paragraphs like this:
<w:p w:rsidR="007809A1" w:rsidRDefault="007809A1" w:rsidP="00191825">
<w:r>
<w:t>Paragraph of text here.</w:t>
</w:r>
</w:p>
然而,通过POI创建的同款看起来像这样字/ document.xml
:
<w:p>
<w:r>
<w:t>Paragraph of text here.</w:t>
</w:r>
</w:p>
我已经想通了,我可以强制使用POI code像这样的RSID添加到每个段落:
I've figured out that I can force POI to add an RSID to each paragraph using code like this:
byte[] rsid = ???;
XWPFParagraph paragraph = document.createParagraph();
paragraph.getCTP().setRsidR(rsid);
paragraph.getCTP().setRsidRDefault(rsid);
不过,我不知道我应该如何生成RSIDs。
However I don't know how I should be generating the RSIDs.
POI是否有办法或产生和/或跟踪RSIDs的?如果没有,有没有什么办法,我可以保证,我产生一个RSID不符合一个是已经在文件中冲突?
Does POI have a way or generate and/or keep track of RSIDs? If not, is there any way I can ensure that an RSID that I generate doesn't conflict with one that's already in the document?
推荐答案
看起来有效RSID条目的字举行的名单/ settings.xml中的&LT; W:rsids&GT;
项。 XWPF应该能够给你的访问了。
It looks like the list of valid rsid entries is held in word/settings.xml in the <w:rsids>
entry. XWPF should be able to give you access to that already.
您很可能希望生成一个8十六进制数字长的随机数,检查如果这是在那里,和重新生成,如果它是。一旦你有一个独特的一,将其添加到该列表,然后用它标记您的段落。
You'd probably want to generate a 8 hex digit long random number, check if that's in there, and re-generate if it is. Once you have a unique one, add it into that list, then tag your paragraphs with it.
什么我建议是,你加入POI开发列表(邮件列表的详细信息) ,我们可以给你的工作了一个补丁为它的手。我觉得要做的事情是:
What I'd suggest is that you join the poi dev list (mailing list details), and we can give you a hand on working up a patch for it. I think the things to do are:
- 解决Word / settings.xml中的RSids进入包装,让你轻松获取列表,并生成一个新的(唯一的)
- 各地不同RSID条目的包装上一个段落和运行
- 在段落和运行,以获得RSID包装方法,添加一个新的,或清除现有
我们应该拿这个去开发列表,但:)
We should take this to the dev list though :)
这篇关于如何生成RSID在使用Apache POI的Word .DOCX文件正确属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!