I am creating a word custom add-in. In that user can able to add custom comments with color, bold, or highlight or set other possible options. But when I try to use directly <b>Hello This is comment</b>
and also try with the below option. When the first option is to try it gives me RichApi.Error GeneralException: GeneralException.
When I try to write this as a comment it prints as it is.
{ tf1ansiansicpg1252deff0 ouicompat{fonttbl{f0fnilfcharset0 Microsoft Sans Serif;}{f1fswissfprq2fcharset0 Microsoft Sans Serif;}{f2fnilfcharset2 Symbol;}} {colortbl ; ed0green0lue255; ed5green99lue193;} {generator Riched20 10.0.17763}viewkind4uc1 pardf0fs17lang1033 uses the parenthetical citation style, with most versions following format:par par pard{pntextf2'B7ab}{pnpnlvlbltpnf2pnindent0{pntxtb'B7}}... (Smith, 2005).par {pntextf2'B7ab}Smith (2005) stated ...par pardpar The Harvard system can vary, so please check your institution's style guide to confirm. par par pardwidctlpar {f1fs16{field{*fldinst{HYPERLINK "https://mysitehere"}}{fldrslt{ulcf1cf2ullang2057 Click here}}}}f1fs16 for more information.f0fs17par }
My Code:
range.insertOoxml(
'<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"><pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="512" ><pkg:xmlData ><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships" ><Relationship Id="rId1" Type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml" /></Relationships></pkg:xmlData ></pkg:part><pkg:part pkg:name="/word/_rels/document.xml.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="256"><pkg:xmlData><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" Target="comments.xml" xmlns="http://schemas.openxmlformats.org/package/2006/relationships" /></Relationships></pkg:xmlData></pkg:part><pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"><pkg:xmlData><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:commentRangeStart w:id="0"/><w:r><w:t>' + selectedText + '</w:t></w:r><w:commentRangeEnd w:id="0"/><w:r><w:commentReference w:id="0"/></w:r></w:p></w:body></w:document></pkg:xmlData></pkg:part><pkg:part xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" pkg:name="/word/comments.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"><pkg:xmlData><w:comments xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:comment xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" w:id="0"><w:sdtContent><w:p><w:r><w:t>' + commentMessage + '</w:t></w:r></w:p></w:sdtContent></w:comment></w:comments></pkg:xmlData></pkg:part><pkg:part pkg:name="/word/_rels/comments.xml.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml"><pkg:xmlData><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships></pkg:xmlData></pkg:part></pkg:package>',
"Replace"
);
If anyone has any idea how about this please let me know.
question from:https://stackoverflow.com/questions/65829989/how-to-add-customized-comment-in-ms-word-using-ooxml