Create MS Office Documents with Toolset
There has been some recent interest in whether the Toolset could be used to create MS Office documents. So being the adventurous guy that I am, I set off to see whether it could be done. And I’m pleased to say it’s possible and really straight forward.
Imagine you were building out an employee on-boarding process using the Toolset. At some point in the process, a user needs to generate an On-Boarding Form that will be used by IT to do things like order a laptop, setup the user in AD and grant access to one or more systems.
The user could simply go to a grid display for all new employees. They would click on an icon that will then invoke MS Word with the employee details already merged into the document. This could be printed or emailed to the appropriate people.
This article is focused on setting up the provider needed when the user clicks on the icon. There are other articles in the community on how to setup a grid display with icons. In our use case above, the icon would simply leverage the provider that you will create using the steps below.
Here are the steps for creating the provider needed to create the Word ML:
1) Create your Toolset provider using a SharePoint Data Provider if your employee content exists in a SharePoint list. Or use the External Data Provider if your employee information resides in an external data source like SQL Server. If you need help setting up your provider, there are a number of community articles and related videos on how to setup a Toolset provider.
2) Create your document in MS Word formatting the way you want the document to look when the Toolset provider creates it. The placeholders in bracket are where you want dynamic content to come through the Toolset provider. More on that in a moment.
3) Now save your document as a Word XML Document. In our example below we are saving it using the Word 2003 XML Document file type.
3) It’s time to move on the XSLT needed to insert our dynamic content into the Word XML that you just saved in the previous step. You will need to have an XSLT file that contains the following XSL. Be sure to change the <xsl:for-each select=”/NewDataSet/Table1”> to the node structure of your provider. NewDataSet/Table1 is the default node structure for a SharePoint Data Provider. NewDataSet/Data is the default node structure for an External Data Provider. Be sure to reference your actual provider for its node structure.
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output method="xml" indent="yes" standalone="yes" /> <xsl:template match="/"> <xsl:for-each select="/NewDataSet/Table1"> [Insert Word XML Here] </xsl:for-each> </xsl:template> </xsl:stylesheet>
4) Now you cut and paste the Word XML into this XSL file. You don’t need the xml declarations at the top. So just highlight everything except the first two lines and insert into the XSL file a the appropriate location where you see [Insert Word XML Here] in the code snippet in the previous step. Save your XSLT file.
Word XML file:
XSLT file after copy and paste:
5) Now replace all your placeholders in the XSLT that came over from your Word XML with the appropriate xsl statement for selecting values in your provider. Once you have replaced all your placeholders and saved the file, you’re ready to move on to the next step.
6) If you are using a SharePoint Data Provider, you will need to create a Mashup Adapter that uses your provider and applies the XSLT file you created in the previous steps. If you don’t know how to create a Mashup Adapter, there are articles in the community on how to do this. Note: this step can be eliminated in the 1.5 release of the Toolset. The SharePoint Data Provider prior to 1.5 is not outputting the encoding XML declaration that is required by Word ML to process correctly. If you are reading and using Toolset 1.5, you can skip this step.
7) If you are using an External Data Provider or the SharePoint Data Provider starting with version 1.5, you will need to complete this step.
If you’re using a SharePoint Data Provider, create an external data provider HTTP Post connection that references your provider.
<Data> <Name>EmployeeOnBoarding</Name> <Default>false</Default> <ConnectionType>HTTP Post</ConnectionType> <HttpPostURI>Insert URL to your SharePoint Data Provider</HttpPostURI> <UseCurrentUserCredentials>2</UseCurrentUserCredentials> <UserName>%CWUserID%</UserName> <Password>%CWPassword%</Password> <XslStylesheetLocation>Insert URL to your XSLT file created in step 4</XslStylesheetLocation> <OutputType>application/msword</OutputType> </Data>
Reference the URL to your SharePoint Data Provider in the HttpPostURI node.
In the XslStylesheetLocation Node, you will reference the URL for the XSLT file you create in step 4.
The OutputType node tells SharePoint to treat the output of this provider connection as a MS Word document. So rather than opening the aspx page for the provider as XML, it will invoke MS Word. There are a number of content types that can be used here. There will be a separate list of these content types posted to the community at a later time.
If you are using an External Data Provider to grab your employee details, you would just need to add the XslStylesheetLocation node and OutputType node as they are above into that connection.
Provider output without the OutputType node applied.
When you add the OutputType node, the provider will invoke MS Word.
You have successfully setup a Toolset provider to create MS Word documents. Imagine the possibilities. Of course, you need to implement this provider in a user display like a grid. So when they click on an employee, it leverages your provider to create the MS Word document. There are some helpful articles in the community on how to do this.


Buy:Zyban.Prevacid.Human Growth Hormone.Accutane.Lumigan.Retin-A.Arimidex.Valtrex.Mega Hoodia.Prednisolone.Zovirax.Actos.Nexium.Synthroid.100% Pure Okinawan Coral Calcium.Petcam (Metacam) Oral Suspension….