You can do it using an add-in written in for instance C#. With VSTO, you can easily and reliably download facts from most databases and put them in custom properties. An alternative is the use of Invantive Composition, which allows you to do this by specifying it in a model of the template, see this model definition: . Please note that I work at the company that made it, so I'm biased.
If you want to go down the road with C#, use code similar to in for instance ApplicationUtility.cs of your project (code taken from Invantive Control, but put in public here for your convenience):
Getting property value
private object GetWordBuiltInProperty(_Word.Document wordDocument, _Word.WdBuiltInProperty property)
{
try
{
if (wordDocument != null)
{
return wordDocument.BuiltInDocumentProperties[property].Value;
}
}
Or changing it
private void CreateDocumentProperty(_Word.Document wordDocument, string name, MsoDocProperties type, object value)
{
Debug.Assert(wordDocument != null, "Word document cannot be null!");
Debug.Assert(!string.IsNullOrEmpty(name), "Name cannot be null!");
object property = this.GetDocumentProperty(wordDocument, name);
if (property == null)
{
Type t = wordDocument.CustomDocumentProperties.GetType();
t.InvokeMember("Add", BindingFlags.InvokeMethod, null, wordDocument.CustomDocumentProperties, new object[] { name, false, type, value });
}
}
private void CreateOrReplaceDocumentProperty(_Word.Document wordDocument, string name, MsoDocProperties type, object value)
{
Debug.Assert(wordDocument != null, "Word document cannot be null!");
Debug.Assert(!string.IsNullOrEmpty(name), "Name cannot be null!");
object property = this.GetDocumentProperty(wordDocument, name);
if (property == null)
{
//
// Add property.
//
this.CreateDocumentProperty(wordDocument, name, type, value);
}
else
{
//
// Set value.
//
this.SetDocumentPropertyValue(wordDocument, name, value);
}
}
private void SetDocumentPropertyValue(_Word.Document wordDocument, string name, object value)
{
object property = this.GetDocumentProperty(wordDocument, name);
if (property != null)
{
Type t = property.GetType();
t.InvokeMember("Value", BindingFlags.SetProperty, null, property, new object[] { value });
}
}