Welcome to APLNext Sign in | Join | Help

Getting form field values from a pre-existing Microsoft Word document

NOTES:

(1)   In this blog-representation of my script, text like <apl_char> is used because some APL characters are not properly represented by the fonts included in the blog software.

(2)   Using VSTO2005 is another way to read form fields. There are screen casts which illustrate using VSTO2005 to do virtually anything with Microsoft Office.

(3)   The appropriate versions of the Microsoft Office interops (.dlls) must be installed on the end user's machine for this script to operate properly.

(4)   It is assumed that form fields have been inserted in the Microsoft Word document using the standard Word end-user application tools.

// Script: MSWord_Read_FormFieldValues created on 3/31/2007 4:26:17 PM by Joe Blaze

using System

refbyname Microsoft.Office.Interop.Word

using Microsoft.Office.Interop

using Word=Microsoft.Office.Interop.Word

using System.Runtime.InteropServices

public ∇Z←GWFVs FNM{

// e.g. FNM = @"c:\myWordDoc.doc"

Z←0<reshape>⊂""

:IF <not>""<match>FNM

M=Type.Missing

wordapp = new Word.ApplicationClass()

:IF <not>null == wordapp

//If you'd like to have something happening on the screen, include: wordapp.Visible=1

D = wordapp.Documents.Open(FNM,M,M,M,M,M,M,M,M,M,M,M,M,M,M,M)

flds=wordapp.ActiveDocument.FormFields

e=flds.GetEnumerator()

:WHILE true==e.MoveNext()

Z←Z,⊂e.Current.Result

//^ Z: The result of this function is a nested vector of text vectors containing the form field values from the document.

//^e.Current.Result = "MyText" can also be used to set the form field values if desired.

:ENDWHILE

OSC=false

//^OSC: false: Do not save current document when quitting Word

OF=Type.Missing

RD=Type.Missing

X=wordapp.Quit(OSC,OF,RD)

:ENDIF

:ENDIF

}

Published Saturday, March 31, 2007 2:08 PM by joe.blaze

Comments

No Comments
Anonymous comments are disabled