Is there a reason the
example_add_rich_text_content_control
example is on the develop branch on GitHub but not on master yet?
We merge it to master from time to time. Anyway, the mentioned example works.
I’d like a way to replace the text inside the ContentControl but also preserve any formatting that has been applied to it (e.g font size / font style (italic, bold, etc), color, etc). The way I’ve achieved that is by using
SelectContentControl
&PasteText
but it feels hacky (as I outlined in the original post). Is there an alternative to way to do that?
You can try to use internalID to specify content control and change its contents. Please check out this code example: sdkjs/word/api_plugins.js at 0ab8241d66b1040bffc4069aec0ca11a8f041010 · ONLYOFFICE/sdkjs · GitHub
* // Add new content control
* var arrDocuments = [{
* "Props": {
* "Id": 100,
* "Tag": "CC_Tag",
* "Lock": 3
* },
* "Script": "var oParagraph = Api.CreateParagraph();oParagraph.AddText('Hello world!');Api.GetDocument().InsertContent([oParagraph]);"
*}]
* window.Asc.plugin.executeMethod("InsertAndReplaceContentControls", [arrDocuments]);
*
* // Change existed content control
* var arrDocuments = [{
* "Props": {
* "InternalId": "2_803"
* },
* "Script": "var oParagraph = Api.CreateParagraph();oParagraph.AddText('New text');Api.GetDocument().InsertContent([oParagraph]);"
*}]
* window.Asc.plugin.executeMethod("InsertAndReplaceContentControls", [arrDocuments]);
It should keep your font\style, but please check it out and let us know if something goes wrong.