Getting contentcontrols in word document

Hi,

I am trying to use the code from this post https://www.syncfusion.com/forums/157348/content-control to find the contentcontrols in my Word document. (see attachement). My contentcontrols (text) are located in a text range (inside a Word table). When looping through the document, it finds the default placeholder text of each contentcontrol, but the content controls are not added to the List<Entity> .

Specifically, the method GetContentControlInTextBody (line 133) has a switch statement, but it does not have a case for TextRange. I have been trying to discover myself what to put there to get the ContentControls in my document to be picked up, but have not had success thus far.

Any help would be appreciated.

Kind regards,

Niels



Attachment: TestRCM_4c421ed9.7z

11 Replies 1 reply marked as answer

HC Hemalatha Chiranjeevulu Syncfusion Team June 2, 2021 08:19 AM UTC

Hi Niels,

Thank you for contacting Syncfusion support.

On further analyzing the given Word document, we found that given word document has CellContentControl. Currently, Essential DocIO doesn’t have support for processing (add, remove, find, etc.) CellContentControl. We have already logged this as a feature request in our database. We don’t have any immediate plans to implement this feature. At the planning stage for every release cycle, we review all open features. We will let you know when this feature is implemented.

The status of the feature can be tracked through below link:
https://www.syncfusion.com/feedback/3119/support-for-cell-row-and-group-content-controls

To achieve your requirement, we have modified the CellContentControl as InlineContentControl in the given Word document. And we have prepared the sample application to find the content control in the modified document and replace with text. Please find the sample from the below link
https://www.syncfusion.com/downloads/support/forum/165991/ze/FindInlineContentControl256774768

In the above sample, we have done the following things:
1. Loads an existing Word document.
2. Iterates into all child entities and get the content controls in the document.
3. Find the content control using its tag name
4. Saves the Word document.

Please refer the below UG documentation to know more about content control:
https://help.syncfusion.com/file-formats/docio/working-with-content-controls

Please let us know if you have any other questions.

Regards,
Hemalatha C



NV NM van Strien June 2, 2021 09:33 AM UTC

Hi Hemalatha,

Thanks for explaining and your help.

I have been using Microsoft.Office.Interop.Word in the past, but now that I moved to .Net 5, there is no support for using this assembly anymore.

My understanding of content controls is based on that experience however. I therefore need to relearn a bit about how Syncfusion implemented this.

I am not sure if I understand what a cell contentcontrol could be. If you look at the enumeration of content controls in Word, I don't see a mention of that type of ContentControl: https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.word.wdcontentcontroltype?view=word-pia

Is there a way to insert an InlineContentControl from the Word user interface?

Kind regards,

Niels









HC Hemalatha Chiranjeevulu Syncfusion Team June 3, 2021 05:24 PM UTC

Hi Niels,

Thank you for your update.

From your previous update, we found your requirement is to replace the content control with text by finding tags. Content control in the Word document is CellContentControl (content control inside the table cell). As mentioned earlier, currently we don’t have support for CellContentControl. So, we modified the given input Word document. In the input Word document, we modified CellContentControl as InlineContentControl (inserted space before content control in the table cell).

Content controls can be categorized based on its occurrence in a document as follows,
1. InlineContentControl: You can add content control as a child to a paragraph using the inline content control. You can add text, pictures, fields or other paragraph items into the inline content control.
2. BlockContentControl: You can add content control to a text body of the Word document using block content control. You can add text, tables, pictures, or other items into the block content control.
3. RowContentControl: You can add content control as a child to table row is RowContentControl.
4. CellContentControl: You can add content control as a child to table cell is CellContentControl. You can add text, tables, pictures, fields, or other items into cell content control.

Note: RowContentControl and CellContentControl are maintained by Essential DocIO. As mentioned earlier, currently we don’t have support for cell content control. We will let you know when this feature is implemented.

Regarding Is there a way to insert an InlineContentControl from the Word user interface?.

1. Steps to insert inlineContentControl in Word document:
You can insert the InlineContentControl using Microsoft Word Application. To insert the inlineContentControl using Microsoft Word Application, insert space or text in the Word document and then insert the content control (becomes child of paragraph which is inlineContentControl).

You can also insert the InlineContentControl in Word document using DocIO. To insert inlineContentControl in the Word document using DocIO, please refer the below code example to insert the inlineContentControl in the Word document:

 
//Creates a new Word document  
WordDocument document = new WordDocument(); 
//Adds one section and one paragraph to the document 
document.EnsureMinimal(); 
//Gets the last paragraph 
WParagraph paragraph =document.LastParagraph; 
//Adds text to the paragraph 
paragraph.AppendText("A new text is added to the paragraph. "); 
//Appends inline content control to the paragraph 
InlineContentControl inlineContentControl = paragraph.AppendInlineContentControl(ContentControlType.RichText) as InlineContentControl; 
WTextRange textRange = new WTextRange(document); 
textRange.Text = "Inline content control "; 
//Adds new text to the inline content control 
inlineContentControl.ParagraphItems.Add(textRange); 
//Saves and closes the Word document instance 
document.Save("Sample.docx", FormatType.Docx); 
document.Close(); 

2. Steps to insert inlineContentControl inside table cell in the Word document:
To insert the inlineContentControl in the table cell using Microsoft Word Application, insert the table in the Word document, insert space inside a cell and then insert the content control (becomes child of paragraph which is inlineContentControl).

To insert inlineContentControl inside the table cell using DocIO, please use the below code example to insert the inlineContentControl inside the table cell in the Word document:

 
//Creates a new Word document  
WordDocument document = new WordDocument(); 
//Adds one section and one paragraph to the document 
document.EnsureMinimal(); 
IWTable table=document.LastSection.AddTable();  
//Specifies the total number of rows & columns 
table.ResetCells(1, 2); 
//Gets the last paragraph 
WParagraph paragraph = table[0, 0].AddParagraph() as WParagraph; 
//Adds text to the paragraph 
paragraph.AppendText("A new text is added to the paragraph. "); 
//Appends inline content control to the paragraph 
InlineContentControl inlineContentControl = paragraph.AppendInlineContentControl(ContentControlType.RichText) as InlineContentControl; 
WTextRange textRange = new WTextRange(document); 
textRange.Text = "Inline content control "; 
//Adds new text to the inline content control 
inlineContentControl.ParagraphItems.Add(textRange); 
//Saves and closes the Word document instance 
document.Save("Sample.docx", FormatType.Docx); 
document.Close(); 

Please refer below UG documentation to know how to work with content control using DocIO:
https://help.syncfusion.com/file-formats/docio/working-with-content-controls

Please let us know if you have any other questions.

Regards,
Hemalatha C


Marked as answer

NV NM van Strien June 4, 2021 01:54 PM UTC

Thank you for your very complete answer! It is very useful to me and I can recommend that you add this information to the DocIO documentation here: https://help.syncfusion.com/file-formats/docio/working-with-content-controls.

Kind regards,

Niels van Strien


HC Hemalatha Chiranjeevulu Syncfusion Team June 7, 2021 11:52 AM UTC

Hi Niels,

Thank you for your feedback.

We will document the details of RowContentControl and CellContentControl in our UG in future.

Please let us know if you have any other questions.

Regards,
Hemalatha C



NV NM van Strien January 25, 2022 01:16 PM UTC

Hi,


Are there still plans to implement this feature:  https://www.syncfusion.com/feedback/3119/support-for-cell-row-and-group-content-controls ?


Is there a way to programmatically set the placeholder text of a content control using DocIO

https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.word.contentcontrol.placeholdertext?view=word-pia

I am aware that the ref to interop is a different kind of content control, but I am looking for a similar parameter on the DocIO content contr

Kind regards




LB Lokesh Baskar Syncfusion Team January 26, 2022 07:02 PM UTC

Hi Strien,

Regarding support-for-cell-row-and-group-content-controls:
 
Currently, we don’t have any immediate plans to implement this feature. At the planning stage for every release cycle, we review all open features. We will let you know when this feature is implemented.

Regarding Is there a way to programmatically set the placeholder text of a content control using DocIO
 
Currently, we are checking your requirement and share further details on 27th January 2022.

Regards,
 
Lokesh B 



MR Manikandan Ravichandran Syncfusion Team January 27, 2022 03:47 PM UTC

Hi Strien,

Currently, we don’t have a support for adding the placeholder text for content control in the Word document using DocIO.

If you want to set title or tags for content control, you can use the below code example. 
blockContentControl.ContentControlProperties.Title = "Name";
blockContentControl.ContentControlProperties.Tag =
"Name"; 

Regards,
Manikandan Ravichandran
 



NV NM van Strien January 27, 2022 08:46 PM UTC

Please add it as a feature request. You already have a 'HasPlaceHolderText' method for contentcontrols , so I would think that exposing the PlaceHolderText  property with get/set should not be too difficult for syncfusion to add.


Of course - I understand there are many requests and resources are limited.


Kind regards,


NIels van Strien



MR Manikandan Ravichandran Syncfusion Team January 28, 2022 03:04 PM UTC

Hi Strien,

Thank you for your update.

We will analyze the feasibility to achieve this requirement and we will share the details on 01st February 2022.

Regards,
Manikandan Ravichandran 



MR Manikandan Ravichandran Syncfusion Team February 1, 2022 04:26 PM UTC

Hi Strien,

We have considered your request as a feature in our end, and we don’t have an immediate plan to implement this feature. We will update you with more details once this feature implemented.

The status of this feature task can be tracked through the following link:
https://www.syncfusion.com/feedback/32318/provide-an-api-to-get-or-set-place-holder-text-for-content-control-in-word

Regards,
Manikandan Ravichandran
 


Loader.
Up arrow icon