Solved

how do I edit office 2007 word xml files programatically

Posted on 2007-11-30
2
845 Views
Last Modified: 2012-06-22
If you take the new *.docx files that MSWord 2007 produces when it saves, and open it up in WinZip, you can see all the of xml files that make up the "dna" of the word file.  One of the xml files is called 'document.xml' that stores all of the text context in the word doc.

So here is the question.. if you make a simple word doc, for example a doc that only contains the text "Hello World", you can easily find the tag the contains this text in the 'document.xml' thats part of the docx package.  However, when I tried to change this tag in a text editor (to, lets say "Goodbye, World" , replace the original 'document.xml' with the modified one, and re-zip the package, word thinks something is corrupted.

I must be missing something because I know that the whole point of using XML as the source for a document is that other programing languages can edit the XML directly and read/modify/create word docs.  I can't even get this to work when editing it manually in a text editor!

I suspect that the zipping step isnt correct, or maybe I have to update another xml file in the package to accept the modified document.xml file?  I would like to learn how to edit MSOffice documents by editing the underlying XML... what am I missing?  Ill give points for an answer that explains why my zipping didnt work rather than answers that are just links to general information about open xml for office.  I feel like I read them all and couldnt find the answer!

thanks, experts
-md

0
Comment
Question by:meuedyn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
wiglack earned 500 total points
ID: 20385720
I made a docx file that had the text Hello World!

I used Winrar.  I extracted the document.xml file.  I then opened the document.xml file in notepad and added EDITED!.  I saved the file in notepad.  Then I deleted document.xml in winrar.  I then added the new document.xml that I edited earlier.
When I opened Word2007 I saw Hello World! EDITED

Since I don't use Winzip I can't see if there is a problem with winzip.  Make sure you aren't changing the archive to zip.  It should work the same way.
0
 

Author Comment

by:meuedyn
ID: 20397310
I think the problem was in WinZip making an archive.  I discovered that using Internet Explorer to view/edit xml files works better and preserves the internal folder structure!

thanks wiglack
-md
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question