diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Join and append documents.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Join and append documents.cs index 9af5c5f8..b37fdd5b 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Join and append documents.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Join and append documents.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Drawing; using System.Text; using Aspose.Words; using Aspose.Words.Fields; @@ -336,7 +337,7 @@ public void KeepSourceTogether() dstDoc.Save(ArtifactsDir + "JoinAndAppendDocuments.KeepSourceTogether.docx"); //ExEnd:KeepSourceTogether - } + } [Test] public void ListKeepSourceFormatting() @@ -460,17 +461,31 @@ public void UseDestinationStyles() public void SmartStyleBehavior() { //ExStart:SmartStyleBehavior - Document srcDoc = new Document(MyDir + "Document source.docx"); - Document dstDoc = new Document(MyDir + "Northwind traders.docx"); + Document dstDoc = new Document(); DocumentBuilder builder = new DocumentBuilder(dstDoc); - - builder.MoveToDocumentEnd(); - builder.InsertBreak(BreakType.PageBreak); - ImportFormatOptions options = new ImportFormatOptions { SmartStyleBehavior = true }; + Style myStyle = builder.Document.Styles.Add(StyleType.Paragraph, "MyStyle"); + myStyle.Font.Size = 14; + myStyle.Font.Name = "Courier New"; + myStyle.Font.Color = Color.Blue; + + builder.ParagraphFormat.StyleName = myStyle.Name; + builder.Writeln("Hello world!"); + + // Clone the document and edit the clone's "MyStyle" style, so it is a different color than that of the original. + // If we insert the clone into the original document, the two styles with the same name will cause a clash. + Document srcDoc = dstDoc.Clone(); + srcDoc.Styles["MyStyle"].Font.Color = Color.Red; - builder.InsertDocument(srcDoc, ImportFormatMode.UseDestinationStyles, options); - builder.Document.Save(ArtifactsDir + "JoinAndAppendDocuments.SmartStyleBehavior.docx"); + // When we enable SmartStyleBehavior and use the KeepSourceFormatting import format mode, + // Aspose.Words will resolve style clashes by converting source document styles. + // with the same names as destination styles into direct paragraph attributes. + ImportFormatOptions options = new ImportFormatOptions(); + options.SmartStyleBehavior = true; + + builder.InsertDocument(srcDoc, ImportFormatMode.KeepSourceFormatting, options); + + dstDoc.Save(ArtifactsDir + "DocumentBuilder.SmartStyleBehavior.docx"); //ExEnd:SmartStyleBehavior } @@ -520,21 +535,18 @@ public void InsertDocumentInline() public void KeepSourceNumbering() { //ExStart:KeepSourceNumbering - Document srcDoc = new Document(MyDir + "Document source.docx"); - Document dstDoc = new Document(MyDir + "Northwind traders.docx"); - - // Keep source list formatting when importing numbered paragraphs. - ImportFormatOptions importFormatOptions = new ImportFormatOptions { KeepSourceNumbering = true }; - - NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KeepSourceFormatting, - importFormatOptions); - - ParagraphCollection srcParas = srcDoc.FirstSection.Body.Paragraphs; - foreach (Paragraph srcPara in srcParas) - { - Node importedNode = importer.ImportNode(srcPara, false); - dstDoc.FirstSection.Body.AppendChild(importedNode); - } + Document srcDoc = new Document(MyDir + "List source.docx"); + Document dstDoc = new Document(MyDir + "List destination.docx"); + + ImportFormatOptions options = new ImportFormatOptions(); + // If there is a clash of list styles, apply the list format of the source document. + // Set the "KeepSourceNumbering" property to "false" to not import any list numbers into the destination document. + // Set the "KeepSourceNumbering" property to "true" import all clashing + // list style numbering with the same appearance that it had in the source document. + options.KeepSourceNumbering = true; + + dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting, options); + dstDoc.UpdateListLabels(); dstDoc.Save(ArtifactsDir + "JoinAndAppendDocuments.KeepSourceNumbering.docx"); //ExEnd:KeepSourceNumbering diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with List.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with List.cs index aecc313f..aba3015a 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with List.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with List.cs @@ -14,27 +14,29 @@ public void RestartListAtEachSection() { //ExStart:RestartListAtEachSection Document doc = new Document(); - + DocumentBuilder builder = new DocumentBuilder(doc); + doc.Lists.Add(ListTemplate.NumberDefault); List list = doc.Lists[0]; list.IsRestartAtEachSection = true; - DocumentBuilder builder = new DocumentBuilder(doc); - builder.ListFormat.List = list; - - for (int i = 1; i < 45; i++) + // The "IsRestartAtEachSection" property will only be applicable when + // the document's OOXML compliance level is to a standard that is newer than "OoxmlComplianceCore.Ecma376". + OoxmlSaveOptions options = new OoxmlSaveOptions { - builder.Writeln($"List Item {i}"); + Compliance = OoxmlCompliance.Iso29500_2008_Transitional + }; - if (i == 15) - builder.InsertBreak(BreakType.SectionBreakNewPage); - } + builder.ListFormat.List = list; - // IsRestartAtEachSection will be written only if compliance is higher then OoxmlComplianceCore.Ecma376. - OoxmlSaveOptions options = new OoxmlSaveOptions { Compliance = OoxmlCompliance.Iso29500_2008_Transitional }; + builder.Writeln("List item 1"); + builder.Writeln("List item 2"); + builder.InsertBreak(BreakType.SectionBreakNewPage); + builder.Writeln("List item 3"); + builder.Writeln("List item 4"); - doc.Save(ArtifactsDir + "WorkingWithList.RestartListAtEachSection.docx", options); + doc.Save(ArtifactsDir + "OoxmlSaveOptions.RestartingDocumentList.docx", options); //ExEnd:RestartListAtEachSection }