The default approach to working with DocumentBuilder 2.0 enables you to take bits and pieces of multiple documents and assemble them together into a new document. However, there is an interesting scenario that this approach does not handle. You may want to import a document into a cell in a table, into a text box, or into a content control. You can do this with DocumentBuilder 2.0. The following video shows how:
This was the content that I presented on the recent web-cast on DocumentBuilder 2.0.
The code presented in the screen-cast is attached to this blog post.
hi Eric. Is there anywhere where you post the sample code that you present in the screencasts? It would be useful to be able to download this and try it out.
I'll get on that. Look for something soon.
Hi Eric, I too would be very graeful if you could post up the code that uses the Content Contol (Bio-01) in your screencast.
I have expert-level knowledge of Word, but I'm only just beginning to explore the more advanced possibilities.
Can you please explain the relationship between Document Builder and Visual Studio? I ask because while I do have access to the Express Edition, the professional edition is not an option due to budget constraints at this time.
I'd like to know, for each of the solutions you present, whether or not the express edition of Visual Studio is sufficient.
Thank you so, so much for all of this excellent information!
DocumentBuilder can certainly be used with express editions. It is simply c# source code that you compile with other Open XML code. However, the Open XML Package Editor PowerTool for Visual Studio 2010,. can only be used with other than express editions.
Thanks so much for your reply.
I'm going to tell you what I would like to be able to do and then cross my fingers that you can tell me:
1. Whether or not your tools are what I need
2. Which tools to use for what, and
3. Specifically which functions are possible only by using the professional edition of Visual Studio
I work with for a consulting organization that responds to RFPs regularly, and once they win a job, the deliverable is usually a report. So, the two types of documents I would like to automate--using the same (master) template--are Proposals and Reports. Separate templates will be used to create the Resumes and Project Descriptions that get inserted into Proposals.
Both Proposals and Reports:
There are certain bits of information that we will use in both proposals and reports, like the name of the company we're writing the RFP/Report for, the title of the proposal or project/study, etc. This information will be gathered via workflow forms wherever in the (Business Development) process the new information is received and ultimately pulled into any document that needs to use it, dynamically, likely with Building Blocks that contain Content Controls (that contain code to insert a file determined by the choice made by the user.)
Then, there are sections like "resumes" (and "project descriptions") that go only in proposals. Resumes and Project Descriptions are individual files on a common server, created using the appropriate template (Resume.dotx or ProjectDescription.dotx) and editable by anyone in the department (they need to be word files because the people I work with don't want to change the way they have been doing things for 25+ years.)
Both the resume (and project description) FILES, and the information contained WITHIN THE FILES need to be dynamically linked to the content controls in the proposal in which they are inserted. So if a new employee, Joe, creates a resume for himself, Joe's name immediately becomes available on the (dropdown) list from which a user has to choose in order to insert Joe's resume.
My question is this: Understanding that my explanation and question are in "non-programmer's English" because I am not a programmer, and that the programmer who will be helping me knows very little about Word (we all have Office 2010 now, but only upgraded recently from 2000!) can you explain which tools/software/languages will allow us to accomplish this in a way that we'll both understand?
I don't necessarily need for you to tell me how to do it (though I wouldn't turn any help down). I just need to narrow down the list of software to download or purchase and languages to learn, to the ones that are absolutely necessary.
I know I'm asking a lot. But please know that I would be grateful for any help you can give me.
Thanks again for your last response and Happy Holidays!
In your Nov. 29th reply, you said that the "Open XML Package Editor PowerTool for Visual Studio 2010" requires an edition of Visual Studio that is not express. I still can't figure out if what you call it is the same thing as, "Visual Studio Tools for the Office System Power Tools." Are there several names for each of these tools Can you list all the tools with their complete and official names, and then say the most common way to refer to them (indicating the tools that require VS Prof. and the ones that dont?)
I am desperately trying to learn this stuff, but I can't find a book on it, and the blogs are almost always written for people who already know the basics.
Thanks again! I'd appreciate any help you can offer.
Code is now attached to the post.
Hi Eric, I want to ask, is it possible to extract a piece of the docx file between the two sentences. For example I have two variables and I need to search required piece of text with images in that file.
DocumentBuilder is restricted to modifying documents at the block-level. In other words, you can extract any element that is a child of the w:body element. You can combine documents, inserting comment, so long as all of the content is combined at the block-level. In other words, you can move paragraphs to another document. You can not move runs to another document.
Does this answer the question you have?
Thank you for such a quick answer
but, maybe my example was not so clear...
I will try one more time) this is new one...
I have two documents (both of them are docx files), first document is a template which contains only headers and footers and second document is a working copy that contains the information I needed (Information includes text, pictures, comments, etc.)
So I decided to use DocumentBuilder for this case.
What I need to do (I am trying to do)
I am trying to make third document, which uses headers and footers from the first document and some part of content of the second document.
But I dont know in what paragraph will be this information, I know only sentences, between which the information will be presented...
small example of my code for retrieving content between sentences:
static void Main(string args)
List<Source> sources = new List<Source>();
using(WordprocessingDocument doc = WordprocessingDocument.Open("../../SomeReport.docx", false))
var _prgs= doc
.Select((p, i) => new
Paragraph = p,
Index = i
sources.Add(new Source(new WmlDocument("../../Report.docx"),
_prgs.FindIndex(i => i.Paragraph.Value == "First Sentence "),
_prgs.FindIndex(i => i.Paragraph.Value == "Second Sentence") -
_prgs.FindIndex(i => i.Paragraph.Value == "First Sentence") + 1, true));
How can I use document builder to copy a TableCell from a table from one document to a Tablecell in other document.
This example shows how to copy the entire document. The only difference is I want to copy just a TableCell
Please guide me. I have downloaded your sample and trying to learn it. Your early reply will be highly appreciated.
The table cell will have text and images.
Using simple OpenXML only text is copied and images are shown as red cross "cannot display message".
Thanks in advance.
As delivered, DocumentBuilder does not have the capability to select just a paragraph or a cell from one document and build it into a new document. However, there is a technique that you can use. You can make a temporary copy of your source document, and then execute some code to 'pare down' the content to just the content that you want. You need to make sure that you pare down the content in such a way that you still have valid WordprocessingML. You can, for instance, pare down so that all that remains is just the contents of a cell - the paragraphs, runs, references to images, styles, and etc. You can then use this pared down document as one of the sources of DocumentBuilder, and if you use DocumentBuilder in the fashion detailed in the video, you can effectively move the contents of one cell from a source document into a cell in the destination document.
If possible, I'll put together a quick screen-cast on this.