Solved

OpenXML Wordprocessing change/replace field contents in a docx document

Posted on 2014-03-31
5
1,159 Views
Last Modified: 2014-11-19
I'm searching a way to change the content of simple text fields in a Word docx document by VB.NET.

I have found some OpenXML based scripts for inserting pictures, or tables but nothing to change (replace) the content of simple text fields inside a well formated docx template.
0
Comment
Question by:hpnix4ever
[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
5 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 40166911
Just asking: are you looking for something like http://www.aspose.com/.net/word-component.aspx ? But then Free ?
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 40168475
You could write your own.  A docx file is nothing more than a zip file containing XML documents.  Most strings are stored in one file (can't remember the name offhand) and referenced from other files by occurrence number within the file (very poor XML design on Microsoft's part).
0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 40176250
you could do something like this
using (WordprocessingDocument doc = WordprocessingDocument.Open(filename, true))
        {
            var allParas = doc.MainDocumentPart.Document.Descendants<DocumentFormat.OpenXml.Wordprocessing.Text>();

            foreach (Text item in allParas)
            {
                if (item.Text == "rrq")
                {
                    item.Text = "bbq";
                }
            }
            doc.MainDocumentPart.Document.Save();
        }

Open in new window

0
 

Author Closing Comment

by:hpnix4ever
ID: 40452401
I have a own solution with OpenXML and the mailmerge function.

Thanks for help!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

628 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