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] 

Reply via email to