Integrating with Microsoft Office
PAW allows you the pull data from Microsoft applications through the use of VBA type calling through COM scripting. This can be done through the "Add calculated field" functionality which allows use of Groovy for this integration.
Microsoft Word Example
Most content generation takes place in Office and Word, and you might need to publish the information online and want to store it as HTML documents for easier access. You can pull the list of .doc files in a specific folder and create HTML versions for those files using the sample code below.
import org.codehaus.groovy.scriptom.ActiveXObject
import java.io.File
def wordFile = "c:\MergePressRelease.doc"
def htmlFile = wordFile - ".doc" + ".html"
def word = new ActiveXObject("Word.Application")
word.Documents.Open(new File(wordFile).canonicalPath)
word.ActiveDocument.SaveAs(new File(htmlFile).canonicalPath, 8)
word.Quit()
return htmlFile
Integrating with Microsoft Outlook
You might be using Outlook to receive customer emails and either need to report on them or pull some data contained in the emails. In the example below, you can pull out the subject line for an email as well as the body.
import org.codehaus.groovy.scriptom.ActiveXObject
def outlook = new ActiveXObject("Outlook.Application")
def namespace = outlook.GetNamespace("MAPI") // There is only "MAPI"
// 6 == Inbox; other values in Outlook's VBA documentation
def inbox = namespace.GetDefaultFolder(6)
//def account = namespace.GetFolder("imap.google.com")
//def accountFolder = account.GetFolder("Inbox")
def mails = inbox.Items
def list = []
for (i in 1..mails.Count.value) {
def mail = mails.Item(i)
if (mail.Subject =~ "Survey Response")
list.add (mail.Subject + "|" + mail.Body)
}
return list
Additional references
These articles on the web may change over-time and we cannot guarantee the continued accuracy of the information, but contain good additional tips.- Examples from Groovy - http://groovy.codehaus.org/COM+Scripting
- Examples from Groovy Scriptcom 1.2 - http://groovy.codehaus.org/Scriptom+1.2
- Writing VBA code for Microsoft Outlook - http://www.outlookcode.com/article.aspx?ID=40
- Accessing Folders and Items in Microsoft Outlook - http://support.microsoft.com/?kbid=208520
- Siebel COM programming with Groovy - http://jbrazile.blogspot.com/2008/03/siebel-com-programming-with-groovy.html
