如何合并两个.odt文件?手动执行,打开每个文件并复制内容将会起作用,但是是不可行的.
我已经尝试过odttoolkit Simple API(simple-odf-0.8.1-incubating)来实现该任务,创建一个空的TextDocument并将其中的所有内容合并到一起:
private File masterFile = new File(...); ... TextDocument t = TextDocument.newTextDocument(); t.save(masterFile); ... for(File f : filesToMerge){ joinOdt(f); } ... void joinOdt(File joinee){ TextDocument master = (TextDocument) TextDocument.loadDocument(masterFile); TextDocument slave = (TextDocument) TextDocument.loadDocument(joinee); master.insertContentFromDocumentAfter(slave,master.getParagraphByReverseIndex(0,false),true); master.save(masterFile); }
而且工作得很好,但是它丢失了有关字体的信息 – 原始文件是Arial Narrow和Windings的组合(对于复选框),输出masterFile都在TimesNewRoman中.起初我怀疑insertContentFromDocumentAfter的最后一个参数,但是将其改为false(几乎)所有的格式化.我做错了吗?还有其他的方法吗?
解决方法
我认为这是“按设计工作”.
我曾尝试过一次全球文件,它导入文档并显示它们,只要段落样式具有不同的名称!
使用相同的命名模板将被“主”文档的值覆盖.
所以我最终用唯一(每个文档)名称克隆标准样式.
HTH