It looks like I can get a list of Merge Fields
from the PlexOfCps data structure.
If I traverse the list of Nodes and convert the Byte Array
into a FieldDescriptor, I can look for a Field Boundary Type
of 19 and a FieldType of 59 to find the Merge Fields.
To get the field Name, I am parsing the Text to the data.
Does this sound right??
Now the next step it to update the field with the right values to generate
a new document. How is this typically done? Directly inserting the values
into
the text stream??
Thanx Joe
Here is the code I added to the HWPFDocument
PS ... Some of the FieldBoundaryTypes equal -107, which is not
defined ... any ideas why??
PlexOfCps plc = new PlexOfCps(_tableStream, _fib.getFcPlcffldMom(),
_fib.getLcbPlcffldMom(), 2);
for (int x = 0; x < plc.length(); x++)
{
GenericPropertyNode node = plc.getProperty(x);
FieldDescriptor fld = new FieldDescriptor(node.getBytes());
if (fld.getFieldBoundaryType() == fld.FIELD_BEGIN_MARK) {
if (fld.getFieldType() == 59) {
System.out.println("Got A Merged Field");
String mergeField = getRange().text().substring(node.getStart
()+1, node.getEnd());
String fieldName = mergeField.substring((mergeField.indexOf
("MERGEFIELD")+12),(mergeField.indexOf("\\*")-2));
System.out.println (fieldName);
}
}