Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

OpenXML Wordprocessing change/replace field contents in a docx document

Posted on 2014-03-31
5
Medium Priority
?
1,259 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 27

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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.

670 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