[Ironpython-users] open xml sdk v2.0

Pawel Jasinski pawel.jasinski at gmail.com
Fri Oct 28 16:08:29 CEST 2011


hi,

I am trying to use openxml sdk v2.0 together with python 2.7.1 (was
2.7.0). I have managed to generate the mini document out of the csharp
(http://msdn.microsoft.com/en-us/library/dd440953%28v=office.12%29.aspx)

However if I try to do it from python, the produced document is
corrupted. Word complains about 'parts missing or invalid'. Unzip
spits the following:

$ unzip -t ../foobar.docx
Archive:  ../foobar.docx
   testing: word/document.xml
 error:  invalid compressed data to inflate
   testing: _rels/.rels              OK
At least one error was detected in ../foobar.docx.


Is there some sort of fundamental incompatibility between openxml sdk
and ironpython? Mixed zip libraries?

The test code:

import clr
clr.AddReferenceToFileAndPath("C:\Program Files\Open XML
SDK\V2.0\lib\DocumentFormat.OpenXml.dll")
from DocumentFormat.OpenXml.Packaging import WordprocessingDocument
from DocumentFormat.OpenXml import WordprocessingDocumentType
from DocumentFormat.OpenXml.Wordprocessing import
Text,Paragraph,Run,Document, Body

package = WordprocessingDocument.Create(
'c:/Users/rejap/Desktop/foobar.docx',
WordprocessingDocumentType.Document)
package.AddMainDocumentPart()
package.MainDocumentPart.Document =
Document(Body(Paragraph(Run(Text("""asdfasdfasdfaasdfa""")))))
package.MainDocumentPart.Document.Save()



--Pawel


More information about the Ironpython-users mailing list