How to delete paragraph and run with change tracking mode #1187
mahesh-anjani
announced in
Q&A
Replies: 1 comment
-
I am able to achieve this. The answer is posted here https://stackoverflow.com/questions/73122982/how-to-delete-paragraph-and-run-with-change-tracking-mode/73427614#73427614 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have an existing document. I am able to open the document in change tracking mode using TrackRevisions. Now, how can I delete a few selected paragraphs and runs as delete? I want to save document in such a state that when a user open the Word document it will display the deleted content as strikethrough and if user accepts all changes, it will remove all the deleted content.
Is it feasible to do? Any sample code would be highly appreciated. Thank you in advance!
I tried following, it generate markup with w:del element as a child of paragraph. However I am expecting all the children of paragraph under w:del element. I tried adding run elements of paragraph to deletedParagraph (commented code), but it throws error "Non-composite elements do not have child elements.".
`using (var document = WordprocessingDocument.Open(@"C:\Data\Test.docx", true))
{
// Change tracking code
DocumentSettingsPart documentSettingsPart = document.MainDocumentPart.DocumentSettingsPart ?? document.MainDocumentPart.AddNewPart();
Settings settings = documentSettingsPart.Settings ?? new Settings();
TrackRevisions trackRevisions = new TrackRevisions();
trackRevisions.Val = new DocumentFormat.OpenXml.OnOffValue(true);
settings.AppendChild(trackRevisions);
The above code generates xml like this:
<w:body>
<w:p w:rsidRPr="0081286C" w:rsidR="003F5596" w:rsidP="0081286C" w:rsidRDefault="001B56FE">
<w:bookmarkStart w:name="_GoBack" w:id="0"/>
<w:bookmarkEnd w:id="0"/>
<w:r>
<w:delText>This is a sentence</w:delText>
</w:r>
<w:del w:author="Author Name" w:date="2022-07-26T07:38:26.7978264-04:00"/>
</w:p>
<w:sectPr w:rsidRPr="0081286C" w:rsidR="003F5596">
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>
Beta Was this translation helpful? Give feedback.
All reactions