4 Answers, 1 is accepted
In case it's of any use: We use both OpenXML and Telerik on the same document in some of our code. The way we work that is:
- load the file to a byte array (DocxFormatProvider.Import(byte[])
- load that byte array into the Telerik objects
- Do what we need to do,
- Export it back to a byte array (DocxFormatProvider Export(RadFlowDocument))
- Load it into the OpenXML objects
- Do our OpenXML actions
WordsProcessing is a library intended to import, modify, generate and export various flow document formats, including DOCX. A file is basically a collection of XML files in accordance with the Office Open XML specification, so I'm not entirely sure what you are trying to achieve, Brian.
If you're looking to edit a document, then the approach Tom outlined is the way to go. You could import a document with the DocxFormatProvider, edit its contents with a RadFlowDocumentEditor and export it back with the format provider.
Alternatively, if for some reason you are looking for access to the underlying XML files, our ZipLibrary can help achieve this task.
I hope this helps, but if I misunderstood your question, please let me know.
Regards,
Petya
Progress Telerik
I am working on some legacy code that parses (read only) the XML document for various reasons. I am trying to replace a lot of that old code with similar functionality from the Telerik tools. As I do this, I am prioritizing by the amount of time each piece will take me to finish. In this case, it will take a while, so it is going on the back burner. At the same time, if I can swap out some small part of the code with Telerik's equivalent utilities, it will make things easier when I come back to it. So what I am looking for is direct access to read the XML document in the DOCX file.
You mentioned the Zip Library. I looked at that, but didn't see examples dealing with OpenXML documents. Do you know of any such examples?
Thanks for elaborating.
The ZipLibrary can help you gain access to the underlying XML files in a DOCX archive, for example:
using
(Stream stream = File.Open(
"test.docx"
, FileMode.Open))
{
using
(ZipArchive archive =
new
ZipArchive(stream))
{
foreach
(var archiveEntry
in
archive.Entries)
{
//process the individual files in the DOCX archive
}
}
}
In this scenario, you can then read the XML files with File.Open, however, the ZipLibrary doesn't have the capabilities to parse those XML files. This would be something WordsProcessing can handle (to provide some additional context - by using the same ZipLibrary internally) with the approach outlined in the previous posts.
Let me know if I can help with anything else.
Regards,
Petya
Progress Telerik
Can you please help us by example. I have exported byte[] from DocxFormatProvider.
Now I want to get Open Office XML from byte[]. My goal is to convert byte[] to xml document.
Hey, Kamran,
If you wish to export the byte array to a DOCX file, please use this line of code:
File.WriteAllBytes("document.docx",byteArray); //The second argument is your byte array
If you wish to programmatically obtain the XML files from a DOCX file created with WordsProcessing, you can first export the RadFlowDocument to a file and then use the example code in the article Extract the contents of a zip file to a directory to extract it with ZipLibrary.
Please let me know if this helps or if you have a different goal.