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

Free Support Forum - aspose.com

Method field.setTextInputValue() gives an error of obfuscation

Aspose.Words.9.7.0 for Java

The following code gives the exception:

FormFieldCollection ffc = doc.getRange().getFormFields();
FormField field;

for (Object node: ffc) {
field = (FormField) node;

if (field.getType() == FieldType.FIELD_FORM_TEXT_INPUT && (field.getResult() == null || "".equals(field.getResult()))) {
field.setTextInputValue(" ");
}
}

Method "field.setTextInputValue" given an error:

at com.aspose.words.FormField.setTextInputValue(FormField.java:154)
java.lang.String cannot be cast to asposewobfuscated.qg

Best regards, Evgeniy

One more ClassCastException:

If we call doc.getMailMerge().execute(fieldNames, fieldValues) the second time to delete empty merge fields (the merge fields which were not merged) then for some document we receive the error:

java.lang.ClassCastException: com.aspose.words.be cannot be cast to com.aspose.words.cc
com.aspose.words.be cannot be cast to com.aspose.words.cc
at com.aspose.words.aor.s(ShellReflower.java:408)
at com.aspose.words.aor.agO(ShellReflower.java:154)
at com.aspose.words.aor.a(ShellReflower.java:61)
at com.aspose.words.bj.d(CellReflower.java:44)
at com.aspose.words.ais.h(RowReflower.java:41)
at com.aspose.words.da.a(ContentPartReflower.java:32)
at com.aspose.words.aor.agP(ShellReflower.java:200)
at com.aspose.words.aor.agN(ShellReflower.java:137)
at com.aspose.words.aor.a(ShellReflower.java:58)
at com.aspose.words.cd.uL(ColumnReflower.java:192)
at com.aspose.words.cd.c(ColumnReflower.java:38)
at com.aspose.words.ago.p(PageReflower.java:106)
at com.aspose.words.ago.h(PageReflower.java:52)
at com.aspose.words.ahb.o(PartReflower.java:30)
at com.aspose.words.aqa.dE(StoryLayout.java:89)
at com.aspose.words.fl.Z(DocumentLayoutReflower.java:168)
at com.aspose.words.ve.a(LayoutDocument.java:45)
at com.aspose.words.Document.updatePageLayout(Document.java:1368)
at com.aspose.words.fi.perform(DocumentActionUpdateLayout.java:25)
at com.aspose.words.of.execute(FieldUpdateExecutionItem.java:78)
at com.aspose.words.oi.gz(FieldUpdater.java:91)
at com.aspose.words.oi.Gh(FieldUpdater.java:78)
at com.aspose.words.xz.QV(MailMergeRegion.java:236)
at com.aspose.words.xz.a(MailMergeRegion.java:70)
at com.aspose.words.MailMerge.execute(MailMerge.java:128)
at com.aspose.words.MailMerge.execute(MailMerge.java:153)

Best regards, Evgeniy

Hi Evgeniy,

Thanks for your request.

1. I cannot reproduce the problem with form field on my side. I used the following code for testing:

Document doc = new Document("C:\\Temp\\in.doc");

FormField field = doc.getRange().getFormFields().get(0);

field.setTextInputValue(" ");

doc.save("C:\\Temp\\out.doc");

I tried setting different values and no exceptions were thrown. Could you please attach your document here for testing? I will check with your document and provide you more information.

2. If you need just remove empty merge fields, you can call doc.getMailMerge().deleteFields(); instead of executing mail merge second time. Anyways, could you please attach your template and sample code that will allow me to reproduce this problem? I will check it and provide you more information.

Best regards,

Hi Alexey,

Please see the attached documents: Test1 - for the first problem, Test2_anon - for the second.

And the code:
--------------------

Document document = new Document(file.getAbsolutePath());
document.acceptAllRevisions();

String[] fieldNames;
String[] fieldValues;

fieldNames = doc.getMailMerge().getFieldNames();
fieldValues = new String[fieldNames.length];

doc.getMailMerge().execute(fieldNames, fieldValues);

doc.getMailMerge().deleteFields();

document.save(file.getAbsolutePath() + ".pdf");
------------------------

Best regards, Evgeniy

Hi Evgeniy,

Thank you for additional information.

1. The problem occurs because two of the formfields in your document are date formfields. So these fields expect Date as value and that is why you get the exception. You can fix this by checking TextInputType:

Document doc = new Document("C:\\Temp\\Test1.doc");

FormFieldCollection fields = doc.getRange().getFormFields();

for(int i=0; i<fields.getCount(); i++)

{

FormField field = fields.get(i);

if(field.getType() == FieldType.FIELD_FORM_TEXT_INPUT && field.getTextInputType() == TextFormFieldType.REGULAR)

field.setTextInputValue("test");

}

doc.save("C:\\Temp\\out.doc")

Also, you can just set Result of the field.

2. I managed to reproduce the second problem. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

Best regards,

A fix for the issue(s) you've reported (filed as 25900) will be released in the next release at the end of this month. You will be notified.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as WORDSNET-4601) have been fixed in this .NET update and in this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.