次の方法で共有


Automatically create Word documents which include list fields

Creating Word documents containing List fields

 

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

 

Creating the document library

 

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:

Name

Type

YourName

Single line of text

Score

Number

 

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.

Creating a Word document to use as a template

 

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”

3. OK

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.

Creating a list to store our fields

 

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:

Name

Type

YourName

Single line of text

Score

Number

 

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.

 

Writing our workflow to create new documents in the certificates 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

 

 

 

  • Give the name as “Make a new certificate”
  • Attach “Documents” list to this workflow.
  • Select “Automatically start this workflow when a new item is created”

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!

Putting it all together – testing our 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.

Comments

  • Anonymous
    January 01, 2003
    Hi, 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. Thanks, Sanket Shah

  • Anonymous
    January 01, 2003
    Anyone link this to the fab40 Employee Training template? The two lists are the courses and registrations lists within the Employee Training Template that is part of the Fab40 for SP2007.  The OOTB design is that upon registering for a course an entry gets created in the "hidden" Registration list with a lookup to the to the Courses list via the Course ID field.  What I am trying to do is also copy the following fields for that registration into the Registrations list: • Location   • Course Title   • Course Completion Date So I can then drive certificates off that list. Thanks in advance.

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    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.

  • Anonymous
    January 01, 2003
    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?

  • Anonymous
    January 01, 2003
    This workflow works great. This is kinda technical but is it possible to allow the workflow to submit by someone with access via a link or button? In other works if someone isn't logged in and they try to submit they get an error message. So I'm trying to get it that when anyone whether logged in or not can go to the list and fill in a new entry and submit without receiving an error. And later when somone who has access can pull up the entry or entries and submit them to the wrokflow if they choose. Any feedback would be helpful, thank you. Chris.

  • Anonymous
    January 01, 2003
    This great. 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 Vincenzo

  • Anonymous
    January 01, 2003
    Hi Vincenzo - take a look at http://msdn.microsoft.com/en-gb/library/cc197932.aspx for a way of achiving this.

  • Anonymous
    January 01, 2003
    HI, 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 britta

  • Anonymous
    January 01, 2003
    Great Article, even after 3 1/2 years! I used this article to setup Document Generation in SharePoint 2010 and for the most part everyhting was the same. I had some difficulty at first (associating) the template to the Doc. Lib. I ended up deleting the D.L. and creating a new one. This will be a BIG time saver for one of our departments that generates LOTS of correspondence.

  • Anonymous
    January 01, 2003
    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?   Thanks.

  • Anonymous
    January 01, 2003
    hi all. Thank you so much for creating this tutorial. its great! but, actually i got the problem. i already followed the steps, but in the end when i try to open the document, the values that i already keyin are not contained in the word document. the values are saved to the column/field only. anyone can help me? pleaseeeeee

  • Anonymous
    January 01, 2003
    The comment has been removed

  • Anonymous
    January 01, 2003
    How can i do this with vs workflow inside sharepoint hosted app?

  • Anonymous
    January 01, 2003
    Hi @Nancydeb - as far as I know this can only be achived in Office 2007 onwards.  Sorry about that.

  • Anonymous
    January 01, 2003
    Thanks for this blog post. This is really a cool idea to create Word reports from List data.

  • Anonymous
    January 01, 2003
    This is a very usuful article. sanketshah_18, try the instructions in the following link to see if it solves your problem; http://support.microsoft.com/kb/947284 Thanks.

  • Anonymous
    January 01, 2003
    Here is good example on how to update Word document in the workflow using SharePoint designer: www.harepoint.com/.../Example-Invoices-PDF-Conversion.aspx

  • Anonymous
    January 01, 2003
    Thank buddy! That was a great step by step guide which saved my day! Cheers!

  • Anonymous
    January 01, 2003
    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?

  • Anonymous
    January 01, 2003
    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?

  • Anonymous
    January 01, 2003
    Great post.quite helpfull

  • Anonymous
    January 01, 2003
    hi 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 Customer Name Address 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

  • Anonymous
    January 01, 2003
    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.

  • Anonymous
    January 01, 2003
    Would love to know if anyone got this working in SharePoint 2013, I keep getting an error that says "Sorry, Word Online ran into a problem opening this document. To view this document please open it in Microsoft Word." I do this and it is blank

  • Anonymous
    January 01, 2003
    Thank you so much for creating this it helped me out a ton! I found what it was

  1.       Change the template name to “template.dotx” I had to change it to "template.docx" and the it worked. Thanks again!
  • Anonymous
    January 01, 2003
    Hello all, Nancydeb: AFAIK you still can save documents to DOCX format - clients just need to install Microsoft Office Compatibility Pack -http://www.microsoft.com/downloads/details.aspx?familyid=941b3470-3ae9-4aee-8f43-c6bb74cd1466&displaylang=en . I think word 2003 with this addon should be able to read generated DOCX files. Another thing about "look up" column. We have created a solution to generate docs using a little bit different approach. Free version have feature to add up to 3 lookup items (commercial have no this limitation). If you are interested - you can try it here:http://www.sharepointdrive.com

  • Anonymous
    July 14, 2010
    Hello, nice tutorial. I've hit on a snag though - I can create new documents by hand with no problems, but when I try to do it in a workflow, the resulting document will not open in Word, giving an error message: "The file whatever.docx cannot be opened because there are problems with the contents. - No error detail available." I was wondering if anyone else got the same error and maybe found a way around it ? Regards.

  • Anonymous
    July 27, 2010
    Hello, I've got the same problem as Piotr. "The file whatever.docx cannot be opened because there are problems with the contents. - No error detail available". If the Library  is set to compatibility 2k3, the file docx are still generated and can be opened but the fields are obviously blank. A solution? Regards

  • Anonymous
    August 13, 2010
    I think i have a similar problem to both Piotr and MRVirtual. When the document is created it doesn't create a Word file but an xml file. Do you know why this might be please?

  • Anonymous
    August 13, 2010
    Apologies, figured it out. I was accidentally setting the name to the name of the infopath form which had an xml extention

  • Anonymous
    October 11, 2010
    The comment has been removed

  • Anonymous
    December 20, 2010
    I'm using this solution to complete a word document with values from sharepoint lookup columns. the thing is instead of the actual value that i select frim the dropdown in the DIP panel, in the docuemnt I get the ID number of the ITEM. Does anyone know what could be wrong with my template or my loook up columns?? ANy help wuold be much appreciated

  • Anonymous
    February 28, 2011
    The comment has been removed

  • Anonymous
    April 08, 2011
    Great article!!! I also have to mention that I got working this by setting docx in library settings as template format! thanks http://ekoncis.blogspot.com

  • Anonymous
    May 04, 2011
    Has anyone been able to do this in SP 2010?

  • Anonymous
    May 08, 2011
    Hi, Great article!!! I am getting the beloww error in the workflow, which I am attaching to list item creation: Unknown Server Error: d Any thoughts on this? Thanks In Advance.

  • Anonymous
    May 20, 2011
    Thanks you so so much, It was very helpful

  • Anonymous
    July 06, 2011
    i am a blogger everyday i browse different types of articles to get lots of new tips while i was browsing,i found ur blog your article is really awesome.Thanks for sharing such nice article here.i also want to share valuable how to build a list tips.

  • Anonymous
    July 22, 2011
    @Matt: Yes, I did it in SP 2010, it works the same way as described above only the user dialogues lock a bit different. However I am still facing one problem: Creating a new document with the SP-liste metadata runs pretty smooth but when I try to update the data it will overwrite all meta-data in the document with empty values....even though I selected to replace files in case they have the same file-name. Anybody an idea on this ?

  • Anonymous
    July 27, 2011
    Works like a charm - the only problem I have, is that I would like in word to have formatted fields - lets say I create automatically an invoice. Regardless what the format in the sharepoint list is, the number 1'000.00 will only be displayed as 1000 in the so generated word file. I tried all the different functions and formatting in the sharepoint lists, but somehow word does its own formatting.

  • Anonymous
    August 05, 2011
    I have tried the steps Using word 2010 and Sharepoint 2010 and when I re-refesh after In Progress I get Error Occurred. any ideas why?

  • Anonymous
    August 30, 2011
    Hi! This works really fine. Is there a way to have the word document updated with new data if you change an item in the list? And the other way around update the list if the document changes? TIA!

  • Anonymous
    January 25, 2012
    Has anyone found a solution for keeping the rich text souce column formatting and inserting to the template with the format retaind and no tags?

  • Anonymous
    May 29, 2012
    Hi! I got through the setup of the list and the library.   When trying to setup the Workflow I am not seeing any of the same screens.  I have SharePoint 2010.  Do you have instructions on how to set this up in SharePoint 2010?  Thanks, Jo.

  • Anonymous
    May 29, 2012
    Hi - I have SharePoint Designer 2010.  Do you have the Workflow instructions for it?  Thanks, Jo

  • Anonymous
    June 05, 2012
    Hello.  Thank you for this awesome walk-through!  I was able to get the functionality to work, however, when the document is created, one of the fields appends the HTML tags, but none of the others do.  is there a quick fix, or have you encountered this before? Thanks!  

  • Anonymous
    February 27, 2013
    Awesome feature and a TOTAL time-saver for me!!  I have one question though, is there a way to continue to update the same document rather than generating a brand new document for every change to the list item?   Thanks!

  • Anonymous
    March 18, 2013
    The comment has been removed

  • Anonymous
    May 14, 2013
    Great post, works very well in top level sites, but i tryed it in a workspace & it doesn't work. I created a workspace by adding a calendar item & clicking the option "workspace" & i followed your procedure, doesn't work !!! HELP !!!

  • Anonymous
    May 28, 2013
    Hello I followed the instructions and it worked for SP2010 but did not work for SP 2013 please help thanks

  • Anonymous
    June 26, 2013
    This helped a ton! Now I'm trying to link a checklist to the options from another checklist. Is there a way to access the options in a checklist? Essentially I'm trying to nest a checklist within another. Thanks

  • Anonymous
    October 29, 2013
    Great post.  Does anyone know how to prevent empty fileds frmo displaying the [fieldname] on document.  I wish to have empty fields not show anything.  Thank You

  • Anonymous
    November 14, 2013
    This is exactly what we needed. Thanks for sharing. Question: Can we do this for a different file format (i.e. powerpoint etc)? Thanks again,

  • Anonymous
    November 14, 2013
    This is exactly what we needed. Thanks for sharing. Question: Can we do this for a different file format (i.e. powerpoint etc)? Thanks again,

  • Anonymous
    November 27, 2013
    for SharePoint 2013, the generated document will be empty and not using the specified template. Please share if this worked on SharePoint 2013

  • Anonymous
    February 06, 2014
    Do document properties not sync up with sharepoint properties in Record Centers? The word document properties are updated through the quick parts and appear in the word properties, but the SharePoint values remain blank. I have tried and successfully repeated this process on other sites in 2010 and 2013, so the only difference I can think of is the record center part. Please advise :)

  • Anonymous
    February 20, 2014
    Excellent write up, but it does not appear to work with SP2013 (many including myself are receiving a blank word document). Is there a reason for this?

  • Anonymous
    February 21, 2014
    Very much helpful..........Thanks

  • Anonymous
    February 27, 2014
    Very helpful and well written article - I appreciate it, it is timely as I'm trying to leverage our (recently) deployed Office 2010 to finally take more advantage of our SharePoint environment... notably to generate Word documents (i.e. purchase orders) based on list or document library data.

  • Anonymous
    March 13, 2014
    This doesn't work in SharePoint Online 2013 and SharePoint Designer 2013. Can anyone please advise if somebody have managed to do it successfully? It would be helpful if you can share it in this thread.

  • Anonymous
    April 13, 2014
    Also tried this and does not work in SP2013

  • Anonymous
    April 22, 2014
    The solution to the empty resulting Word document in 2013 is to create the workflow as a 2010 workflow (not a 2013 workflow).

  • Anonymous
    May 16, 2014
    Please someone can do it work in SP online 2013???

  • Anonymous
    May 26, 2014
    Hey Guys

    My Problem is It does not want to save and file in the library. but it has the extension .000 so it is not a word document.

    Any Ideas why it would be doing this?

  • Anonymous
    May 26, 2014
    Sorry I mean it saves a file but it has the extension .000

  • Anonymous
    May 27, 2014
    Hey Guys I got it to Work.

    Let me know if you need any help. data is not blank and saves as word document.

    add me on linked in. Juan de Roock

  • Anonymous
    June 06, 2014
    This is fantastic information. Thank you so much.

  • Anonymous
    June 26, 2014
    I try to create a empty document, but when I open it an "Can't open the document because its a problem with the content". I do this with SharePont 2010 and works fine. But with SP2013 don't. PLEASE HELP!
    I try with .docx, .dotx documents, with workflow 2010 and still not working.
    If i open the document clicking "new document" everything works fine

  • Anonymous
    July 02, 2014
    Hi please you have any solution for SharePoint selection columns? This type of columns doesn't show in Quick Parts option in Word. Thanks

  • Anonymous
    July 10, 2014
    Have you tried this http://www.enovapoint.com/jungledoc/sharepoint-document-automation/ solution? I am working with it everyday and dont have any problems. Now i started to use it for reports about sales and have that information in different sites of sharepoint. Really recommend you to try this its OWESOME!!!

  • Anonymous
    August 27, 2014
    Does anyone have a solution for SP2013? It works with SP2010...but I would like to find a sustainable solution for SP2013. Thanks!

  • Anonymous
    November 05, 2014
    The comment has been removed

  • Anonymous
    December 02, 2014
    Thank you!

  • Anonymous
    January 21, 2015
    Thank you, I found this extremely useful!
    Follow up question. I'd like to add Consolidated Comments from the workflow to the Word document. It works, but as an outcome I have my comments with html tags. Do you know how to get only text without them?
    Thank you in advance,
    Polina

  • Anonymous
    January 22, 2015
    Hi, this is quite a neat solution, but I wonder if someone could help with an issue I have. If I amend/update an entry in my original list, it overwrites the document but with the original template, not with a document with the updated fields. For example, the first time I add an entry, the document created shows 'John Smith' in place of the [Name]. But if I then update the original entry, say I change 'John Smith' to 'Jon Smit', then the output goes back to [Name]. Has anyone encountered that issue? Thanks

  • Anonymous
    March 03, 2015
    Should this:
    "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)."

    be this instead:
    "I am a little reticent to use the word template as we will actually just create a normal document (DOC / DOCX) rather than a Word template (DOT / DOTX)."

  • Anonymous
    April 07, 2015
    Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    http://staygreenacademy.com/sharepoint-administrator-online-training-videos-certification-courses/">SharePoint Administration Training Online

  • Anonymous
    May 06, 2015
    Is it possible to create a word doc using this workflow, but pull fields from multiple records in the list into the same Word Doc?

  • Anonymous
    May 31, 2015
    The comment has been removed

  • Anonymous
    June 04, 2015
    Is there a way to remove empty fields name from the document?
    e.g. if this field is not filled in "Address2", you end up on the document "[Address2]".

  • Anonymous
    June 12, 2015
    This example is good and worked in Sharepoint 2010.
    The biggest problem is when you wanna play a formatted list field in Word Doc. Write all in HTML.

  • Anonymous
    June 14, 2015
    The comment has been removed

  • Anonymous
    July 07, 2015
    Thanks for that helpful post.
    How about a solution for Sharepoint 2013? Anyone came across it so far?

  • Anonymous
    August 01, 2015
    While creating the workflow when I am doing create new list item--><>, I am asked to provide value of a "Path and Name" field. It is a mandatory field, what should be its value?

  • Anonymous
    October 23, 2015
    For all looking for a more powerful and reliable solution that doesn't require installed Word, I suggest to look at Docentric Toolkit:
    http://www.docentric.com
    This is a .NET mail-merge and document generation library that allows you to design template documents in MS Word and then call a single .NET method to populate such a template by providing the template and the data. It only requires couple of lines of code to integrate into a SharePoint project/add-on.

  • Anonymous
    November 18, 2015
    I have this working on SharePoint 2013 by using a 2010 workflow and not a 2013 one.

  • Anonymous
    December 11, 2015
    Great post! Found it very useful...Thanks :)

  • Anonymous
    December 13, 2015
    we use a solution that allows you to do this from within SharePoint Lists- with now code. It works for word, excel and PowerPoint templates using the merge-field or place holders. Also a workflow available for this-https://sharepointdocumentmerge.com - it works great for us Highly recommended!

  • Anonymous
    January 05, 2016
    Hi,
    very good post, worked perfectly, but I have one little problem:

    Im using SP2010 and need this list export for automatically generated reports.
    My workflow is starting only manually for now (for testing). If I start my workflow a second time on an already generated report, the new version is totally empty. It has the correct name (which is also a field of the list) but all other information could not be received.
    (If I start the workflow a third or more times, nothing changes. So I have to delete the existing file first, if I want a new version).

    My workflow is basically the same as in the manual on this page, but I checked the 'overwrite existing file' radio-button at the workflow. I tried to change my workflow, so that it deletes first the existing file, but I got errors on that (message said I may have not the sufficient permissions, which I do).

    Any idea ?
    Thanks.