Add image using WordML

故事扮演 提交于 2020-01-24 20:58:27

问题


I am trying to add an image into a document using WordML. I have used the xml as a basis from the jpg example from here http://www.codeproject.com/KB/office/WordML.aspx. I have managed to write Java which creates this exact xml(wordML) in the document, however when I try and open the generated file in MS Word 2007 it says the file in invalid or corrupt.

The xml for the document that won't open is here:

http://pastebin.com/RNEkbvYG (Raw xml) Sorry for the long paste, this is the shortest example I could create, there's load of gumph at the top and bottom, but you can clearly see the data image in the middle.

http://pastebin.com/download.php?i=RNEkbvYG (download, rename from txt to xml and open with word)

I would greatly appreciate if anybody could look at the xml at the link above and see if they can see why it won't open in word.


回答1:


<w:pict>
            <w:binData w:name="wordml://02000001.jpg">/9j/4AA..Xof/9k=</w:binData>
            <v:shape id="_x0000_i1025" style="width:100%;height:auto" type="#_x0000_t75">
              <v:imagedata o:title="network" src="wordml://02000001.jpg"/>
            </v:shape>
          </w:pict>

is 2003 WordML. There is no w:binData element in the 2007 docx format / ECMA standard.

You might try docx4j instead :-)

See http://dev.plutext.org/svn/docx4j/trunk/docx4j/src/main/java/org/docx4j/samples/AddImage.java



来源:https://stackoverflow.com/questions/5406625/add-image-using-wordml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!