Find and Check the Content Control Checkbox using Java

Hello Aspose team,
I am using aspose java library for word to process the word document.
I have a word document that contains tables and within the table there are checkboxes in some cells. I have attached the sample document. The logic used to read data from the document is not able to recognize check-boxes within the table, so I am not able to get info whether the check-boxes in the table are checked or not checked. I also need to know a particular checbox is in which cell. The code used is as below:

InputStream fis = new FileInputStream(fileName);
Document doc = new Document(fis);
NodeCollection nodes = doc.getChildNodes(NodeType.TABLE, true);
for (Iterator<Node> itr = nodes.iterator(); itr.hasNext(); ++count) {
	nod = itr.next()
	Table table = (Table) nod;
	RowCollection rowColl = table.getRows();
	for (int i = 0; i < rowColl.getCount(); ++i) {
		com.aspose.words.Row rowdata = rowColl.get(i);
		CellCollection cells = rowdata.getCells();
      	int columnCount = cells.getCount();
		for (int colIndex = 0; colIndex < columnCount; colIndex++) {
		  com.aspose.words.Cell cell = rowdata.getCells().get(colIndex);
		  if (cell != null) {
			cellJson.put("cellData", cell.getText());
			cellJson.put("columnIndex", colIndex);
			if ( cell.getChildNodes() != null) {
			  NodeCollection cellNodes = cell.getChildNodes();
			  for ( int nodeIndex =0; nodeIndex  < cellNodes.getCount(); nodeIndex ++) {
				logger.info("cell child node type:" + cellNodes.get(nodeIndex).getNodeType());
				if (cellNodes.get(nodeIndex).getNodeType() == FieldType.FIELD_FORM_CHECK_BOX ) {
				  FormField field1= (FormField)cellNodes.get(nodeIndex);
				  logger.info("ccell has checkbox. is it checked:" + field1.getChecked());
				  cellJson.put("checked", field1.getChecked());
				}
			  }
			}
		  }
		}
	}
}

@shashimn

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

I have attached zip file that contains the java code and the word document file.
I m using aspose words 19.3.
GRP-sample.zip (152.0 KB)

@shashimn

The FormField class represents legacy form controls. You can insert legacy form field using MS Word from developer tab. See the attached image (Legacy Forms.png) for detail.

Your input Word document contains content controls instead of form fields. Please read the following article to work with content controls.
Working with Content Control SDT

Please use the following code snippet to get the desierd output. Hope this helps you.

for (int colIndex = 0; colIndex < columnCount; colIndex++) {
    com.aspose.words.Cell cell = rowdata.getCells().get(colIndex);
    if (cell != null) {
        cellJson.put("cellData", cell.getText());
        cellJson.put("columnIndex", colIndex);
        if ( cell.getChildNodes() != null) {
            NodeCollection cellNodes = cell.getChildNodes(NodeType.ANY, true);
            for ( int nodeIndex =0; nodeIndex  < cellNodes.getCount(); nodeIndex ++) {
                System.out.println("cell child node type:" + cellNodes.get(nodeIndex).getNodeType());
                if (cellNodes.get(nodeIndex).getNodeType() == NodeType.STRUCTURED_DOCUMENT_TAG) {

                    StructuredDocumentTag sdt = (StructuredDocumentTag)cellNodes.get(nodeIndex);
                    if(sdt.getSdtType() == SdtType.CHECKBOX)
                    {
                        System.out.println("ccell has checkbox. is it checked:" + sdt.getChecked());
                    }
                }
            }
        }
    }}