public int JoinRunsWithSameFormatting()
Public Function JoinRunsWithSameFormatting As Integer
public: int JoinRunsWithSameFormatting()
member JoinRunsWithSameFormatting : unit -> int
This is an optimization method. Some documents contain adjacent runs with same formatting. Usually this occurs if a document was intensively edited manually. You can reduce the document size and speed up further processing by joining these runs.
The operation checks every Paragraph node in the document for adjacent Run nodes having identical properties. It ignores unique identifiers used to track editing sessions of run creation and modification. First run in every joining sequence accumulates all text. Remaining runs are deleted from the document.
// Open a document which contains adjacent runs of text with identical formatting // This can, for example, occur if we edit one paragraph many times Document doc = new Document(MyDir + "Rendering.docx"); // Get the number of runs our document contains Assert.AreEqual(317, doc.GetChildNodes(NodeType.Run, true).Count); // We can merge all nearby runs with the same formatting to reduce that number by calling JoinRunsWithSameFormatting() // This method will also notify us of the number of run joins that took place Assert.AreEqual(121, doc.JoinRunsWithSameFormatting()); // Get the number of runs after joining, which, together with the number of joins should add up to the original number of runs Assert.AreEqual(196, doc.GetChildNodes(NodeType.Run, true).Count);