In Word API there is the ability to manage custom document properties. You
can access them via _Document.getBuiltinDocumentProperties() method:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._docum
ent.builtindocumentproperties.aspx
or _Document.getCustomDocumentProperties() method:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._docum
ent.customdocumentproperties.aspx
Sincerely,
Serge
According to this support article:
http://support.microsoft.com/kb/303296/en-us "DocumentProperties and the
DocumentProperty interfaces are late bound interfaces. To use these
interfaces, you must treat them like you would an IDispatch interface."
This probably explains why you were not able to invoke methods of that
object via appropriate interface, which in fact is early binding technique.
So, in this case I suppose you can use Automation to access fields and
method of that object, like it's demonstrated in the example below:
IDispatch properties = workbook.getBuiltinDocumentProperties();
// IDispatch properties = workbook.getCustomDocumentProperties();
boolean useCurrentThread = true;
Automation propertiesAutomation = new Automation(properties,
useCurrentThread);
Variant propertyCount = propertiesAutomation.getProperty("Count");
int count = (int) propertyCount.getLVal().getValue();
System.out.println("count = " + count);
for (int i = 1; i <= count; i++) {
Variant item = propertiesAutomation.getProperty("item", i);
Automation itemAutomation = new
Automation(item.getPdispVal(), useCurrentThread);
try {
Variant itemName =
itemAutomation.getProperty("Name");
System.out.println("itemName = " +
itemName.getValue());
Variant itemValue =
itemAutomation.getProperty("Value");
System.out.println("itemValue = " +
itemValue.getValue());
} catch (AutomationException e) {
ExcepInfo information = e.getExceptionInformation();
System.err.println("description: " +
information.getBstrDescription());
}
itemAutomation.release();
}
propertiesAutomation.release();
I also would like to notice that it's not necessary to use
OleFunctions.oleUninitialize(); at all, because it may interfere with
automatic memory management in ComfyJ.
Please let me know if you have another questions.
Sincerely,
Serge
> -----Original Message-----
> From: comfyj...@teamdev.com [mailto:comfyj...@teamdev.com] On
> Behalf Of venkky venkky
> Sent: Thursday, March 10, 2011 9:20 AM
> To: ComfyJ Forum
> Subject: Re: How to Set and Get Custom Properties to a word document
>
> Hi,