Free Support Forum - aspose.com

Regarding getting FormField Class from FieldStart Class


#1

I am using latest version of Aspose.words java product family and I am getting an fieldStart node on parsing an sample .docx file which contains form fields and I have attached that document for your Reference.FormFieldListTest.zip (9.8 KB)

I am trying to get the formField froim the current fieldStart node like fieldStart.getFormField() similar to getting field using fieldStart.getField() but I could not find any API for it
So, i tried using getRange() API to get the formField as
fieldStart.getParentNode().getRange().getFormFields().get(0);
I am exception to get the first Form field within that range but it is returning null.
I also tried getting parentNode which should be run but it is returning paragraph.

FieldStart.getParentNode().getRange().getFormFields().get(0);

I have attached my code for your referral :::
FieldStart fieldStart = (FieldStart)this.node;
FormField formField = fieldStart.getParentNode().getRange().getFormFields().get(0);
int count = fieldStart.getParentNode().getRange().getFormFields().getCount();
System.out.println(count);

It should obviously forgive count 1 as there is only one FormField inside run of the Paragraph but it gives count of 4 which is formField of entire paragraph. I expect fieldStart.getParentNode() to give run node but it gives paragraph. Is this correct ?

Requirement::
1)I need an Api to get FormField from FieldStart
Or else is there a way to get FormField from fieldStart using any other api like getRange(). I tried using getRange() but it still gives paragraph. I think it is wrong or is it the intended behavior then please explain me how ??
I dont want to get if from doc.getRange().getFormFields.get(int index) but from FieldStart
Please it is urgent!!!


#2

@Anbu2Win

Thanks for your inquiry. Unfortunately, Aspose.Words does not support the requested feature at the moment. However, we have logged this feature request as WORDSNET-17957 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.


#3

@Anbu2Win

Thanks for your patience. We have closed WORDSNET-17957 with “Won’t Fix” resolution. Following code example shows how to get the FormField from FieldStart. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");

FieldStart fieldStart = (FieldStart)doc.getChild(NodeType.FIELD_START, 0, true);

if (fieldStart.getFieldType() == FieldType.FIELD_FORM_CHECK_BOX ||
        fieldStart.getFieldType() == FieldType.FIELD_FORM_TEXT_INPUT ||
        fieldStart.getFieldType() == FieldType.FIELD_FORM_DROP_DOWN)
{
    // Try to find FormField from the FieldStart to the FieldEnd
    Node currentNode = fieldStart.getNextSibling();
    while (currentNode != null && currentNode.getNodeType() != NodeType.FIELD_END && currentNode.getNodeType() != NodeType.FORM_FIELD)
        currentNode = currentNode.getNextSibling();

    if (currentNode.getNodeType() == NodeType.FORM_FIELD)
    {
        FormField expectedFormField = (FormField)currentNode;
        System.out.println(expectedFormField.getName());
    }
}