Word Document Automation Using UiPath

Word Automation Services is a new service application in SharePoint Server 2010. Word Automation Services provides unattended, server-side conversion of documents into formats that are supported by the Microsoft Word client application.

In simplest terms, Word Automation Services takes the Save As functionality of the Word client application and replicates it for the server. Specifically, Word Automation Services helps in Opening the documents that Word can open, including:

  • Open XML File Format documents (.docx, .docm, .dotx, .dotm).
  • Word 97-2003 documents (.doc, .dot).
  • Rich Text Format files (.rtf).
  • Single File Web Pages (.mht, .mhtml).
  • Word 2003 XML Documents (.xml).
  • Word XML Document (.xml).

Supports all automatic tasks that execute when a document opens, such as :

  • Updating the Table of Contents, the Table of Authorities, and index fields.
  • Recalculating all field types.
  • XML mapping.
  • Merging of alternate format chunks.
  • Setting the compatibility mode of the document to the latest version or to previous versions of Word.

Saves documents types that Word can save. This list is identical to the previous list of files that the Word Automation Services can open, but also includes the following types:

  • Portable Document Format (PDF) files.
  • XML Paper Specification (XPS) files.
  • With Word Automation Services, tasks that previously required you to run the Word client application can now be automated to run unattended in a more reliable and scalable way than in previous solutions.

Word automation also supports to perform the following activities:

  • Adding Picture to Word Document
  • Replace the picture in the word document
  • Repeat text in the document by using append text activity.
  • Export text from a word document to the PDF
  • Inserting a Data table into the Word document.
  • Read text from the Word document
  • Replace text in the word document
Example 1.

The following example demonstrates the creating Word Document and adding Text and Images to the document

Create a new process as Word Automation Example
word-automation-example

Once the process opened in the UiPath Studio, Install UiPath.Word.Activities from Ofiicial under Manage Packages as shown below.
install-word-activity-rpa-uipath

Now, UiPath.Word.Activities installed all the activities which are related to Word.
word-related-activities-rpa-uipath

Add Sequence to the Designer pane and then add Word Application Scope activity. As the name itself says you have to do whatever the activities you wanted to do for a word document inside the Word Application Scope activity.

The Word Application Scope activity will fetch the document once you give a filename. If the filename given does not exist then this will create a new document and fetches it.
adding-word-application-scopr-activity-rpa-uipath

I am going to create a new file(word document) using the Word Application Scope(C:UsersUserDocumentssamplessampledoc.docx). To create a new file we have to provide the file path which does not exist.
creating-new-doc-rpa-uipath

Add the Append Text activity inside the Word Application Scope activity and add the text inside the Append Text activity as Welcome to UiPath Studio and then save and run the sequence.

adding-append-activity-rpa-uipath

Once the sequence starts to execute, the Sampledoc.docx file will be created which contains the text Welcome to UiPath Studio.
sampledoc-file-created-rpa-uipath

Next, add Add Picture activity inside the Word Application Scope activity to add a picture inside the Document.
add-picture-activity-rp-auipath

Add the Picture path by clicking on the three horizontal(...) dots and select the picture you wanted to add. As soon as you select the picture, the picture path will be identified by the picture path in the property pane.
word-automation-example-picture-path

Save the sequence and run, Once the sequence starts to execute, the picture will be added to the document.
picture-added-in-the-doc-rpa-uipath

As many times as you run the sequence, the image and text will be added every time. Once again if you run the sequence you can see two text and two images in the document.
two-text-two-images-rpa-uipath

Example.2:

Replacing text in the word document by using the replace text activity by creating another sequence called Test_Sample_one
test-sample-sequence-rpa-uipath

Add the Word Application Scope activity and add the Document path(C:UsersUserDocumentssamplessampledoc.docx). Let us replace the text in the document by using the Replace Text activity and add the same inside the word application scope activity.

Enter the old text(Path) you wanted to replace in the first box and enter the new text(Root) you wanted to replace with the second box as shown below.
replace-text-rpa-uipath

Save and run the sequence. Once you run the sequence, the text Path will be replaced with Root as shown below.
replaced-text-rpa-uipath

Example.3:

Export text from Word document to PDF.

Create a new sequence called Export_to_PDF
word-automation-example-export-to-pdf

Add the Word Application Scope inside the sequence and then add the sampledoc.docx document path("C:UsersUserDocumentssamplessampledoc.docx") inside the word application scope activity as shown below.
word-automation-example-export-to-pdf-sample

Add Read Text Activity inside the Do container of the Word Application Scope Activity. Create a variable in the Property pane as doc2text.
word-automation-example-read-text

Set the scope of the variable doc2text to broad(that means the scope of the variable is extended to the whole sequence). Select Export_to_PDF as the scope for the variable doc2text under the Read Text activity
word-automation-example-export-to-pdf-2

Add Export to PDF activity inside the Word Application Scope and enter the path of the new file which is going to create in it as shown below.
word-automation-example-export-to-pdf-3

Save and run the sequence, Once the sequence starts to execute, the Text and Image from the word document will be extracted into the samplepdf file.
word-automation-example-export-to-pdf-completed

Example.4:

The following example demonstrates extracting text from word document to a pop-up message

Create a new sequence called Export_to_Message_Box
word-automation-example-export-to-message-box

Add the Word Application Scope inside the sequence and then add the sampledoc.docx document path inside the word application scope activity as shown below.
word-automation-example-export-to-message-box-2

Add Read Text Activity inside the Do container of the Word Application Scope Activity. Create a variable in the Property pane as doc2text.
word-automation-example-doc-text

Set the scope of the variable doc2text to broad(that means the scope of the variable is extended to the whole sequence). Select Export_to_PDF as the scope for the variable doc2text under the Read Text activity.
word-automation-example-export-msg

Add the Message Box activity inside the sequence(Outside the word Application scope) and enter the variable name(doc2text) inside Message Box.
word-automation-example-2

Now, Save the Sequence and run, Once the sequence starts to execute the text which is present in the Document will be pop-up in the message box.
word-automation-example-message

0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions