Thanks for your replies and sorry for my late answer. But I needed a lot of testing
My situation is a bit complicated as I create an empty document at runtime, create dozens of textsections and link files to them. After working with the document I want to save the changes to the linked files.
For performance reasons I want to keep saving actions, iterations on the whole document and creating of new blank and hidden documents as low as possible.
So there is no original document. Maybe I'll change that in future. I have to think about it. But saving a large odt file needs some time and if you have to do it two or three times, it can last an incredibly long time.
My first solution to my problem was to create a second hidden document and use copy and paste between these two hidden documents. It seemed to work, but I prefer your solution. Thanks a lot. Linking to the region worked well.
In the moment I try to figure out if I can use MetadataReference. If you take a look at the content.xml in the .odt file, you'll find all the listed textsections in a quite comfortable way. It would be a nice and easy solution to be able to link them directly. In that case I wouldn't to have take care, if there are other sections - hidden or not - inside of them.
I tried this:
Code: Select all
TS = doc.TextSections
for i in range(TS.Count):
sec = TS.getByIndex(i)
sec.ensureMetadataReference()
MD_ref = section.MetadataReference
newDoc.addMetadataFile('some_name',MD_ref)
But I get this error:
2014-02-03 09:15:16,903 [CALL,tid 3000]: error py->uno[0x56406e0].addMetadataFile = (com.sun.star.script.CannotConvertException){ (com.sun.star.uno.Exception){ Message = (string)"conversion not possible!", Context = (com.sun.star.uno.XInterface)0x0 }, DestinationTypeClass = (com.sun.star.uno.TypeClass)SEQUENCE, Reason = (long)0x8, ArgumentIndex = (long)0x1 }
I don't know if the addMetadataFile asks for something else than the MetadataReference?
The documentation says I need a FileName and a Sequence of type XURI.
http://www.openoffice.org/api/docs/comm ... tadataFile
http://www.openoffice.org/api/docs/comm ... /XURI.html
I thought my MD_ref is a type XURI. But that seemes to be wrong.
Many thanks for your help,
ponc