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

Free Support Forum - aspose.com

How to read a table from a particular section

Hi - We have recently got the license for Aspose.Total product family. Basically, we need to read a table data from a particular section of a Word document.

The only key is section name. In our Word document the sections are created dynamically and they are not static. How do we locate the section by a given name?

Thanks & Regards

Please reply

@ramanna,

When you create a sections dynamically, please bookmark (use hidden bookmarks starting with an underscore '’_) them as well to be able to identify them in a later stage.

Please ZIP and upload your input Word document here for testing. Please also tell what Table’s data you want to read from this document. We will investigate the issue on our end and provide you more information.

Actually, we have tables created under paragraphs and need to provide form input fields under cells whereby the user won’t be able to delete the fields.

I tried with StructuredDocumentTag and FormFields but unable to achieve the expected result.

Please refer the attached zip for reference field.

Requirements:

  1. Need to create WORD document with input fields as per the attached reference field
  2. Read the same document with the input fields captured and display in our Pega System

Thanks & RegardsSample Input Field.zip (7.1 KB)

@ramanna,

Thanks for your inquiry. Please ZIP and attach the following resources here for testing:

  • Your input Word document.
  • Your expected Word document which shows the desired output. You can create this document by using Microsoft Word.

As soon as you get these pieces of information ready, we’ll start further investigation into your issue and provide you code to achieve the same expected output by using Aspose.Words.

Please refer to the attached input sample format. It has 4 different controls namely:

  1. Input text control
  2. Checkbox
  3. Date control
  4. Input free text box

We are mostly interested in 1 & 4 controls to create in our input word document to show in our table cells and read those input values separately from a java program and display in Pega. There is no expected word document.
The expected output is just to read those input values from Sample format.zip (48.3 KB)
control fields.

Please advise and appreciate your response at the earliest. thanks.

@ramanna,

Please check the following code:

Document doc = new Document("D:\\temp\\Sample format.docx");

// To check how many types of Content Controls are present in Document
for (StructuredDocumentTag sdt : (Iterable<StructuredDocumentTag>) doc.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true)){
    System.out.println(sdt.getSdtType());
}

// To use the values of PlainText
for (StructuredDocumentTag sdt : (Iterable<StructuredDocumentTag>) doc.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true)) {
    if (sdt.getSdtType() == 12) {
        System.out.println(sdt.toString(SaveFormat.TEXT));
    }
}

// To add a new PlainText StructuredDocumentTag (Content Control) at the end of Document
StructuredDocumentTag plainText = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.INLINE);
plainText.removeAllChildren();
plainText.setTag("tag_1");
plainText.setTitle("some title");
plainText.appendChild(new Run(doc, "new StructuredDocumentTag of type PlainText"));

DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
builder.writeln();
builder.writeln();
builder.writeln();
builder.writeln();
builder.insertNode(plainText);

doc.save("D:\\temp\\awjava-18.2.docx");

By executing the code to add a new PlainText control to the document, the output is displaying like a simple display field with text. As per my previous email and requirement, I am expecting the control to be an input field. Please refer to my earlier attachment for reference.

Please advice. Thanks,

Appreciate your response at the earliest. thanks.

@ramanna,

I have attached an output document here for your reference.

awjava-18.2.zip (7.8 KB)

Is this output produced by using the following code is acceptable for you?

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

StructuredDocumentTag plainText = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.INLINE);
plainText.setTag("tag_1");
plainText.setTitle("some title");
plainText.isShowingPlaceholderText(false);
((Run)plainText.getFirstChild()).setText("new StructuredDocumentTag of type PlainText");
builder.insertNode(plainText);

doc.save("D:\\temp\\awjava-18.2.docx");

Thanks for the code. Your attached output shows the fields as an input and when we start key in the data, the field is highlighted.It is better but this is not what we are expecting.

I used the same code and generated at my side and attached the o/p for your reference. I dont see the field changed to input and it is similar to previous version.

In addition can we do the following for content control fields:

  1. Can we limit the number of input characters in the text field?
  2. Can this field inserted in table as a cell?

Thanks & RegardsIO_DOWNLOAD_2.zip (1.7 KB)

I am trying to read the content control field which was created with the following code:
The field is not identified and no output.

for (StructuredDocumentTag sdt : (Iterable) doc.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true)) {
System.out.println(“Inside FOR”);
if (sdt.getSdtType() == 12) {
System.out.println(sdt.toString(SaveFormat.TeX));
}
}

@ramanna,

You can move cursor inside a Cell by using a suitable DocumentBuilder.MoveTo() method and insert content control in Cell.

Are you able to insert PlainText StructuredDocumentTag (Content Control) field with check to limit the number of input characters by using MS Word application? Please create your expected Word document by using MS Word and attach it here for our reference.

Can we look into the basic functionality first based on my earlier email as below? I am unable to see the text field as an input field. I already sent you expected word document as an attachment.

Previous message:
I used the same code and generated at my side and attached the o/p for your reference. I don’t see the field changed to input and it is similar to the previous version.

@ramanna,

Yes, there are no Content Controls in your “IO_DOWNLOAD_2.doc” document. But can you please try running the following code (see awjava-18.2.zip (7.8 KB)):

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

StructuredDocumentTag plainText = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.INLINE);
plainText.setTag("tag_1");
plainText.setTitle("some title");
plainText.isShowingPlaceholderText(false);
((Run)plainText.getFirstChild()).setText("new StructuredDocumentTag of type PlainText");
builder.insertNode(plainText);

doc.save("D:\\temp\\awjava-18.2.docx");

Please create a comparison screenshot which highlights the problematic areas in this Aspose.Words generated DOCX (as compared to your expected document) and attach it here for our reference. We will investigate the issue further on our end and provide you more information.

Thank you. The code works fine for .docx document but not for .doc document.

Is there any additional logic to be added to be added to handle .doc document?

How do we highlight the content control input box? This helps the user to clearly notice the field and length of it. Please refer to the sample format I send earlier.

Thanks.

@ramanna,

This is because the DOC format does not support such StructuredDocumentTag. When you convert to DOC, such Content controls will be converted to static content.

You can verify this even by using MS Word 2016. Please open awjava-18.2.docx with MS Word 2016. Go to File > Info, click Check for Issues > Check Compatibility. In the Select versions to show drop down, choose Word 97 to 2003 option. This will show you the compatibility issues.

Noted the info.
Please help to answer my other query from the previous message.

How to highlight the content control input box? This helps the user to clearly notice the field and length of it. Please refer to the sample format I send earlier.

@ramanna,

We have logged your requirement in our issue tracking system. The ID of this issue is WORDSNET-16532. We will keep you informed of any updates.

Ok noted with Thanks.