Solved

OpenXML Wordprocessing change/replace field contents in a docx document

Posted on 2014-03-31
5
1,126 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

728 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