I haven’t seen much information on the web regarding how to automatically create Word documents in SharePoint and how to pass list item fields directly into a document.
It’s fairly straightforward to get this working (certainly no code is required, just SharePoint designer) and the technique could be used to automate all manner of business processes. For example, you could create an ASPX page containing drop down fields and calculated fields that automatically creates a quotation document or you could have a form that captures all the details for a job vacancy that would create a standard looking job advert.
In this exercise I will keep things simple and create an application that creates a certificate with an exam name, user name and pass mark passed into the Word documents from a list item. This would make a nice addition to the Quiz Web Application exam. This example requires Word 2007.
Here is an example of the created document with fields (the name, the exam title and mark – shown below in bold, being variables stored in a SharePoint list.
The example has the following components:
· A document library which has a Word document associated which is used as the basis for all new documents
· A list containing the fields that we want to pass into a new document
· A workflow which creates a new Word document and copies the fields from the list into the document
A document library is really just a special type of list. There are some differences in functionality but many of the features remain the same.
First we need to create a new document library, in your browser:
· (Top right) Site Actions > Create
· Select “Document Library”
· Name: Certificates
· Ensure the “Document template” is set to “Word document”
Next we want to add some columns to our document library for our variables to be added to
1. Click on the “Settings” button in the list view
2. Click on “Document library settings”
3. Click on “Create Column
Add the following columns:
Single line of text
By default, the Title column has already been created in the list so we will use that to store our Exam title field. There are some other columns in that are created for a document library that we will not need to use.
Next we want to create our word document which will act as a template for all newly created documents in this library. I am a little reticent to use the word template as we will actually just create a normal document (DOT / DOTX) rather than a Word template (DOT / DOTX).
In the settings screen of the document library:
1. Click “Advanced Settings”
2. Click “(Edit Template”)
Word will open the file template.dot which is located in the forms library of your document library.
3. Save the file as a “Word document” (click okay if you are asked to confirm)
This saves the template document from Word 97-2003 format (compatibility mode) to Word 2007 format which is a DOTX file. This allows use the document property field. Note we are also saving the file as DOCX and not DOTX (which is a word template file and will not work).
We need to associate our document library with the new file, to do this:
1. Document library > List settings > Advanced settings
2. Change the template name to “template.docx”
Now we are ready to create the template for our certificate, go back into the Document Library > List Settings > Advanced settings and click on the Edit Template link.
You can create a nice looking document leaving space for where our list fields will go. When you are ready to insert our fields, do the following:
1. From the main menu select “Insert”
2. Click “Quick Parts” > “Document Properties”
3. You will see a list of the document properties including the columns we added (Score and YourName)
You can select each of our fields and place them in our document – YourName, Score and Title are the three fields we will insert.
4. Insert each of the fields into your document, they will display like this:
Here is an example of the basic layout:
And here is something a little fancier.
That completes the creation of the document library and the associated word document.
We need to create a list to store our values that will be inserted into the document template.
As you can imagine, this is very straightforward:
· Site Actions > Create
· Custom List
· Name: Documents
· Click Create
Then add our two fields into (Title will already exist)
Add the following fields to the Documents list Add the following columns:
You will notice this is exactly the same as what we did for the document library fields. Our final step is to create a workflow that copies the fields from the Documents list into a new document in the Certificates document library.
We are going to create a simple workflow that does the following
· When a new item is added to the Documents list create a new Item in the Certificates library
· Copy the title, YourName and Score fields from the Documents item into the Certificates item
This will in effect create a new document in the Certificates library that has the fields automatically populated with the values from our Documents list. Here is how:
1. Open SharePoint designer and connect to your site
2. File | New | Workflow
We are saying here, each time a new item is added to the Documents list then run the workflow.
3. Click “Next”
4. Click “Actions” > “Create List Item”
5. Click on the “this list” link
6. On the list selector choose “Certificates”
7. Click on the “Name (for use in forms) ...” entry and click “Modify”
8. In the value box, click the “Fx” button
9. Keep the source as “Current Item” and change the field to “YourName”
10. Click OK, OK
The above steps mean that when a item is added to the list Document then a new document will be created in the Certificates document library and the name of the item will be set to YourName feild.
If more than one item is created with the same name then a unique identifier will be automatically added to the title.
Next we need to add our three fields to the Create List Item action. To do this:
1. Click the “Add” button
2. Set this field: Score
3. To this value: Click the “Fx” button
4. Source: Current Item
5. Field: YourName
Do the same for the Title and YourName values. Your completed List Item dialogue should look like this:
You can now click “OK” and you will see SharePoint designer create the new Workflow and assign it to your list.
We are now all ready to test our new solution!
Go back to our website and select the “Documents” list and click “New” and complete the fields and click “OK”
Back in the list of items in the Documents list you will notice a new column “Make a new Certificate” has appeared. This column shows the status of the workflow that we created.
Currently it will be showing “In Progress” whilst the workflow kicks and begins to run (creating the new word document in the Certificates library). Wait for a few seconds and then refresh the page (F5). You should see the status has changed to “Completed”
Finally, switch to the Certificates document library. You will see our new document has been created. When you open the document you will see that values that we passed are now contained in the Word document.
Thank you so much for creating this it helped me out a ton! I found what it was
2. Change the template name to “template.dotx”
I had to change it to "template.docx" and the it worked. Thanks again!
Thanks Terry - you are right, the file cannot be a template (DOT) file. I've updated the post which hopefully makes this clear. I'd be interested in the kind of furture posts you would like to see?
Is there a way to do an iteration over many list items to create one document that contains MANY Name, Title, Score records?
Thanks & Ciao
Hi Vincenzo - take a look at http://msdn.microsoft.com/en-gb/library/cc197932.aspx for a way of achiving this.
I must say that your information is very useful and to the point, good work.
I am facing challenges while starting of workflow as per your described steps, when I have selected workflow start options as “Item Created” or “Item Changed”, then also my workflow didn't start on any steps, then I have to start my workflow manually, for generating word 2007 file, do I miss any points? I didn't understand what's wrong in one simple steps of designer workflow.
Is it possible to achieve same functionality with word 2003 documents? Because I have observed that in word 2003, we don't have capability to add document properties fields.
Thank you very much for your help.
Thank you for the interesting article. I had a similar requirement where I would need to autopopulate "Customer Name" and "address" from a sharepoint list into a word document. Followed the details above, but have a formatting issue.
I need to autopopulate two fields
Firstly there is a space between Customer Name and Address which should not happen.
Secondly the address part of the text gets greyed out. Would want it in black normal font.
If you could help me solve these issues, it would really helpful. Just concerned about formatting
this tutorial works very fine, we have just one Problem. I used a rich text field with formated text an in the final Word document all html tags like <strong>Stammdaten </strong> are shown. Are there any way to copy the field with the correct formatting and without the tags?
Thanks for any ideas
How about something similar...
what if I want to print a book from a document library. think of the Employee Manual, autocreated from a doc library.
I can do it with code, but not sure how far we can take Workflows. I also figure we need to do some extra magic in Word like creating a TOC on the fly.
Is this an OBA? Any suggestions?
This is a very usuful article.
sanketshah_18, try the instructions in the following link to see if it solves your problem;
Great post, thank you. Does this work if one of the columns in your list is a 'look up' column type, that is grabbing items from another list in your site.
Another question. Not everyone in our office has Office 2007. Can I set up a workflow to automate the saving of my new docx created to a doc?
Hi @Nancydeb - as far as I know this can only be achived in Office 2007 onwards. Sorry about that.
Hi @ Nancydeb,
I faced the same requirement as you, my client doesnt have 2007 . So i come up with an idea to again convert the document as webpage (You can see the below link how to do it.) It solved my purpose.
My list has a "Link to Picture/image" , requirment is that the image should also be part of the document created. Will it be possible? Any help would be highly appreciated.
Thanks in advance.
Great post, good information. Of course, it's never enough... Ughhh! I have a question / issue related to the above.
I have created a workflow similar to yours, and I was wanting to have some fields remain optional.
i.e. First Name, Middle Initial, Last Name
If the user does not have middle initial, and the field is left blank, the final document has the vacant field printing or at least showing up...
Do you have a solution for this?