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

Free Support Forum - aspose.com

Please suggest How to check text input format of the fields present in the word document

Hi,


I am using aspose.words.jdk16-7.0.0 library in my project.
Following are steps to know what I want to do:
1- There is a fillable form present in word document, I want to load word document inside my java code and retrieve that form.
2- After retrieving the word document and receiving form details inside java code I want to know the properties of the different text boxes(fields) present in the form.(Properties like Uppercase Lowercase , Mixed case) and also I want to retrieve exact data which is looking inside the fields
like(Suppose I entered text data in lowercase and suppose the property of the field in which I am entering data is of converting any text to Uppercase internally then I want to retrieve that data in uppercase and vice a versa).
3-whatever I have mentioned above is working properly, But when I want to retrieve the format of the fields inside form(Uppercase,Lowercase,Mixed) it is giving the output for 1-2 cases and blank for remaining.
4-I am using following code for that.


package com.att.cio.wfmlsc.test;

import org.apache.log4j.Logger;
import org.apache.poi.hwpf.extractor.WordExtractor;

import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.FormFieldCollection;
import com.aspose.words.License;

public class Test1 {

public static void main(String[] args)
{
License license = new License();
WordExtractor extractor = null;
TestDocParsing testDocParsing = new TestDocParsing();
try {
license.setLicense(“C://Users//Abhay.Pathare//Desktop//Project_Study//”
+ “aspose.lic”);

Document doc = new Document(“C://Users//Abhay.Pathare//Desktop//Project_Study//”
+ “033_DL.doc”);
DocumentBuilder builder = new DocumentBuilder(doc);
FormFieldCollection documentFormFields = doc.getRange().getFormFields();
if(documentFormFields.getCount()!=0)
{
for (int i = 0; i < documentFormFields.getCount(); i++)
{
System.out.println("Bookmark Input format type : " + documentFormFields.get(i).getTextInputFormat());
System.out.println("Bookmark Result Value : " + documentFormFields.get(i).getResult());
}
}

} catch (Exception e) {
e.printStackTrace();
}
}
}




Thanks in advance.


Hi Abhay,

Thanks for your inquiry. FormField.TextInputFormat property returns or set the text formatting for a text form field. If the text form field contains regular text, then valid format strings are "", "UPPERCASE", "LOWERCASE", "FIRST CAPITAL" and "TITLE CASE". The strings are case-insensitive.

Could you please attach your input Word document here for testing? We will investigate the issue on our side and provide you more information.

Hi Tahir,


Thank you for your reply.I am attaching the snapshot of my form,which I am using inside word document.
In that form all fields are case insensitive i.e. whatever text I enter in these fields, It will change as per the property of that text box.(There are some text boxes whose properties are Uppecase/Lowercase compulsion, But user might enter data in wrong way so Inside my forms I internally set the properties inside word to correct the user input according to requirement of form fields).
Now I want to retrieve that texts and format of that texts in the format in which it is looking there inside these text boxes into my java code.

I am just sharing snapshot of my form. Actually I am working inside client domain, Once I will get confirmation from client I will share the Actual form.


Thank You
Hi Abhay,

Thanks for sharing the detail. You can also set the text formatting for a text form field using FormField.TextInputFormat property. If you are getting any incorrect results, we need your input document and form field detail for investigation purposes.

Hi,

As discussed I am attaching the form for testing.I also want to fill the form using java code.
I am using setTextInputValue and setTextResult for setting the form fields from java, But these values does not get reflected into the word for.

After setting the values into word form I am printing the values inside java code then it shows updated values, But these updated values not getting reflected inside word form.

Please suggest on this.If you contact me on my cellphone then I can explain better way.

Thank You,
Abhay
Contact:8698386776

Hi Abhay,

Thanks for sharing the detail. We have tested the scenario using following code example and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-13051. You will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

Document doc = new Document(MyDir + "Testing.doc");

for(FormField formfield : doc.getRange().getFormFields())

{

if(formfield.getType() == FieldType.FIELD_FORM_TEXT_INPUT)

{

formfield.setResult("New value" + formfield.getName());

formfield.setTextInputDefault("New value" + formfield.getName());

formfield.setTextInputFormat("UPPERCASE");

}

}

doc.unprotect();

doc.save(MyDir + "Out.docx");

If you are using different code example, please share that code here for our reference.

Hi as discussed above I am not able to get the input format of the text fields present in the form.


I am using getTextInputFormat() method to retrieve the format.

Thank You
Hi Abhay,

Thanks for your inquiry. It seems that form field's text format is empty. Could you please attach your editable input Word document here for testing? We will investigate the issue on our side and provide you more information.

Hi Abhay,

Thanks for your patience. It is to inform you that we have completed the work on issue (WORDSNET-13051) and has come to a conclusion that this issue is actually not a bug in Aspose.Words. So, we have closed this issue as 'Not a Bug'. We are quoting developer's comments here for your reference.

Changing the Formfield.TextInputFormat and other such properties in code does not take effect to value of the Result property. It is only hints for an office application (e.g. MS Word) that gives graphical interface to work with form fields.

You need to format the values according to your requirements and set the FormField.Result value as shown in following code example.

Document doc = new Document(MyDir + "Testing.doc");

for(FormField formfield : doc.getRange().getFormFields())

{

if(formfield.getType() == FieldType.FIELD_FORM_TEXT_INPUT)

{

formfield.setResult("New value" + formfield.getName());

formfield.setTextInputDefault("New value" + formfield.getName());

formfield.setTextInputFormat("UPPERCASE");

formfield.setResult(formfield.getResult().toUpperCase());

}

}

doc.unprotect();

doc.save(MyDir + "Out.docx");