Many thanks Svante for your input. In my debugging for this problem I went through this method and and it was working just fine. Actually the files were inserted in the master file and I can see them when I open the master file as zip file. But when I open it from OpenOffice, only the original data coming from the template is there and not the rest of the inserted documents.
For running the below test, I can gladly do that, but I'm not sure how. I tried before to get all the source code from Maven but it was a trouble mistake from my side and I don't think I can handle such experience again :) If you can just guide me to download the source code of these tests, and how to run them, I can do that. I am using the following versions for libraries of the code. dom4j-1.6.1.jar odfdom-java-0.8.7.jar poi-3.9-20121203.jar poi-ooxml-3.9-20121203.jar poi-ooxml-schemas-3.9-20121203.jar simple-odf-0.6.6 stax-api-1.0.1.jar xmlbeans-2.3.0.jar xslt-runner-1.2.1-incubating.jar Xslt-runner-task-1.2.1-incubating.jar I created a one eclipse project for most of the demos (one is having errors that I couldn't fix) that I can share with you guys but it is more than 6 MB (due to the libraries) and I don't think that attachment to this mailing list will allow it. I wonder if there is some place to upload it to. Thanks & Best Regards / السلام عليكم Ahmed Ibrahim MBA ,Senior IT Architect, SWG Cairo Lab Services BPM Client Solution Manager, MEA IT Architect Egypt Profession Lead Mobile: +20 100 1615 506 From: Svante Schubert <[email protected]> To: Robert Weir <[email protected]>, Ahmed I Ibrahim/Egypt/IBM@IBMEG, Cc: [email protected] Date: 04/15/2014 11:16 AM Subject: Re: How to insert a text document into another text document? Hi Rob, any idea, why the demos of the simple API (e.g. http://incubator.apache.org/odftoolkit/simple/demo/demo7.html) are not part of the source code repository? Wouldn't it be nice to have them as part of the regression tests? @Ahmed: Due to obstacle mentioned above, you need to debug yourself in the ODFDOM class OdfPackageDocument the following function: /** * Embed an OdfPackageDocument to the current OdfPackageDocument. * All the file entries of child document will be embedded as well to the current document package. * @param newDocument the OdfPackageDocument to be embedded. * @param documentPath to the directory the ODF document should be inserted (relative to the root of this document). */ public void insertDocument(OdfPackageDocument newDocument, String documentPath) { newDocument.flushDoms(); mPackage.insertDocument(newDocument, mDocumentPathInPackage + documentPath); } The function is being called from the following tests: * DocumentCreationTest.java * LoadSaveErrorTest.java * LoadSaveTest.java PS: A little history, the simple API was once an IBM "branch", in general I focus on supporting the lower ODFDOM library. Hope this helps already, Svante Am 15.04.2014 10:49, schrieb Ahmed I Ibrahim: > Dear all, > > Sorry for my previous mail, it had more details but my editor just get rid > of them. Any way it sent the important part which is the code. > > I still have the problem and actually the problem is simple. I need to > merge a set of text documents into one text document. To regenerate my > problem, I modified the demo7 available at > http://incubator.apache.org/odftoolkit/simple/demo/demo7.html > > This demo is generating a set of documents and I modified it to also merge > these documents into one document. I used two methods to do so: > > One by using org.odftoolkit.simple.TextDocument as following: > > public static void generateAllOffersLetterTextDocument() throws > Exception { > TextDocument templateDocument = TextDocument.loadDocument( > fRootDirectory + "/"+ "OfferTemplate.odt"); > > SpreadsheetDocument dataDocument = SpreadsheetDocument. > loadDocument(fRootDirectory + "/"+ "Candidates.ods"); > Table table = dataDocument.getTableByName("Sheet1"); > int rowCount = table.getRowCount(); > > TextDocument offerDoc = null; > for(int i = 1; i<rowCount; i++){ > Row row = table.getRowByIndex(i); > String name = > row.getCellByIndex(0).getDisplayText(); > > offerDoc = TextDocument.loadDocument(fOutDirectory > + "/" + name+"'s offer letter.odt"); > templateDocument.insertDocument(offerDoc, "/" + > name); > } > > templateDocument.save(fOutDirectory + > "/AllOffersTextDoc.odt"); > } > > And the other way is by extending > org.odftoolkit.odfdom.doc.OdfTextDocument by a new class MyTextDocument to > do exactly the same thing as follows: > > public static void generateAllOffersODFDocument () throws > Exception { > MyTextDocument allDocTextDoc = MyTextDocument. > newTextWorkProduct(fRootDirectory + "/"+ "OfferTemplate.ott"); > > SpreadsheetDocument dataDocument = SpreadsheetDocument. > loadDocument(fRootDirectory + "/"+ "Candidates.ods"); > Table table = dataDocument.getTableByName("Sheet1"); > int rowCount = table.getRowCount(); > > for(int i = 1; i<rowCount; i++){ > Row row = table.getRowByIndex(i); > String name = > row.getCellByIndex(0).getDisplayText(); > > allDocTextDoc.includeFile(fOutDirectory + "/" + > name+"'s offer letter.odt", "/" + name); > } > > > allDocTextDoc.save (fOutDirectory + "/AllOffersODFDoc.odt" > ); > } > > While the includeFile is as follows: > > public void includeFile (String filePath, String documentPath) > throws Exception{ > OdfPackageDocument newDocument; > > try { > newDocument = OdfPackageDocument.loadDocument > (filePath); > insertDocument(newDocument, documentPath); > } catch (Exception exception) { > throw new Exception ("Failed to include the file: > " + filePath, exception); > } > } > > The results were exactly the same, the generated files didn't show the > agregated documents, only the first contents of the document, however the > conetns of the documents are inserted in their coresponding folders in the > zip file. > > In the attached zip file in the previous message, I included the source > code (FieldsDemo.java and MyTextDocument.java) as well as the source files > and the generated files. Sorry again for the previous messgae. I am > stucked here and I can not move forward, and I am looking for help. > > > Thanks & Best Regards / السلام عليكم > > Ahmed Ibrahim > MBA ,Senior IT Architect, SWG Cairo Lab Services > BPM Client Solution Manager, MEA > IT Architect Egypt Profession Lead > Mobile: +20 100 1615 506 > > > > From: Ahmed I Ibrahim/Egypt/IBM@IBMEG > To: [email protected], > Date: 04/15/2014 10:18 AM > Subject: Re: How to insert a text document into another text > document? > > > [attachment "ODF_FileMerge.zip" deleted by Ahmed I Ibrahim/Egypt/IBM] >
