Sorry, I am not aware of any other example. You might want to define yourself a fixed set of style name for all templates, for instance use those styles being used by Apache OpenOffice.
Anyone else has done this before and could lend a helping hand? Best regards, Svante Am 15.04.2014 14:08, schrieb Ahmed I Ibrahim: > Thanks Svant, > > I see your point now. I tried this OLE object and it is not really what I > need. So the right statement right now, is that I need to copy the > contents of the other documents and add them to the content of the > AllFiles.odt > > That will give me a chance to apply the styles in the AllFiles. Odt to the > contents of the other documents. The question now how can I do that using > the APIs? Is there a sample for that, that I can follow? > > 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: [email protected], > Date: 04/15/2014 01:37 PM > Subject: Re: How to insert a text document into another text > document? > > > > Hi Ahmed, > > not a problem, answer inline.. > Am 15.04.2014 12:57, schrieb Ahmed I Ibrahim: >> Hi Svante, >> >> Thank you for your time again. >> >> I tried to see how can I do merge documents using OpenOffice, but I > didn't >> see how. The only thing that I found from the help is Edit -> Changes -> >> Merge Documents but this gave me an error saying "can not merge > documents" >> when I select different document. I think this is not its target. >> >> So if you can help me in two things: >> 1- How can I merge documents manually > In an OpenOffice descendant application it is Insert->Object->Ole Object > Than choose from file and insert your ODF text file. >> 2- When I see the different in the context.xml , how would I found the >> needed API convent to do it. You see I am still new with ODF so I may > need >> more detailed guidance (sorry) > A frame will be added for instance in my example it looked like: > <draw:frame draw:style-name="fr1" draw:name="Objekt1" > text:anchor-type="paragraph" svg:width="21.001cm" svg:height="13.386cm" > draw:z-index="0"> > <draw:object xlink:href="./Object 1" xlink:type="simple" > xlink:show="embed" xlink:actuate="onLoad"/> > <draw:image xlink:href="./ObjectReplacements/Object 1" > xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/> > </draw:frame> > > Where "Object 1" was the name of the directory of the embedded file (the > directory containing the content.xml, etc.) > > NOTE: In ODF the surrounding frame element provides the view frame only. > The children are view options the application might chose. > For instance, above it is first an draw:object, but in case the ODF > application do not know about OLE objects, the second child the > draw:image will be shown. > [It is quite similar to the HTML 5 <video> tag, which includes multiple > <source> elements of the same video in different codecs.] > You may find the ODF 1.2 spec documentation here > http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#element-draw_frame > > > To know if there is any existing functionality in the ODF Toolkit, I > searched for DrawFrameElement, as <draw:frame> would be mapped to that > typed DOM class. > > But charts are usually added as embedded document, therefore you might > look at the simple API and the chart test case, but what suited best was > searching for "DrawFrameElement" in the simple API tests (i.e. > odftoolkit20140415\simple\src\test\java\org\odftoolkit\simple) and take > a look at the DocumentCreationTest > especially at the addImageToDocument(..) function as draw:object is > quite similar to draw:image. > > PS: A better API should hopefully be available later this year, when I > merge my change-tracking changes into the repository.. (do not wait!) ;) > > Hope that helps! > > Best regards, > Svante > > >> >> >> 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: Ahmed I Ibrahim/Egypt/IBM@IBMEG, [email protected], >> Date: 04/15/2014 12:37 PM >> Subject: Re: How to insert a text document into another text >> document? >> >> >> >> Hi Ahmed, >> >> we just missed each other by mail. >> If there are still questions after my last mail and perhaps references >> http://incubator.apache.org/odftoolkit/source.html >> >> Please do not hesitate to write again ;) >> >> Best regards, >> Svante >> >> Am 15.04.2014 12:29, schrieb Ahmed I Ibrahim: >>> 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] >>>> >> > >
