We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Replace field result with static text

I am not authorized to upload doc/docx files.

DatumKBBB.zip (22.4 KB)
Thus, i have used ZIP to overcome this issue.

Please review the DOC file in the compressed archive. it is the document that has caused all of my problems.

@benzoid,

Thanks for sharing the document. We have tested the scenario using latest version of Aspose.Words for Java 18.6 with following code examples and have not found the shared issue. Please use Aspose.Words for Java 18.6. We have attached the output documents with this post for your kind reference. Docs.zip (53.0 KB)

Document doc = new Document(MyDir + "DatumKBBB.doc");
FieldsHelper.convertFieldsToStaticText(doc, FieldType.FIELD_FORM_TEXT_INPUT);

doc.save(MyDir + "FieldsHelper out.docx");

Document doc = new Document(MyDir + "DatumKBBB.doc");
 
for(Field field : doc.getRange().getFields())
{
    if(field.getType() == FieldType.FIELD_FORM_TEXT_INPUT)
    {
         
        field.unlink();
    }
}
 
doc.save(MyDir + "out-unlink.docx");

I am not a topic owner, so i cannot download your zip file.
My document is a DATE field.

Document doc = new Document(MyDir + "DatumKBBB.doc");
FieldsHelper.convertFieldsToStaticText(doc, FieldType.FIELD_DATE);
doc.save(MyDir + "FieldsHelper out.docx");

@benzoid,

Thanks for your inquiry. Your document contains the legacy form control (Text Form Field). It is imported as FormField into Aspose.Words’ DOM. Its field type is FIELD_FORM_TEXT_INPUT. Please check the attached image. FormField.png (30.9 KB)

If you want to check type of text form field, please use FormField.TextInputType. The Field class represents a Microsoft Word document field e.g. date, page etc.

Moreover, the date field has following field code. Please insert date field into document using MS Word to check its field code.

{ DATE @ “dddd d MMMM yyyy” * MERGEFORMAT }

Please check the code and document in my previous post to get the desired output.