diff --git a/Examples/ApiExamples/ApiExamples/ApiExampleBase.cs b/Examples/ApiExamples/ApiExamples/ApiExampleBase.cs index e94be9c65..f03390d9d 100644 --- a/Examples/ApiExamples/ApiExamples/ApiExampleBase.cs +++ b/Examples/ApiExamples/ApiExamples/ApiExampleBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2023 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ApiExamples.csproj b/Examples/ApiExamples/ApiExamples/ApiExamples.csproj index 063f8f7e4..d44debd3d 100644 --- a/Examples/ApiExamples/ApiExamples/ApiExamples.csproj +++ b/Examples/ApiExamples/ApiExamples/ApiExamples.csproj @@ -126,16 +126,16 @@ - - - - - - - - + + + + + + + + - + all runtime; build; native; contentfiles; analyzers diff --git a/Examples/ApiExamples/ApiExamples/CustomBarcodeGenerator.cs b/Examples/ApiExamples/ApiExamples/CustomBarcodeGenerator.cs index fe96e9898..b89a92d6e 100644 --- a/Examples/ApiExamples/ApiExamples/CustomBarcodeGenerator.cs +++ b/Examples/ApiExamples/ApiExamples/CustomBarcodeGenerator.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/DocumentHelper.cs b/Examples/ApiExamples/ApiExamples/DocumentHelper.cs index 67bd8688c..2aa78638c 100644 --- a/Examples/ApiExamples/ApiExamples/DocumentHelper.cs +++ b/Examples/ApiExamples/ApiExamples/DocumentHelper.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExAI.cs b/Examples/ApiExamples/ApiExamples/ExAI.cs index 5a18525f8..45abee56a 100644 --- a/Examples/ApiExamples/ApiExamples/ExAI.cs +++ b/Examples/ApiExamples/ApiExamples/ExAI.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided @@ -55,14 +55,14 @@ public void AiSummarize() //ExEnd:AiSummarize } - [Test, Ignore("This test should be run manually to manage API requests amount")] + [Test, Explicit("This test should be run manually to manage API requests amount")] public void AiTranslate() { //ExStart:AiTranslate //GistId:695136dbbe4f541a8a0a17b3d3468689 - //ExFor:IAiModelText.Translate(Document, AI.Language) - //ExFor:AI.Language - //ExSummary:Shows how to translate text using Google models. + //ExFor:IAiModelText.Translate(Document, AI.Language) + //ExFor:AI.Language + //ExSummary:Shows how to translate text using Google models. Document doc = new Document(MyDir + "Document.docx"); string apiKey = Environment.GetEnvironmentVariable("API_KEY"); @@ -74,7 +74,7 @@ public void AiTranslate() //ExEnd:AiTranslate } - [Test, Ignore("This test should be run manually to manage API requests amount")] + [Test, Explicit("This test should be run manually to manage API requests amount")] public void AiGrammar() { //ExStart:AiGrammar @@ -86,13 +86,13 @@ public void AiGrammar() string apiKey = Environment.GetEnvironmentVariable("API_KEY"); // Use OpenAI generative language models. - IAiModelText model = (IAiModelText)AiModel.Create(AiModelType.Gpt4OMini).WithApiKey(apiKey); + IAiModelText model = (OpenAiModel)AiModel.Create(AiModelType.Gpt4OMini).WithApiKey(apiKey); CheckGrammarOptions grammarOptions = new CheckGrammarOptions(); grammarOptions.ImproveStylistics = true; Document proofedDoc = model.CheckGrammar(doc, grammarOptions); - proofedDoc.Save("AI.AiGrammar.docx"); + proofedDoc.Save(ArtifactsDir + "AI.AiGrammar.docx"); //ExEnd:AiGrammar } } diff --git a/Examples/ApiExamples/ApiExamples/ExAbsolutePositionTab.cs b/Examples/ApiExamples/ApiExamples/ExAbsolutePositionTab.cs index 35f85b693..5150cd4f3 100644 --- a/Examples/ApiExamples/ApiExamples/ExAbsolutePositionTab.cs +++ b/Examples/ApiExamples/ApiExamples/ExAbsolutePositionTab.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExBookmarks.cs b/Examples/ApiExamples/ApiExamples/ExBookmarks.cs index 517564780..d3144ae14 100644 --- a/Examples/ApiExamples/ApiExamples/ExBookmarks.cs +++ b/Examples/ApiExamples/ApiExamples/ExBookmarks.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExBookmarksOutlineLevelCollection.cs b/Examples/ApiExamples/ApiExamples/ExBookmarksOutlineLevelCollection.cs index d198f46a7..9dd199455 100644 --- a/Examples/ApiExamples/ApiExamples/ExBookmarksOutlineLevelCollection.cs +++ b/Examples/ApiExamples/ApiExamples/ExBookmarksOutlineLevelCollection.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExBorder.cs b/Examples/ApiExamples/ApiExamples/ExBorder.cs index 6fffd65e6..658d75693 100644 --- a/Examples/ApiExamples/ApiExamples/ExBorder.cs +++ b/Examples/ApiExamples/ApiExamples/ExBorder.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExBorderCollection.cs b/Examples/ApiExamples/ApiExamples/ExBorderCollection.cs index 7aac9def6..5b206a5cb 100644 --- a/Examples/ApiExamples/ApiExamples/ExBorderCollection.cs +++ b/Examples/ApiExamples/ApiExamples/ExBorderCollection.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExBuildVersion.cs b/Examples/ApiExamples/ApiExamples/ExBuildVersion.cs index a76d4850f..2833678ed 100644 --- a/Examples/ApiExamples/ApiExamples/ExBuildVersion.cs +++ b/Examples/ApiExamples/ApiExamples/ExBuildVersion.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExBuildingBlocks.cs b/Examples/ApiExamples/ApiExamples/ExBuildingBlocks.cs index 2776854b7..fb3c1d799 100644 --- a/Examples/ApiExamples/ApiExamples/ExBuildingBlocks.cs +++ b/Examples/ApiExamples/ApiExamples/ExBuildingBlocks.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExCellFormat.cs b/Examples/ApiExamples/ApiExamples/ExCellFormat.cs index 72ec33030..bc95d19a0 100644 --- a/Examples/ApiExamples/ApiExamples/ExCellFormat.cs +++ b/Examples/ApiExamples/ApiExamples/ExCellFormat.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExCertificateHolder.cs b/Examples/ApiExamples/ApiExamples/ExCertificateHolder.cs index 26916d8cd..c83e0f4b7 100644 --- a/Examples/ApiExamples/ApiExamples/ExCertificateHolder.cs +++ b/Examples/ApiExamples/ApiExamples/ExCertificateHolder.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExCharts.cs b/Examples/ApiExamples/ApiExamples/ExCharts.cs index d3e7f2355..fdfbeb726 100644 --- a/Examples/ApiExamples/ApiExamples/ExCharts.cs +++ b/Examples/ApiExamples/ApiExamples/ExCharts.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExChmLoadOptions.cs b/Examples/ApiExamples/ApiExamples/ExChmLoadOptions.cs index 01221e474..1e2ae89ac 100644 --- a/Examples/ApiExamples/ApiExamples/ExChmLoadOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExChmLoadOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExCleanupOptions.cs b/Examples/ApiExamples/ApiExamples/ExCleanupOptions.cs index dd878a6d0..7cd677d9a 100644 --- a/Examples/ApiExamples/ApiExamples/ExCleanupOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExCleanupOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExComHelper.cs b/Examples/ApiExamples/ApiExamples/ExComHelper.cs index 870cf7f67..78eb72da8 100644 --- a/Examples/ApiExamples/ApiExamples/ExComHelper.cs +++ b/Examples/ApiExamples/ApiExamples/ExComHelper.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExComment.cs b/Examples/ApiExamples/ApiExamples/ExComment.cs index deccca7ad..70ebe4f5c 100644 --- a/Examples/ApiExamples/ApiExamples/ExComment.cs +++ b/Examples/ApiExamples/ApiExamples/ExComment.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided @@ -77,7 +77,7 @@ public void PrintAllComments() // If a comment has no ancestor, it is a "top-level" comment as opposed to a reply-type comment. // Print all top-level comments along with any replies they may have. - foreach (Comment comment in comments.OfType().Where(c => c.Ancestor == null)) + foreach (Comment comment in comments.OfType().Where(c => c.Ancestor == null).ToList()) { Console.WriteLine("Top-level comment:"); Console.WriteLine($"\t\"{comment.GetText().Trim()}\", by {comment.Author}"); @@ -219,7 +219,7 @@ private static void PrintAllCommentInfo(NodeCollection comments) CommentInfoPrinter commentVisitor = new CommentInfoPrinter(); // Iterate over all top-level comments. Unlike reply-type comments, top-level comments have no ancestor. - foreach (Comment comment in comments.Where(c => ((Comment)c).Ancestor == null)) + foreach (Comment comment in comments.Where(c => ((Comment)c).Ancestor == null).ToList()) { // First, visit the start of the comment range. CommentRangeStart commentRangeStart = (CommentRangeStart)comment.PreviousSibling.PreviousSibling.PreviousSibling; diff --git a/Examples/ApiExamples/ApiExamples/ExCompatibilityOptions.cs b/Examples/ApiExamples/ApiExamples/ExCompatibilityOptions.cs index e02f43caf..62aa0d863 100644 --- a/Examples/ApiExamples/ApiExamples/ExCompatibilityOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExCompatibilityOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExControlChar.cs b/Examples/ApiExamples/ApiExamples/ExControlChar.cs index ed393aa0a..4ebfd0005 100644 --- a/Examples/ApiExamples/ApiExamples/ExControlChar.cs +++ b/Examples/ApiExamples/ApiExamples/ExControlChar.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExDigitalSignatureCollection.cs b/Examples/ApiExamples/ApiExamples/ExDigitalSignatureCollection.cs index 244e6b383..2bc42f0f9 100644 --- a/Examples/ApiExamples/ApiExamples/ExDigitalSignatureCollection.cs +++ b/Examples/ApiExamples/ApiExamples/ExDigitalSignatureCollection.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExDigitalSignatureUtil.cs b/Examples/ApiExamples/ApiExamples/ExDigitalSignatureUtil.cs index af3ce75a7..fe5f9e3bb 100644 --- a/Examples/ApiExamples/ApiExamples/ExDigitalSignatureUtil.cs +++ b/Examples/ApiExamples/ApiExamples/ExDigitalSignatureUtil.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExDocSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExDocSaveOptions.cs index a5650fbb4..aeded6358 100644 --- a/Examples/ApiExamples/ApiExamples/ExDocSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExDocSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExDocument.cs b/Examples/ApiExamples/ApiExamples/ExDocument.cs index 2dd82ce1b..557d9b3fb 100644 --- a/Examples/ApiExamples/ApiExamples/ExDocument.cs +++ b/Examples/ApiExamples/ApiExamples/ExDocument.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided @@ -548,8 +548,8 @@ public void AppendDocument() string outDocText = new Document(ArtifactsDir + "Document.AppendDocument.docx").GetText(); - Assert.True(outDocText.StartsWith(dstDoc.GetText(), StringComparison.Ordinal)); - Assert.True(outDocText.EndsWith(srcDoc.GetText(), StringComparison.Ordinal)); + Assert.True(outDocText.StartsWith(dstDoc.GetText())); + Assert.True(outDocText.EndsWith(srcDoc.GetText())); } [Test] diff --git a/Examples/ApiExamples/ApiExamples/ExDocumentBase.cs b/Examples/ApiExamples/ApiExamples/ExDocumentBase.cs index 663bce3bb..a5bb69bc5 100644 --- a/Examples/ApiExamples/ApiExamples/ExDocumentBase.cs +++ b/Examples/ApiExamples/ApiExamples/ExDocumentBase.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided @@ -77,7 +77,7 @@ public void ImportNode() // Every node has a parent document, which is the document that contains the node. // Inserting a node into a document that the node does not belong to will throw an exception. Assert.AreNotEqual(dstDoc, srcDoc.FirstSection.Document); - Assert.Throws(() => { dstDoc.AppendChild(srcDoc.FirstSection); }); + Assert.Throws(() => dstDoc.AppendChild(srcDoc.FirstSection)); // Use the ImportNode method to create a copy of a node, which will have the document // that called the ImportNode method set as its new owner document. diff --git a/Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs b/Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs index 0a7f257d5..93ac8d6e6 100644 --- a/Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs +++ b/Examples/ApiExamples/ApiExamples/ExDocumentBuilder.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExDocumentBuilderImages.cs b/Examples/ApiExamples/ApiExamples/ExDocumentBuilderImages.cs index 4afcda490..2eb5c363a 100644 --- a/Examples/ApiExamples/ApiExamples/ExDocumentBuilderImages.cs +++ b/Examples/ApiExamples/ApiExamples/ExDocumentBuilderImages.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExDocumentProperties.cs b/Examples/ApiExamples/ApiExamples/ExDocumentProperties.cs index 0668a7ebe..4065d69ca 100644 --- a/Examples/ApiExamples/ApiExamples/ExDocumentProperties.cs +++ b/Examples/ApiExamples/ApiExamples/ExDocumentProperties.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExDocumentVisitor.cs b/Examples/ApiExamples/ApiExamples/ExDocumentVisitor.cs index 9f91ccb63..eff29c04a 100644 --- a/Examples/ApiExamples/ApiExamples/ExDocumentVisitor.cs +++ b/Examples/ApiExamples/ApiExamples/ExDocumentVisitor.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExDrawing.cs b/Examples/ApiExamples/ApiExamples/ExDrawing.cs index 754d826c4..0a2a1ed6d 100644 --- a/Examples/ApiExamples/ApiExamples/ExDrawing.cs +++ b/Examples/ApiExamples/ApiExamples/ExDrawing.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExEditableRange.cs b/Examples/ApiExamples/ApiExamples/ExEditableRange.cs index 21e1a9698..19c2bc604 100644 --- a/Examples/ApiExamples/ApiExamples/ExEditableRange.cs +++ b/Examples/ApiExamples/ApiExamples/ExEditableRange.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExField.cs b/Examples/ApiExamples/ApiExamples/ExField.cs index 69535adcb..b81c11a68 100644 --- a/Examples/ApiExamples/ApiExamples/ExField.cs +++ b/Examples/ApiExamples/ApiExamples/ExField.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided @@ -1401,7 +1401,7 @@ public void FieldAutoNumLgl() // has reset the count for this level so that this field will display "2.2.1.". InsertNumberedClause(builder, "\tHeading 6", fillerText, StyleIdentifier.Heading3); - foreach (FieldAutoNumLgl field in doc.Range.Fields.Where(f => f.Type == FieldType.FieldAutoNumLegal)) + foreach (FieldAutoNumLgl field in doc.Range.Fields.Where(f => f.Type == FieldType.FieldAutoNumLegal).ToList()) { // The separator character, which appears in the field result immediately after the number, // is a full stop by default. If we leave this property null, @@ -1440,7 +1440,7 @@ private void TestFieldAutoNumLgl(Document doc) { doc = DocumentHelper.SaveOpen(doc); - foreach (FieldAutoNumLgl field in doc.Range.Fields.Where(f => f.Type == FieldType.FieldAutoNumLegal)) + foreach (FieldAutoNumLgl field in doc.Range.Fields.Where(f => f.Type == FieldType.FieldAutoNumLegal).ToList()) { TestUtil.VerifyField(FieldType.FieldAutoNumLegal, " AUTONUMLGL \\s : \\e", string.Empty, field); @@ -1471,7 +1471,7 @@ public void FieldAutoNumOut() builder.InsertField(FieldType.FieldAutoNumOutline, true); builder.Writeln("\tParagraph 2."); - foreach (FieldAutoNumOut field in doc.Range.Fields.Where(f => f.Type == FieldType.FieldAutoNumOutline)) + foreach (FieldAutoNumOut field in doc.Range.Fields.Where(f => f.Type == FieldType.FieldAutoNumOutline).ToList()) Assert.AreEqual(" AUTONUMOUT ", field.GetFieldCode()); doc.Save(ArtifactsDir + "Field.AUTONUMOUT.docx"); @@ -4671,25 +4671,25 @@ public void FieldStyleRefParagraphNumbers() field = (FieldStyleRef)doc.Range.Fields[2]; - TestUtil.VerifyField(FieldType.FieldStyleRef, " STYLEREF Quote \\n", "b )", field); + TestUtil.VerifyField(FieldType.FieldStyleRef, " STYLEREF Quote \\n", "‎b )", field); Assert.AreEqual("Quote", field.StyleName); Assert.True(field.InsertParagraphNumber); field = (FieldStyleRef)doc.Range.Fields[3]; - TestUtil.VerifyField(FieldType.FieldStyleRef, " STYLEREF Quote \\r", "b )", field); + TestUtil.VerifyField(FieldType.FieldStyleRef, " STYLEREF Quote \\r", "‎b )", field); Assert.AreEqual("Quote", field.StyleName); Assert.True(field.InsertParagraphNumberInRelativeContext); field = (FieldStyleRef)doc.Range.Fields[4]; - TestUtil.VerifyField(FieldType.FieldStyleRef, " STYLEREF Quote \\w", "1.b )", field); + TestUtil.VerifyField(FieldType.FieldStyleRef, " STYLEREF Quote \\w", "‎1.b )", field); Assert.AreEqual("Quote", field.StyleName); Assert.True(field.InsertParagraphNumberInFullContext); field = (FieldStyleRef)doc.Range.Fields[5]; - TestUtil.VerifyField(FieldType.FieldStyleRef, " STYLEREF Quote \\w \\t", "1.b)", field); + TestUtil.VerifyField(FieldType.FieldStyleRef, " STYLEREF Quote \\w \\t", "‎1.b)", field); Assert.AreEqual("Quote", field.StyleName); Assert.True(field.InsertParagraphNumberInFullContext); Assert.True(field.SuppressNonDelimiters); @@ -6181,28 +6181,28 @@ private void TestFieldRef(Document doc) field = (FieldRef)doc.Range.Fields[2]; - TestUtil.VerifyField(FieldType.FieldRef, " REF MyBookmark \\n", ">>> i", field); + TestUtil.VerifyField(FieldType.FieldRef, " REF MyBookmark \\n", "‎>>> i", field); Assert.AreEqual("MyBookmark", field.BookmarkName); Assert.True(field.InsertParagraphNumber); Assert.AreEqual(" REF MyBookmark \\n", field.GetFieldCode()); - Assert.AreEqual(">>> i", field.Result); + Assert.AreEqual("‎>>> i", field.Result); field = (FieldRef)doc.Range.Fields[3]; - TestUtil.VerifyField(FieldType.FieldRef, " REF MyBookmark \\n \\t", "i", field); + TestUtil.VerifyField(FieldType.FieldRef, " REF MyBookmark \\n \\t", "‎i", field); Assert.AreEqual("MyBookmark", field.BookmarkName); Assert.True(field.InsertParagraphNumber); Assert.True(field.SuppressNonDelimiters); field = (FieldRef)doc.Range.Fields[4]; - TestUtil.VerifyField(FieldType.FieldRef, " REF MyBookmark \\w", "> 4>> c>>> i", field); + TestUtil.VerifyField(FieldType.FieldRef, " REF MyBookmark \\w", "‎> 4>> c>>> i", field); Assert.AreEqual("MyBookmark", field.BookmarkName); Assert.True(field.InsertParagraphNumberInFullContext); field = (FieldRef)doc.Range.Fields[5]; - TestUtil.VerifyField(FieldType.FieldRef, " REF MyBookmark \\r", ">> c>>> i", field); + TestUtil.VerifyField(FieldType.FieldRef, " REF MyBookmark \\r", "‎>> c>>> i", field); Assert.AreEqual("MyBookmark", field.BookmarkName); Assert.True(field.InsertParagraphNumberInRelativeContext); } diff --git a/Examples/ApiExamples/ApiExamples/ExFieldOptions.cs b/Examples/ApiExamples/ApiExamples/ExFieldOptions.cs index 9070acde7..fe827ff86 100644 --- a/Examples/ApiExamples/ApiExamples/ExFieldOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExFieldOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExFile.cs b/Examples/ApiExamples/ApiExamples/ExFile.cs index 549bd2a26..670f0c075 100644 --- a/Examples/ApiExamples/ApiExamples/ExFile.cs +++ b/Examples/ApiExamples/ApiExamples/ExFile.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExFont.cs b/Examples/ApiExamples/ApiExamples/ExFont.cs index 8c469cffb..4c972d04e 100644 --- a/Examples/ApiExamples/ApiExamples/ExFont.cs +++ b/Examples/ApiExamples/ApiExamples/ExFont.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided @@ -16,6 +16,7 @@ using Aspose.Words.Fields; using Aspose.Words.Fonts; using Aspose.Words.Notes; +using Aspose.Words.Settings; using Aspose.Words.Tables; using Aspose.Words.Themes; using NUnit.Framework; @@ -1700,5 +1701,35 @@ public void PhysicalFontInfoEmbeddingLicensingRights() } //ExEnd:PhysicalFontInfoEmbeddingLicensingRights } + + [Test] + public void NumberSpacing() + { + //ExStart:NumberSpacing + //GistId:95fdae949cefbf2ce485acc95cccc495 + //ExFor:Font.NumberSpacing + //ExFor:NumSpacing + //ExSummary:Shows how to set the spacing type of the numeral. + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + + // This effect is only supported in newer versions of MS Word. + doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2019); + + builder.Write("1 "); + builder.Write("This is an example"); + + Run run = doc.FirstSection.Body.FirstParagraph.Runs[0]; + if (run.Font.NumberSpacing == NumSpacing.Default) + run.Font.NumberSpacing = NumSpacing.Proportional; + + doc.Save(ArtifactsDir + "Fonts.NumberSpacing.docx"); + //ExEnd:NumberSpacing + + doc = new Document(ArtifactsDir + "Fonts.NumberSpacing.docx"); + + run = doc.FirstSection.Body.FirstParagraph.Runs[0]; + Assert.AreEqual(NumSpacing.Proportional, run.Font.NumberSpacing); + } } } \ No newline at end of file diff --git a/Examples/ApiExamples/ApiExamples/ExFontSettings.cs b/Examples/ApiExamples/ApiExamples/ExFontSettings.cs index 7549812f8..8678be221 100644 --- a/Examples/ApiExamples/ApiExamples/ExFontSettings.cs +++ b/Examples/ApiExamples/ApiExamples/ExFontSettings.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided @@ -170,7 +170,7 @@ public void SubstitutionWarning() Assert.True(callback.FontSubstitutionWarnings[0].WarningType == WarningType.FontSubstitution); Assert.True(callback.FontSubstitutionWarnings[0].Description .Equals( - "Font 'Times New Roman' has not been found. Using 'Fanwood' font instead. Reason: first available font.", StringComparison.Ordinal)); + "Font 'Times New Roman' has not been found. Using 'Fanwood' font instead. Reason: first available font.")); } private class FontSubstitutionWarningCollector : IWarningCallback @@ -303,7 +303,7 @@ public void SubstitutionWarningsClosestMatch() Assert.True(callback.FontWarnings[0].Description .Equals( - "Font \'SymbolPS\' has not been found. Using \'Wingdings\' font instead. Reason: font info substitution.", StringComparison.Ordinal)); + "Font \'SymbolPS\' has not been found. Using \'Wingdings\' font instead. Reason: font info substitution.")); } [Test] diff --git a/Examples/ApiExamples/ApiExamples/ExFormFields.cs b/Examples/ApiExamples/ApiExamples/ExFormFields.cs index 949b52a5e..8cba33316 100644 --- a/Examples/ApiExamples/ApiExamples/ExFormFields.cs +++ b/Examples/ApiExamples/ApiExamples/ExFormFields.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExHeaderFooter.cs b/Examples/ApiExamples/ApiExamples/ExHeaderFooter.cs index e570d7b2a..5790553b9 100644 --- a/Examples/ApiExamples/ApiExamples/ExHeaderFooter.cs +++ b/Examples/ApiExamples/ApiExamples/ExHeaderFooter.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExHtmlFixedSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExHtmlFixedSaveOptions.cs index c588bcd6b..0ae214f32 100644 --- a/Examples/ApiExamples/ApiExamples/ExHtmlFixedSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExHtmlFixedSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExHtmlLoadOptions.cs b/Examples/ApiExamples/ApiExamples/ExHtmlLoadOptions.cs index 767f862f7..183206649 100644 --- a/Examples/ApiExamples/ApiExamples/ExHtmlLoadOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExHtmlLoadOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExHtmlSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExHtmlSaveOptions.cs index f92fca428..fb4f9f62e 100644 --- a/Examples/ApiExamples/ApiExamples/ExHtmlSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExHtmlSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided @@ -819,11 +819,12 @@ public void ExportXhtmlTransitional(bool showDoctypeDeclaration) // Our document will only contain a DOCTYPE declaration heading if we have set the "ExportXhtmlTransitional" flag to "true". string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlSaveOptions.ExportXhtmlTransitional.html"); + string newLine = Environment.NewLine; if (showDoctypeDeclaration) Assert.True(outDocContents.Contains( - "\r\n" + - "\r\n" + + $"{newLine}" + + $"{newLine}" + "")); else Assert.True(outDocContents.Contains("")); @@ -1747,7 +1748,7 @@ public void ScaleImageToShapeSize(bool scaleImageToShapeSize) #if NET461_OR_GREATER || JAVA Assert.IsTrue(testedImageLength < 3000); #elif NET5_0_OR_GREATER - Assert.IsTrue(testedImageLength < 6000); + Assert.IsTrue(testedImageLength < 6200); #endif else Assert.IsTrue(testedImageLength < 16000); @@ -1850,27 +1851,28 @@ public void PrettyFormat(bool usePrettyFormat) // Enabling pretty format makes the raw html code more readable by adding tab stop and new line characters. string html = File.ReadAllText(ArtifactsDir + "HtmlSaveOptions.PrettyFormat.html"); + string newLine = Environment.NewLine; if (usePrettyFormat) Assert.AreEqual( - "\r\n" + - "\t\r\n" + - "\t\t\r\n" + - "\t\t\r\n" + - $"\t\t\r\n" + - "\t\t\r\n" + - "\t\t\r\n" + - "\t\r\n" + - "\t\r\n" + - "\t\t
\r\n" + - "\t\t\t

\r\n" + - "\t\t\t\tHello world!\r\n" + - "\t\t\t

\r\n" + - "\t\t\t

\r\n" + - "\t\t\t\t \r\n" + - "\t\t\t

\r\n" + - "\t\t
\r\n" + - "\t\r\n", + $"{newLine}" + + $"\t{newLine}" + + $"\t\t{newLine}" + + $"\t\t{newLine}" + + $"\t\t{newLine}" + + $"\t\t{newLine}" + + $"\t\t{newLine}" + + $"\t{newLine}" + + $"\t{newLine}" + + $"\t\t
{newLine}" + + $"\t\t\t

{newLine}" + + $"\t\t\t\tHello world!{newLine}" + + $"\t\t\t

{newLine}" + + $"\t\t\t

{newLine}" + + $"\t\t\t\t {newLine}" + + $"\t\t\t

{newLine}" + + $"\t\t
{newLine}" + + $"\t{newLine}", html); else Assert.AreEqual( diff --git a/Examples/ApiExamples/ApiExamples/ExHyphenation.cs b/Examples/ApiExamples/ApiExamples/ExHyphenation.cs index 8c4043c32..88846dfe9 100644 --- a/Examples/ApiExamples/ApiExamples/ExHyphenation.cs +++ b/Examples/ApiExamples/ApiExamples/ExHyphenation.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExImage.cs b/Examples/ApiExamples/ApiExamples/ExImage.cs index c0459588e..b2f1c101e 100644 --- a/Examples/ApiExamples/ApiExamples/ExImage.cs +++ b/Examples/ApiExamples/ApiExamples/ExImage.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExImageSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExImageSaveOptions.cs index 0f4dbd279..b3751badf 100644 --- a/Examples/ApiExamples/ApiExamples/ExImageSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExImageSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExInline.cs b/Examples/ApiExamples/ApiExamples/ExInline.cs index defe5aeca..ac8ba8ea2 100644 --- a/Examples/ApiExamples/ApiExamples/ExInline.cs +++ b/Examples/ApiExamples/ApiExamples/ExInline.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExInlineStory.cs b/Examples/ApiExamples/ApiExamples/ExInlineStory.cs index 91c59608b..efff4ef95 100644 --- a/Examples/ApiExamples/ApiExamples/ExInlineStory.cs +++ b/Examples/ApiExamples/ApiExamples/ExInlineStory.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExLayout.cs b/Examples/ApiExamples/ApiExamples/ExLayout.cs index 024cf0357..3ef103b6e 100644 --- a/Examples/ApiExamples/ApiExamples/ExLayout.cs +++ b/Examples/ApiExamples/ApiExamples/ExLayout.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExLicense.cs b/Examples/ApiExamples/ApiExamples/ExLicense.cs index 12b07679f..4c1ee14bd 100644 --- a/Examples/ApiExamples/ApiExamples/ExLicense.cs +++ b/Examples/ApiExamples/ApiExamples/ExLicense.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExLists.cs b/Examples/ApiExamples/ApiExamples/ExLists.cs index 85657f634..ad487d3e1 100644 --- a/Examples/ApiExamples/ApiExamples/ExLists.cs +++ b/Examples/ApiExamples/ApiExamples/ExLists.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided @@ -517,7 +517,7 @@ public void DetectBulletedParagraphs() NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true); - foreach (Paragraph para in paras.OfType().Where(p => p.ListFormat.IsListItem)) + foreach (Paragraph para in paras.OfType().Where(p => p.ListFormat.IsListItem).ToList()) { Console.WriteLine($"This paragraph belongs to list ID# {para.ListFormat.List.ListId}, number style \"{para.ListFormat.ListLevel.NumberStyle}\""); Console.WriteLine($"\t\"{para.GetText().Trim()}\""); @@ -527,7 +527,7 @@ public void DetectBulletedParagraphs() doc = DocumentHelper.SaveOpen(doc); paras = doc.GetChildNodes(NodeType.Paragraph, true); - Assert.AreEqual(6, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); + Assert.AreEqual(6, paras.Count(n => ((Paragraph)n).ListFormat.IsListItem)); } [Test] @@ -546,12 +546,12 @@ public void RemoveBulletsFromParagraphs() builder.ListFormat.RemoveNumbers(); NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true); - Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); + Assert.AreEqual(3, paras.Count(n => ((Paragraph)n).ListFormat.IsListItem)); foreach (Paragraph paragraph in paras) paragraph.ListFormat.RemoveNumbers(); - Assert.AreEqual(0, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); + Assert.AreEqual(0, paras.Count(n => ((Paragraph)n).ListFormat.IsListItem)); //ExEnd } @@ -570,25 +570,25 @@ public void ApplyExistingListToParagraphs() NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true); - Assert.AreEqual(0, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); + Assert.AreEqual(0, paras.Count(n => ((Paragraph)n).ListFormat.IsListItem)); doc.Lists.Add(ListTemplate.NumberDefault); - List list = doc.Lists[0]; + List docList = doc.Lists[0]; foreach (Paragraph paragraph in paras.OfType()) { - paragraph.ListFormat.List = list; + paragraph.ListFormat.List = docList; paragraph.ListFormat.ListLevelNumber = 2; } - Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); + Assert.AreEqual(3, paras.Count(n => ((Paragraph)n).ListFormat.IsListItem)); //ExEnd doc = DocumentHelper.SaveOpen(doc); paras = doc.GetChildNodes(NodeType.Paragraph, true); - Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); - Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.ListLevelNumber == 2)); + Assert.AreEqual(3, paras.Count(n => ((Paragraph)n).ListFormat.IsListItem)); + Assert.AreEqual(3, paras.Count(n => ((Paragraph)n).ListFormat.ListLevelNumber == 2)); } [Test] @@ -606,24 +606,24 @@ public void ApplyNewListToParagraphs() NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true); - Assert.AreEqual(0, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); + Assert.AreEqual(0, paras.Count(n => ((Paragraph)n).ListFormat.IsListItem)); - List list = doc.Lists.Add(ListTemplate.NumberUppercaseLetterDot); + List docList = doc.Lists.Add(ListTemplate.NumberUppercaseLetterDot); foreach (Paragraph paragraph in paras.OfType()) { - paragraph.ListFormat.List = list; + paragraph.ListFormat.List = docList; paragraph.ListFormat.ListLevelNumber = 1; } - Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); + Assert.AreEqual(3, paras.Count(n => ((Paragraph)n).ListFormat.IsListItem)); //ExEnd doc = DocumentHelper.SaveOpen(doc); paras = doc.GetChildNodes(NodeType.Paragraph, true); - Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); - Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.ListLevelNumber == 1)); + Assert.AreEqual(3, paras.Count(n => ((Paragraph)n).ListFormat.IsListItem)); + Assert.AreEqual(3, paras.Count(n => ((Paragraph)n).ListFormat.ListLevelNumber == 1)); } //ExStart @@ -904,7 +904,7 @@ public void GetListLabels() // Find if we have the paragraph list. In our document, our list uses plain Arabic numbers, // which start at three and ends at six. - foreach (Paragraph paragraph in paras.OfType().Where(p => p.ListFormat.IsListItem)) + foreach (Paragraph paragraph in paras.OfType().Where(p => p.ListFormat.IsListItem).ToList()) { Console.WriteLine($"List item paragraph #{paras.IndexOf(paragraph)}"); @@ -1030,5 +1030,39 @@ public void SetCustomNumberStyleFormat() Assert.AreEqual("002.", paras[2].ListLabel.LabelString); //ExEnd:SetCustomNumberStyleFormat } + + [Test] + public void AddSingleLevelList() + { + //ExStart:AddSingleLevelList + //GistId:95fdae949cefbf2ce485acc95cccc495 + //ExFor:ListCollection.AddSingleLevelList(ListTemplate) + //ExSummary:Shows how to create a new single level list based on the predefined template. + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + ListCollection listCollection = doc.Lists; + + // Creates the bulleted list from BulletCircle template. + List bulletedList = listCollection.AddSingleLevelList(ListTemplate.BulletCircle); + + // Writes the bulleted list to the resulting document. + builder.Writeln("Bulleted list starts below:"); + builder.ListFormat.List = bulletedList; + builder.Writeln("Item 1"); + builder.Writeln("Item 2"); + builder.ListFormat.RemoveNumbers(); + + // Creates the numbered list from NumberUppercaseLetterDot template. + List numberedList = listCollection.AddSingleLevelList(ListTemplate.NumberUppercaseLetterDot); + + // Writes the numbered list to the resulting document. + builder.Writeln("Numbered list starts below:"); + builder.ListFormat.List = numberedList; + builder.Writeln("Item 1"); + builder.Writeln("Item 2"); + + doc.Save(ArtifactsDir + "Lists.AddSingleLevelList.docx"); + //ExEnd:AddSingleLevelList + } } } \ No newline at end of file diff --git a/Examples/ApiExamples/ApiExamples/ExLoadOptions.cs b/Examples/ApiExamples/ApiExamples/ExLoadOptions.cs index da5950f19..ae8f13568 100644 --- a/Examples/ApiExamples/ApiExamples/ExLoadOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExLoadOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExLowCode.cs b/Examples/ApiExamples/ApiExamples/ExLowCode.cs index 941095b24..c533dbda0 100644 --- a/Examples/ApiExamples/ApiExamples/ExLowCode.cs +++ b/Examples/ApiExamples/ApiExamples/ExLowCode.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExMailMerge.cs b/Examples/ApiExamples/ApiExamples/ExMailMerge.cs index 4f9c7b7c3..138f7c707 100644 --- a/Examples/ApiExamples/ApiExamples/ExMailMerge.cs +++ b/Examples/ApiExamples/ApiExamples/ExMailMerge.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExMailMergeCustom.cs b/Examples/ApiExamples/ApiExamples/ExMailMergeCustom.cs index 95f2807bb..3971d5ea3 100644 --- a/Examples/ApiExamples/ApiExamples/ExMailMergeCustom.cs +++ b/Examples/ApiExamples/ApiExamples/ExMailMergeCustom.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExMailMergeCustomNested.cs b/Examples/ApiExamples/ApiExamples/ExMailMergeCustomNested.cs index 32a77c58b..c5c2f6755 100644 --- a/Examples/ApiExamples/ApiExamples/ExMailMergeCustomNested.cs +++ b/Examples/ApiExamples/ApiExamples/ExMailMergeCustomNested.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExMailMergeEvent.cs b/Examples/ApiExamples/ApiExamples/ExMailMergeEvent.cs index 140fe9c84..586c3a838 100644 --- a/Examples/ApiExamples/ApiExamples/ExMailMergeEvent.cs +++ b/Examples/ApiExamples/ApiExamples/ExMailMergeEvent.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExMarkdownLoadOptions.cs b/Examples/ApiExamples/ApiExamples/ExMarkdownLoadOptions.cs index f67f2d7e7..314ee6282 100644 --- a/Examples/ApiExamples/ApiExamples/ExMarkdownLoadOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExMarkdownLoadOptions.cs @@ -1,4 +1,11 @@ -using System; +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// + +using System; using System.IO; using System.Text; using Aspose.Words; diff --git a/Examples/ApiExamples/ApiExamples/ExMarkdownSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExMarkdownSaveOptions.cs index cfba8575d..2611a2527 100644 --- a/Examples/ApiExamples/ApiExamples/ExMarkdownSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExMarkdownSaveOptions.cs @@ -1,4 +1,10 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// + using System; using System.Drawing; using System.IO; diff --git a/Examples/ApiExamples/ApiExamples/ExMetered.cs b/Examples/ApiExamples/ApiExamples/ExMetered.cs index ba00916be..e4f94602f 100644 --- a/Examples/ApiExamples/ApiExamples/ExMetered.cs +++ b/Examples/ApiExamples/ApiExamples/ExMetered.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExMossDoc2Pdf.cs b/Examples/ApiExamples/ApiExamples/ExMossDoc2Pdf.cs index cece6a3d8..c2863c1dc 100644 --- a/Examples/ApiExamples/ApiExamples/ExMossDoc2Pdf.cs +++ b/Examples/ApiExamples/ApiExamples/ExMossDoc2Pdf.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExMossRtf2Docx.cs b/Examples/ApiExamples/ApiExamples/ExMossRtf2Docx.cs index e642ccb0d..91a5d6115 100644 --- a/Examples/ApiExamples/ApiExamples/ExMossRtf2Docx.cs +++ b/Examples/ApiExamples/ApiExamples/ExMossRtf2Docx.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExNode.cs b/Examples/ApiExamples/ApiExamples/ExNode.cs index 0a626feee..f6ab341e2 100644 --- a/Examples/ApiExamples/ApiExamples/ExNode.cs +++ b/Examples/ApiExamples/ApiExamples/ExNode.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExNodeImporter.cs b/Examples/ApiExamples/ApiExamples/ExNodeImporter.cs index 901b4f561..37bace797 100644 --- a/Examples/ApiExamples/ApiExamples/ExNodeImporter.cs +++ b/Examples/ApiExamples/ApiExamples/ExNodeImporter.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExOdtSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExOdtSaveOptions.cs index 1fa2a991f..60ab55fc1 100644 --- a/Examples/ApiExamples/ApiExamples/ExOdtSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExOdtSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExOoxmlSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExOoxmlSaveOptions.cs index cc13cb3a2..dd94e2147 100644 --- a/Examples/ApiExamples/ApiExamples/ExOoxmlSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExOoxmlSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExPageSetup.cs b/Examples/ApiExamples/ApiExamples/ExPageSetup.cs index c948776bd..699d49198 100644 --- a/Examples/ApiExamples/ApiExamples/ExPageSetup.cs +++ b/Examples/ApiExamples/ApiExamples/ExPageSetup.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExParagraph.cs b/Examples/ApiExamples/ApiExamples/ExParagraph.cs index d29d92377..0957ff452 100644 --- a/Examples/ApiExamples/ApiExamples/ExParagraph.cs +++ b/Examples/ApiExamples/ApiExamples/ExParagraph.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExParagraphFormat.cs b/Examples/ApiExamples/ApiExamples/ExParagraphFormat.cs index c91e4fe6c..5382cf7bc 100644 --- a/Examples/ApiExamples/ApiExamples/ExParagraphFormat.cs +++ b/Examples/ApiExamples/ApiExamples/ExParagraphFormat.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExPclSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExPclSaveOptions.cs index ce89fbc9b..c8416ae3d 100644 --- a/Examples/ApiExamples/ApiExamples/ExPclSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExPclSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExPdf2Word.cs b/Examples/ApiExamples/ApiExamples/ExPdf2Word.cs index ea35782f8..85895262d 100644 --- a/Examples/ApiExamples/ApiExamples/ExPdf2Word.cs +++ b/Examples/ApiExamples/ApiExamples/ExPdf2Word.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExPdfLoadOptions.cs b/Examples/ApiExamples/ApiExamples/ExPdfLoadOptions.cs index 886ab962a..4477002bb 100644 --- a/Examples/ApiExamples/ApiExamples/ExPdfLoadOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExPdfLoadOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExPdfSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExPdfSaveOptions.cs index 5b56f4221..79b4d0180 100644 --- a/Examples/ApiExamples/ApiExamples/ExPdfSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExPdfSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExPlainTextDocument.cs b/Examples/ApiExamples/ApiExamples/ExPlainTextDocument.cs index 6a3a89064..e5c388cb2 100644 --- a/Examples/ApiExamples/ApiExamples/ExPlainTextDocument.cs +++ b/Examples/ApiExamples/ApiExamples/ExPlainTextDocument.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExPrinting.cs b/Examples/ApiExamples/ApiExamples/ExPrinting.cs index 0701eaaad..b75a1d459 100644 --- a/Examples/ApiExamples/ApiExamples/ExPrinting.cs +++ b/Examples/ApiExamples/ApiExamples/ExPrinting.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExPsSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExPsSaveOptions.cs index 630d95a57..eb16296ea 100644 --- a/Examples/ApiExamples/ApiExamples/ExPsSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExPsSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExRange.cs b/Examples/ApiExamples/ApiExamples/ExRange.cs index 3b2f34221..bb0eb976d 100644 --- a/Examples/ApiExamples/ApiExamples/ExRange.cs +++ b/Examples/ApiExamples/ApiExamples/ExRange.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExRenameMergeFields.cs b/Examples/ApiExamples/ApiExamples/ExRenameMergeFields.cs index b0ae429f5..9e6075639 100644 --- a/Examples/ApiExamples/ApiExamples/ExRenameMergeFields.cs +++ b/Examples/ApiExamples/ApiExamples/ExRenameMergeFields.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExRendering.cs b/Examples/ApiExamples/ApiExamples/ExRendering.cs index 43eea114d..b3e322d26 100644 --- a/Examples/ApiExamples/ApiExamples/ExRendering.cs +++ b/Examples/ApiExamples/ApiExamples/ExRendering.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExReplaceHyperlinks.cs b/Examples/ApiExamples/ApiExamples/ExReplaceHyperlinks.cs index ef7a54eee..448fed35e 100644 --- a/Examples/ApiExamples/ApiExamples/ExReplaceHyperlinks.cs +++ b/Examples/ApiExamples/ApiExamples/ExReplaceHyperlinks.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExReportingEngine.cs b/Examples/ApiExamples/ApiExamples/ExReportingEngine.cs index 430caea0b..dc7719650 100644 --- a/Examples/ApiExamples/ApiExamples/ExReportingEngine.cs +++ b/Examples/ApiExamples/ApiExamples/ExReportingEngine.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExRevision.cs b/Examples/ApiExamples/ApiExamples/ExRevision.cs index 8f3a42e3d..0c816bfba 100644 --- a/Examples/ApiExamples/ApiExamples/ExRevision.cs +++ b/Examples/ApiExamples/ApiExamples/ExRevision.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided @@ -400,7 +400,7 @@ public void TrackRevisions() // We can accept/reject these revisions programmatically // by calling methods such as Document.AcceptAllRevisions, or each revision's Accept method. // In Microsoft Word, we can process them manually via "Review" -> "Changes". - doc.Save(ArtifactsDir + "Document.StartTrackRevisions.docx"); + doc.Save(ArtifactsDir + "Revision.StartTrackRevisions.docx"); //ExEnd } @@ -600,10 +600,10 @@ public void CompareOptions() }; docOriginal.Compare(docEdited, "John Doe", DateTime.Now, compareOptions); - docOriginal.Save(ArtifactsDir + "Document.CompareOptions.docx"); + docOriginal.Save(ArtifactsDir + "Revision.CompareOptions.docx"); //ExEnd - docOriginal = new Document(ArtifactsDir + "Document.CompareOptions.docx"); + docOriginal = new Document(ArtifactsDir + "Revision.CompareOptions.docx"); TestUtil.VerifyFootnote(FootnoteType.Endnote, true, string.Empty, "OriginalEdited endnote text.", (Footnote)docOriginal.GetChild(NodeType.Footnote, 0, true)); @@ -662,7 +662,7 @@ public void LayoutOptionsRevisions() doc.LayoutOptions.RevisionOptions.ShowRevisionBars = false; doc.LayoutOptions.RevisionOptions.RevisionBarsPosition = HorizontalAlignment.Right; - doc.Save(ArtifactsDir + "Document.LayoutOptionsRevisions.pdf"); + doc.Save(ArtifactsDir + "Revision.LayoutOptionsRevisions.pdf"); //ExEnd } diff --git a/Examples/ApiExamples/ApiExamples/ExRtfLoadOptions.cs b/Examples/ApiExamples/ApiExamples/ExRtfLoadOptions.cs index 25341080e..139110341 100644 --- a/Examples/ApiExamples/ApiExamples/ExRtfLoadOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExRtfLoadOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExRtfSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExRtfSaveOptions.cs index 707e8e31a..98eec61dd 100644 --- a/Examples/ApiExamples/ApiExamples/ExRtfSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExRtfSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExSavingCallback.cs b/Examples/ApiExamples/ApiExamples/ExSavingCallback.cs index d06fcdca6..6755f9cde 100644 --- a/Examples/ApiExamples/ApiExamples/ExSavingCallback.cs +++ b/Examples/ApiExamples/ApiExamples/ExSavingCallback.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExSection.cs b/Examples/ApiExamples/ApiExamples/ExSection.cs index ba951d56e..3b4e36cc1 100644 --- a/Examples/ApiExamples/ApiExamples/ExSection.cs +++ b/Examples/ApiExamples/ApiExamples/ExSection.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExShape.cs b/Examples/ApiExamples/ApiExamples/ExShape.cs index 7062b5199..e6552152b 100644 --- a/Examples/ApiExamples/ApiExamples/ExShape.cs +++ b/Examples/ApiExamples/ApiExamples/ExShape.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided @@ -1253,9 +1253,6 @@ public void LinkedChartSourceFullName() var sourceFullName = shape.Chart.SourceFullName; Assert.True(sourceFullName.Contains("Examples\\Data\\Spreadsheet.xlsx")); - - sourceFullName = "D:\\Documents\\ChartData.xlsx"; - Assert.True(sourceFullName.Equals("D:\\Documents\\ChartData.xlsx", StringComparison.Ordinal)); //ExEnd } @@ -2329,7 +2326,6 @@ public void CreateLinkBetweenTextBoxes() // Break the forward link between textBox2 and textBox3, and then verify that they are no longer linked. textBox3.Previous.BreakForwardLink(); - Assert.IsTrue(textBox2.Next == null); Assert.IsTrue(textBox3.Previous == null); } diff --git a/Examples/ApiExamples/ApiExamples/ExSignDocumentCustom.cs b/Examples/ApiExamples/ApiExamples/ExSignDocumentCustom.cs index 65198a97f..ebc04e617 100644 --- a/Examples/ApiExamples/ApiExamples/ExSignDocumentCustom.cs +++ b/Examples/ApiExamples/ApiExamples/ExSignDocumentCustom.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExSmartTag.cs b/Examples/ApiExamples/ApiExamples/ExSmartTag.cs index 934d6470b..49e010a35 100644 --- a/Examples/ApiExamples/ApiExamples/ExSmartTag.cs +++ b/Examples/ApiExamples/ApiExamples/ExSmartTag.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExStructuredDocumentTag.cs b/Examples/ApiExamples/ApiExamples/ExStructuredDocumentTag.cs index 069ffc6fd..b0a654e2d 100644 --- a/Examples/ApiExamples/ApiExamples/ExStructuredDocumentTag.cs +++ b/Examples/ApiExamples/ApiExamples/ExStructuredDocumentTag.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExStyles.cs b/Examples/ApiExamples/ApiExamples/ExStyles.cs index f8aafe729..c1b9f89ee 100644 --- a/Examples/ApiExamples/ApiExamples/ExStyles.cs +++ b/Examples/ApiExamples/ApiExamples/ExStyles.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExSvgSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExSvgSaveOptions.cs index 0a7108cb4..a120bcd93 100644 --- a/Examples/ApiExamples/ApiExamples/ExSvgSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExSvgSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExTabStop.cs b/Examples/ApiExamples/ApiExamples/ExTabStop.cs index d245a90b6..2c04d5e05 100644 --- a/Examples/ApiExamples/ApiExamples/ExTabStop.cs +++ b/Examples/ApiExamples/ApiExamples/ExTabStop.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExTable.cs b/Examples/ApiExamples/ApiExamples/ExTable.cs index 170b0a4a3..3a58e830c 100644 --- a/Examples/ApiExamples/ApiExamples/ExTable.cs +++ b/Examples/ApiExamples/ApiExamples/ExTable.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExTableColumn.cs b/Examples/ApiExamples/ApiExamples/ExTableColumn.cs index ec3b63a1d..862b49fe8 100644 --- a/Examples/ApiExamples/ApiExamples/ExTableColumn.cs +++ b/Examples/ApiExamples/ApiExamples/ExTableColumn.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExThemes.cs b/Examples/ApiExamples/ApiExamples/ExThemes.cs index 7514ebbd9..92d5de987 100644 --- a/Examples/ApiExamples/ApiExamples/ExThemes.cs +++ b/Examples/ApiExamples/ApiExamples/ExThemes.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExTxtLoadOptions.cs b/Examples/ApiExamples/ApiExamples/ExTxtLoadOptions.cs index defd93cf5..71cf817d6 100644 --- a/Examples/ApiExamples/ApiExamples/ExTxtLoadOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExTxtLoadOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExTxtSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExTxtSaveOptions.cs index 3c3b26b03..04946cbdd 100644 --- a/Examples/ApiExamples/ApiExamples/ExTxtSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExTxtSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided @@ -144,28 +144,29 @@ public void ExportHeadersFooters(TxtExportHeadersFootersMode txtExportHeadersFoo string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.ExportHeadersFooters.txt"); + string newLine = Environment.NewLine; switch (txtExportHeadersFootersMode) { case TxtExportHeadersFootersMode.AllAtEnd: - Assert.AreEqual("Page 1\r\n" + - "Page 2\r\n" + - "Page 3\r\n" + - "Even header\r\n\r\n" + - "Primary header\r\n\r\n" + - "Even footer\r\n\r\n" + - "Primary footer\r\n\r\n", docText); + Assert.AreEqual($"Page 1{newLine}" + + $"Page 2{newLine}" + + $"Page 3{newLine}" + + $"Even header{newLine}{newLine}" + + $"Primary header{newLine}{newLine}" + + $"Even footer{newLine}{newLine}" + + $"Primary footer{newLine}{newLine}", docText); break; case TxtExportHeadersFootersMode.PrimaryOnly: - Assert.AreEqual("Primary header\r\n" + - "Page 1\r\n" + - "Page 2\r\n" + - "Page 3\r\n" + - "Primary footer\r\n", docText); + Assert.AreEqual($"Primary header{newLine}" + + $"Page 1{newLine}" + + $"Page 2{newLine}" + + $"Page 3{newLine}" + + $"Primary footer{newLine}", docText); break; case TxtExportHeadersFootersMode.None: - Assert.AreEqual("Page 1\r\n" + - "Page 2\r\n" + - "Page 3\r\n", docText); + Assert.AreEqual($"Page 1{newLine}" + + $"Page 2{newLine}" + + $"Page 3{newLine}", docText); break; } //ExEnd @@ -249,18 +250,20 @@ public void SimplifyListLabels(bool simplifyListLabels) string docText = File.ReadAllText(ArtifactsDir + "TxtSaveOptions.SimplifyListLabels.txt"); + string newLine = Environment.NewLine; + if (simplifyListLabels) - Assert.AreEqual("* Item 1\r\n" + - " > Item 2\r\n" + - " + Item 3\r\n" + - " - Item 4\r\n" + - " o Item 5\r\n", docText); + Assert.AreEqual($"* Item 1{newLine}" + + $" > Item 2{newLine}" + + $" + Item 3{newLine}" + + $" - Item 4{newLine}" + + $" o Item 5{newLine}", docText); else - Assert.AreEqual("· Item 1\r\n" + - "o Item 2\r\n" + - "§ Item 3\r\n" + - "· Item 4\r\n" + - "o Item 5\r\n", docText); + Assert.AreEqual($"· Item 1{newLine}" + + $"o Item 2{newLine}" + + $"§ Item 3{newLine}" + + $"· Item 4{newLine}" + + $"o Item 5{newLine}", docText); //ExEnd } diff --git a/Examples/ApiExamples/ApiExamples/ExUtilityClasses.cs b/Examples/ApiExamples/ApiExamples/ExUtilityClasses.cs index ed00ac13f..80cf49d53 100644 --- a/Examples/ApiExamples/ApiExamples/ExUtilityClasses.cs +++ b/Examples/ApiExamples/ApiExamples/ExUtilityClasses.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExVariableCollection.cs b/Examples/ApiExamples/ApiExamples/ExVariableCollection.cs index 752921929..658d5e5f0 100644 --- a/Examples/ApiExamples/ApiExamples/ExVariableCollection.cs +++ b/Examples/ApiExamples/ApiExamples/ExVariableCollection.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExVbaProject.cs b/Examples/ApiExamples/ApiExamples/ExVbaProject.cs index 985783545..18fbc0691 100644 --- a/Examples/ApiExamples/ApiExamples/ExVbaProject.cs +++ b/Examples/ApiExamples/ApiExamples/ExVbaProject.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExViewOptions.cs b/Examples/ApiExamples/ApiExamples/ExViewOptions.cs index e2540d327..774cc3976 100644 --- a/Examples/ApiExamples/ApiExamples/ExViewOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExViewOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExWordML2003SaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExWordML2003SaveOptions.cs index b62648e7c..a1b4c0437 100644 --- a/Examples/ApiExamples/ApiExamples/ExWordML2003SaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExWordML2003SaveOptions.cs @@ -1,10 +1,11 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided // "as is", without warranty of any kind, either expressed or implied. ////////////////////////////////////////////////////////////////////////// +using System; using System.IO; using Aspose.Words; using Aspose.Words.Saving; @@ -41,19 +42,20 @@ public void PrettyFormat(bool prettyFormat) doc.Save(ArtifactsDir + "WordML2003SaveOptions.PrettyFormat.xml", options); string fileContents = File.ReadAllText(ArtifactsDir + "WordML2003SaveOptions.PrettyFormat.xml"); + string newLine = Environment.NewLine; if (prettyFormat) Assert.True(fileContents.Contains( - "\r\n\t\t" + - "1\r\n\t\t" + - "0\r\n\t\t" + - "1\r\n\t\t" + - "0\r\n\t\t" + - "0\r\n\t\t" + - "1\r\n\t\t" + - "1\r\n\t\t" + - "0\r\n\t\t" + - "11.5606\r\n\t" + + $"{newLine}\t\t" + + $"1{newLine}\t\t" + + $"0{newLine}\t\t" + + $"1{newLine}\t\t" + + $"0{newLine}\t\t" + + $"0{newLine}\t\t" + + $"1{newLine}\t\t" + + $"1{newLine}\t\t" + + $"0{newLine}\t\t" + + $"11.5606{newLine}\t" + "")); else Assert.True(fileContents.Contains( diff --git a/Examples/ApiExamples/ApiExamples/ExXamlFixedSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExXamlFixedSaveOptions.cs index ef089f85d..2a3817d67 100644 --- a/Examples/ApiExamples/ApiExamples/ExXamlFixedSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExXamlFixedSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExXamlFlowSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExXamlFlowSaveOptions.cs index 6816c55db..565835760 100644 --- a/Examples/ApiExamples/ApiExamples/ExXamlFlowSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExXamlFlowSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExXlsxSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExXlsxSaveOptions.cs index 7c54a1842..ee1ffbd9d 100644 --- a/Examples/ApiExamples/ApiExamples/ExXlsxSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExXlsxSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/ExXpsSaveOptions.cs b/Examples/ApiExamples/ApiExamples/ExXpsSaveOptions.cs index 17cd32dcd..a1d26a07f 100644 --- a/Examples/ApiExamples/ApiExamples/ExXpsSaveOptions.cs +++ b/Examples/ApiExamples/ApiExamples/ExXpsSaveOptions.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/ApiExamples/TestUtil.cs b/Examples/ApiExamples/ApiExamples/TestUtil.cs index f435228ad..3d55aee0a 100644 --- a/Examples/ApiExamples/ApiExamples/TestUtil.cs +++ b/Examples/ApiExamples/ApiExamples/TestUtil.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2001-2024 Aspose Pty Ltd. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. // // This file is part of Aspose.Words. The source code in this file // is only intended as a supplement to the documentation, and is provided diff --git a/Examples/ApiExamples/Runner.MAUI/Runner.MAUI.csproj b/Examples/ApiExamples/Runner.MAUI/Runner.MAUI.csproj index c102ef579..abeef24c6 100644 --- a/Examples/ApiExamples/Runner.MAUI/Runner.MAUI.csproj +++ b/Examples/ApiExamples/Runner.MAUI/Runner.MAUI.csproj @@ -49,20 +49,20 @@
- - - - + + + + - + - + - + diff --git a/Examples/DocsExamples/Docker/Docker.csproj b/Examples/DocsExamples/Docker/Docker.csproj index b16a432a2..c14ebad1f 100644 --- a/Examples/DocsExamples/Docker/Docker.csproj +++ b/Examples/DocsExamples/Docker/Docker.csproj @@ -6,7 +6,7 @@ - + diff --git a/Examples/DocsExamples/DocsExamples/AI-powered Features/Working with AI.cs b/Examples/DocsExamples/DocsExamples/AI-powered Features/Working with AI.cs new file mode 100644 index 000000000..873b74e1e --- /dev/null +++ b/Examples/DocsExamples/DocsExamples/AI-powered Features/Working with AI.cs @@ -0,0 +1,73 @@ +using Aspose.Words.AI; +using Aspose.Words; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DocsExamples.AI_powered_Features +{ + public class Working_with_AI : DocsExamplesBase + { + [Test, Explicit("This test should be run manually to manage API requests amount")] + public void AiSummarize() + { + //ExStart:AiSummarize + //GistId:1e379bedb2b759c1be24c64aad54d13d + Document firstDoc = new Document(MyDir + "Big document.docx"); + Document secondDoc = new Document(MyDir + "Document.docx"); + + string apiKey = Environment.GetEnvironmentVariable("API_KEY"); + // Use OpenAI or Google generative language models. + IAiModelText model = ((OpenAiModel)AiModel.Create(AiModelType.Gpt4OMini).WithApiKey(apiKey)).WithOrganization("Organization").WithProject("Project"); + + SummarizeOptions options = new SummarizeOptions(); + + options.SummaryLength = SummaryLength.Short; + Document oneDocumentSummary = model.Summarize(firstDoc, options); + oneDocumentSummary.Save(ArtifactsDir + "AI.AiSummarize.One.docx"); + + options.SummaryLength = SummaryLength.Long; + Document multiDocumentSummary = model.Summarize(new Document[] { firstDoc, secondDoc }, options); + multiDocumentSummary.Save(ArtifactsDir + "AI.AiSummarize.Multi.docx"); + //ExEnd:AiSummarize + } + + [Test, Ignore("This test should be run manually to manage API requests amount")] + public void AiTranslate() + { + //ExStart:AiTranslate + //GistId:ea14b3e44c0233eecd663f783a21c4f6 + Document doc = new Document(MyDir + "Document.docx"); + + string apiKey = Environment.GetEnvironmentVariable("API_KEY"); + // Use Google generative language models. + IAiModelText model = (GoogleAiModel)AiModel.Create(AiModelType.Gemini15Flash).WithApiKey(apiKey); + + Document translatedDoc = model.Translate(doc, Language.Arabic); + translatedDoc.Save(ArtifactsDir + "AI.AiTranslate.docx"); + //ExEnd:AiTranslate + } + + [Test, Ignore("This test should be run manually to manage API requests amount")] + public void AiGrammar() + { + //ExStart:AiGrammar + //GistId:98a646d19cd7708ed0cd3d97b993a053 + Document doc = new Document(MyDir + "Big document.docx"); + + string apiKey = Environment.GetEnvironmentVariable("API_KEY"); + // Use OpenAI generative language models. + IAiModelText model = (IAiModelText)AiModel.Create(AiModelType.Gpt4OMini).WithApiKey(apiKey); + + CheckGrammarOptions grammarOptions = new CheckGrammarOptions(); + grammarOptions.ImproveStylistics = true; + + Document proofedDoc = model.CheckGrammar(doc, grammarOptions); + proofedDoc.Save(ArtifactsDir + "AI.AiGrammar.docx"); + //ExEnd:AiGrammar + } + } +} diff --git a/Examples/DocsExamples/DocsExamples/DocsExamples.csproj b/Examples/DocsExamples/DocsExamples/DocsExamples.csproj index 68b60251a..782f1efaa 100644 --- a/Examples/DocsExamples/DocsExamples/DocsExamples.csproj +++ b/Examples/DocsExamples/DocsExamples/DocsExamples.csproj @@ -116,13 +116,13 @@ - - - - - + + + + + - + diff --git a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Load Options/Working with LoadOptions.cs b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Load Options/Working with LoadOptions.cs index 844e807fc..6f93bcfb2 100644 --- a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Load Options/Working with LoadOptions.cs +++ b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Load Options/Working with LoadOptions.cs @@ -15,6 +15,7 @@ public class WorkingWithLoadOptions : DocsExamplesBase public void UpdateDirtyFields() { //ExStart:UpdateDirtyFields + //GistId:08db64c4d86842c4afd1ecb925ed07c4 LoadOptions loadOptions = new LoadOptions { UpdateDirtyFields = true }; Document doc = new Document(MyDir + "Dirty field.docx", loadOptions); @@ -53,6 +54,7 @@ public void LoadEncryptedDocumentWithoutPassword() public void ConvertShapeToOfficeMath() { //ExStart:ConvertShapeToOfficeMath + //GistId:ad463bf5f128fe6e6c1485df3c046a4c LoadOptions loadOptions = new LoadOptions { ConvertShapeToOfficeMath = true }; Document doc = new Document(MyDir + "Office math.docx", loadOptions); diff --git a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Load Options/Working with TxtLoadOptions.cs b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Load Options/Working with TxtLoadOptions.cs index d04261cd4..45f9a7445 100644 --- a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Load Options/Working with TxtLoadOptions.cs +++ b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Load Options/Working with TxtLoadOptions.cs @@ -1,8 +1,10 @@ using System; using System.IO; +using System.Runtime.InteropServices.ComTypes; using System.Text; using Aspose.Words; using Aspose.Words.Loading; +using Aspose.Words.Saving; using NUnit.Framework; namespace DocsExamples.File_Formats_and_Conversions.Load_Options @@ -13,6 +15,7 @@ public class WorkingWithTxtLoadOptions : DocsExamplesBase public void DetectNumberingWithWhitespaces() { //ExStart:DetectNumberingWithWhitespaces + //GistId:ddafc3430967fb4f4f70085fa577d01a // Create a plaintext document in the form of a string with parts that may be interpreted as lists. // Upon loading, the first three lists will always be detected by Aspose.Words, // and List objects will be created for them after loading. @@ -49,6 +52,7 @@ public void DetectNumberingWithWhitespaces() public void HandleSpacesOptions() { //ExStart:HandleSpacesOptions + //GistId:ddafc3430967fb4f4f70085fa577d01a const string textDoc = " Line 1 \n" + " Line 2 \n" + " Line 3 "; @@ -69,6 +73,7 @@ public void HandleSpacesOptions() public void DocumentTextDirection() { //ExStart:DocumentTextDirection + //GistId:ddafc3430967fb4f4f70085fa577d01a TxtLoadOptions loadOptions = new TxtLoadOptions { DocumentDirection = DocumentDirection.Auto }; Document doc = new Document(MyDir + "Hebrew text.txt", loadOptions); @@ -79,5 +84,48 @@ public void DocumentTextDirection() doc.Save(ArtifactsDir + "WorkingWithTxtLoadOptions.DocumentTextDirection.docx"); //ExEnd:DocumentTextDirection } + + [Test] + public void ExportHeadersFootersMode() + { + //ExStart:ExportHeadersFootersMode + //GistId:ddafc3430967fb4f4f70085fa577d01a + Document doc = new Document(); + + // Insert even and primary headers/footers into the document. + // The primary header/footers will override the even headers/footers. + doc.FirstSection.HeadersFooters.Add(new HeaderFooter(doc, HeaderFooterType.HeaderEven)); + doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderEven].AppendParagraph("Even header"); + doc.FirstSection.HeadersFooters.Add(new HeaderFooter(doc, HeaderFooterType.FooterEven)); + doc.FirstSection.HeadersFooters[HeaderFooterType.FooterEven].AppendParagraph("Even footer"); + doc.FirstSection.HeadersFooters.Add(new HeaderFooter(doc, HeaderFooterType.HeaderPrimary)); + doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].AppendParagraph("Primary header"); + doc.FirstSection.HeadersFooters.Add(new HeaderFooter(doc, HeaderFooterType.FooterPrimary)); + doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].AppendParagraph("Primary footer"); + + // Insert pages to display these headers and footers. + DocumentBuilder builder = new DocumentBuilder(doc); + builder.Writeln("Page 1"); + builder.InsertBreak(BreakType.PageBreak); + builder.Writeln("Page 2"); + builder.InsertBreak(BreakType.PageBreak); + builder.Write("Page 3"); + + TxtSaveOptions options = new TxtSaveOptions(); + options.SaveFormat = SaveFormat.Text; + + // All headers and footers are placed at the very end of the output document. + options.ExportHeadersFootersMode = TxtExportHeadersFootersMode.AllAtEnd; + doc.Save(ArtifactsDir + "WorkingWithTxtLoadOptions.HeadersFootersMode.AllAtEnd.txt", options); + + // Only primary headers and footers are exported at the beginning and end of each section. + options.ExportHeadersFootersMode = TxtExportHeadersFootersMode.PrimaryOnly; + doc.Save(ArtifactsDir + "WorkingWithTxtLoadOptions.HeadersFootersMode.PrimaryOnly.txt", options); + + // No headers and footers are exported. + options.ExportHeadersFootersMode = TxtExportHeadersFootersMode.None; + doc.Save(ArtifactsDir + "WorkingWithTxtLoadOptions.HeadersFootersMode.None.txt", options); + //ExEnd:ExportHeadersFootersMode + } } } diff --git a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with MarkdownSaveOptions.cs b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with MarkdownSaveOptions.cs index 85cec8dd4..88aed2e28 100644 --- a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with MarkdownSaveOptions.cs +++ b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with MarkdownSaveOptions.cs @@ -8,9 +8,10 @@ namespace DocsExamples.File_Formats_and_Conversions.Save_Options public class WorkingWithMarkdownSaveOptions : DocsExamplesBase { [Test] - public void ExportIntoMarkdownWithTableContentAlignment() + public void MarkdownTableContentAlignment() { - //ExStart:ExportIntoMarkdownWithTableContentAlignment + //ExStart:MarkdownTableContentAlignment + //GistId:19de942ef8827201c1dca99f76c59133 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -37,7 +38,7 @@ public void ExportIntoMarkdownWithTableContentAlignment() // The alignment in this case will be taken from the first paragraph in corresponding table column. saveOptions.TableContentAlignment = TableContentAlignment.Auto; doc.Save(ArtifactsDir + "WorkingWithMarkdownSaveOptions.AutoTableContentAlignment.md", saveOptions); - //ExEnd:ExportIntoMarkdownWithTableContentAlignment + //ExEnd:MarkdownTableContentAlignment } [Test] diff --git a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with RtfSaveOptions.cs b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with RtfSaveOptions.cs index 6bfa6d7b1..4e77479e7 100644 --- a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with RtfSaveOptions.cs +++ b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with RtfSaveOptions.cs @@ -10,6 +10,7 @@ public class WorkingWithRtfSaveOptions : DocsExamplesBase public void SavingImagesAsWmf() { //ExStart:SavingImagesAsWmf + //GistId:6f849e51240635a6322ab0460938c922 Document doc = new Document(MyDir + "Document.docx"); RtfSaveOptions saveOptions = new RtfSaveOptions { SaveImagesAsWmf = true }; diff --git a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with TxtSaveOptions.cs b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with TxtSaveOptions.cs index 8b252fc15..3c6f1ce84 100644 --- a/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with TxtSaveOptions.cs +++ b/Examples/DocsExamples/DocsExamples/File Formats and Conversions/Save Options/Working with TxtSaveOptions.cs @@ -10,6 +10,7 @@ public class WorkingWithTxtSaveOptions : DocsExamplesBase public void AddBidiMarks() { //ExStart:AddBidiMarks + //GistId:ddafc3430967fb4f4f70085fa577d01a Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -25,9 +26,10 @@ public void AddBidiMarks() } [Test] - public void UseTabCharacterPerLevelForListIndentation() + public void UseTabForListIndentation() { - //ExStart:UseTabCharacterPerLevelForListIndentation + //ExStart:UseTabForListIndentation + //GistId:ddafc3430967fb4f4f70085fa577d01a Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -43,14 +45,15 @@ public void UseTabCharacterPerLevelForListIndentation() saveOptions.ListIndentation.Count = 1; saveOptions.ListIndentation.Character = '\t'; - doc.Save(ArtifactsDir + "WorkingWithTxtSaveOptions.UseTabCharacterPerLevelForListIndentation.txt", saveOptions); - //ExEnd:UseTabCharacterPerLevelForListIndentation + doc.Save(ArtifactsDir + "WorkingWithTxtSaveOptions.UseTabForListIndentation.txt", saveOptions); + //ExEnd:UseTabForListIndentation } [Test] - public void UseSpaceCharacterPerLevelForListIndentation() + public void UseSpaceForListIndentation() { - //ExStart:UseSpaceCharacterPerLevelForListIndentation + //ExStart:UseSpaceForListIndentation + //GistId:ddafc3430967fb4f4f70085fa577d01a Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -66,8 +69,8 @@ public void UseSpaceCharacterPerLevelForListIndentation() saveOptions.ListIndentation.Count = 3; saveOptions.ListIndentation.Character = ' '; - doc.Save(ArtifactsDir + "WorkingWithTxtSaveOptions.UseSpaceCharacterPerLevelForListIndentation.txt", saveOptions); - //ExEnd:UseSpaceCharacterPerLevelForListIndentation + doc.Save(ArtifactsDir + "WorkingWithTxtSaveOptions.UseSpaceForListIndentation.txt", saveOptions); + //ExEnd:UseSpaceForListIndentation } } } \ No newline at end of file diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Extract content.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Extract content.cs index afb6643e0..8448ac1b3 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Extract content.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Extract content.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; using Aspose.Words; @@ -387,6 +387,7 @@ public void ExtractImages() public void ExtractContentBasedOnStyles() { //ExStart:ExtractContentBasedOnStyles + //GistId:a73b495f610523670f0847331ef4d6fc Document doc = new Document(MyDir + "Styles.docx"); List paragraphs = ParagraphsByStyleName(doc, "Heading 1"); @@ -404,6 +405,7 @@ public void ExtractContentBasedOnStyles() } //ExStart:RunsByStyleName + //GistId:a73b495f610523670f0847331ef4d6fc public List RunsByStyleName(Document doc, string styleName) { List runsWithStyle = new List(); diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Find and replace.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Find and replace.cs index 022c9b0d6..7c9234762 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Find and replace.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Find and replace.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Generic; +using System.Diagnostics; using System.Drawing; using System.Text; using System.Text.RegularExpressions; @@ -9,6 +10,7 @@ using Aspose.Words.Replacing; using Aspose.Words.Tables; using NUnit.Framework; +using static DocsExamples.Programming_with_Documents.Working_with_Document.AddContentUsingDocumentBuilder; namespace DocsExamples.Programming_with_Documents.Contents_Management { @@ -155,6 +157,7 @@ public void MetaCharactersInSearchPattern() public void ReplaceTextContainingMetaCharacters() { //ExStart:ReplaceTextContainingMetaCharacters + //GistId:27c3408b2c7fbee8d6dc6a1c8b61c105 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -179,6 +182,19 @@ public void ReplaceTextContainingMetaCharacters() //ExEnd:ReplaceTextContainingMetaCharacters } + [Test] + public void HighlightColor() + { + //ExStart:HighlightColor + //GistId:27c3408b2c7fbee8d6dc6a1c8b61c105 + Document doc = new Document(MyDir + "Footer.docx"); + + FindReplaceOptions options = new FindReplaceOptions(); + options.ApplyFont.HighlightColor = Color.DarkOrange; + doc.Range.Replace(new Regex("(header|footer)"), "", options); + //ExEnd:HighlightColor + } + [Test] public void IgnoreTextInsideFields() { @@ -207,6 +223,7 @@ public void IgnoreTextInsideFields() public void IgnoreTextInsideDeleteRevisions() { //ExStart:IgnoreTextInsideDeleteRevisions + //GistId:27c3408b2c7fbee8d6dc6a1c8b61c105 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -301,13 +318,13 @@ ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) public void ReplaceTextInFooter() { //ExStart:ReplaceTextInFooter + //GistId:27c3408b2c7fbee8d6dc6a1c8b61c105 Document doc = new Document(MyDir + "Footer.docx"); HeaderFooterCollection headersFooters = doc.FirstSection.HeadersFooters; HeaderFooter footer = headersFooters[HeaderFooterType.FooterPrimary]; FindReplaceOptions options = new FindReplaceOptions { MatchCase = false, FindWholeWordsOnly = false }; - footer.Range.Replace("(C) 2006 Aspose Pty Ltd.", "Copyright (C) 2020 by Aspose Pty Ltd.", options); doc.Save(ArtifactsDir + "FindAndReplace.ReplaceTextInFooter.docx"); @@ -496,6 +513,7 @@ ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) [Test] //ExStart:ReplaceWithHtml + //GistId:27c3408b2c7fbee8d6dc6a1c8b61c105 public void ReplaceWithHtml() { Document doc = new Document(); @@ -542,6 +560,7 @@ ReplaceAction IReplacingCallback.Replacing(ReplacingArgs args) public void ReplaceWithRegex() { //ExStart:ReplaceWithRegex + //GistId:27c3408b2c7fbee8d6dc6a1c8b61c105 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -576,12 +595,13 @@ public void RecognizeAndSubstitutionsWithinReplacementPatterns() public void ReplaceWithString() { //ExStart:ReplaceWithString + //GistId:27c3408b2c7fbee8d6dc6a1c8b61c105 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); - builder.Writeln("sad mad bad"); + builder.Writeln("Hello _CustomerName_,"); - doc.Range.Replace("sad", "bad", new FindReplaceOptions(FindReplaceDirection.Forward)); + doc.Range.Replace("_CustomerName_", "James Bond", new FindReplaceOptions(FindReplaceDirection.Forward)); doc.Save(ArtifactsDir + "FindAndReplace.ReplaceWithString.docx"); //ExEnd:ReplaceWithString @@ -636,5 +656,38 @@ public void ReplaceTextInTable() doc.Save(ArtifactsDir + "FindAndReplace.ReplaceTextInTable.docx"); //ExEnd:ReplaceText } + + //ExStart:LineCounter + //GistId:27c3408b2c7fbee8d6dc6a1c8b61c105 + [Test] //ExSkip + public void LineCounter() + { + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + + builder.Writeln("This is first line"); + builder.Writeln("Second line"); + builder.Writeln("And last line"); + + // Prepend each line with line number. + FindReplaceOptions opt = new FindReplaceOptions() { ReplacingCallback = new LineCounterCallback() }; + doc.Range.Replace(new Regex("[^&p]*&p"), "", opt); + + doc.Save(ArtifactsDir + "FindAndReplace.LineCounter.docx"); + } + + internal class LineCounterCallback : IReplacingCallback + { + public ReplaceAction Replacing(ReplacingArgs args) + { + Debug.WriteLine(args.Match.Value); + + args.Replacement = string.Format("{0} {1}", mCounter++, args.Match.Value); + return ReplaceAction.Replace; + } + + private int mCounter = 1; + } + //ExEnd:LineCounter } } diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Remove content.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Remove content.cs index 6b7eba1ab..71a3c940d 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Remove content.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Remove content.cs @@ -87,7 +87,8 @@ public void RemoveFooters() } [Test] - //ExStart:RemoveTOCFromDocument + //ExStart:RemoveToc + //GistId:db118a3e1559b9c88355356df9d7ea10 public void RemoveToc() { Document doc = new Document(MyDir + "Table of contents.docx"); @@ -146,6 +147,6 @@ public void RemoveTableOfContents(Document doc, int index) node.Remove(); } } - //ExEnd:RemoveTOCFromDocument + //ExEnd:RemoveToc } } \ No newline at end of file diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with Bookmarks.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with Bookmarks.cs index 52ce2c456..d4dcafcff 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with Bookmarks.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with Bookmarks.cs @@ -13,8 +13,8 @@ internal class WorkingWithBookmarks : DocsExamplesBase public void AccessBookmarks() { //ExStart:AccessBookmarks + //GistId:c4555b1a088856e21394104faeb86e51 Document doc = new Document(MyDir + "Bookmarks.docx"); - // By index: Bookmark bookmark1 = doc.Range.Bookmarks[0]; // By name: @@ -26,6 +26,7 @@ public void AccessBookmarks() public void UpdateBookmarkData() { //ExStart:UpdateBookmarkData + //GistId:c4555b1a088856e21394104faeb86e51 Document doc = new Document(MyDir + "Bookmarks.docx"); Bookmark bookmark = doc.Range.Bookmarks["MyBookmark1"]; @@ -42,6 +43,7 @@ public void UpdateBookmarkData() public void BookmarkTableColumns() { //ExStart:BookmarkTable + //GistId:c4555b1a088856e21394104faeb86e51 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -71,6 +73,7 @@ public void BookmarkTableColumns() //ExEnd:BookmarkTable //ExStart:BookmarkTableColumns + //GistId:c4555b1a088856e21394104faeb86e51 foreach (Bookmark bookmark in doc.Range.Bookmarks) { Console.WriteLine("Bookmark: {0}{1}", bookmark.Name, bookmark.IsColumn ? " (Column)" : ""); @@ -148,6 +151,7 @@ private void AppendBookmarkedText(NodeImporter importer, Bookmark srcBookmark, C public void CreateBookmark() { //ExStart:CreateBookmark + //GistId:c4555b1a088856e21394104faeb86e51 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -173,6 +177,7 @@ public void CreateBookmark() public void ShowHideBookmarks() { //ExStart:ShowHideBookmarks + //GistId:c4555b1a088856e21394104faeb86e51 Document doc = new Document(MyDir + "Bookmarks.docx"); ShowHideBookmarkedContent(doc, "MyBookmark1", true); @@ -182,6 +187,7 @@ public void ShowHideBookmarks() } //ExStart:ShowHideBookmarkedContent + //GistId:c4555b1a088856e21394104faeb86e51 public void ShowHideBookmarkedContent(Document doc, string bookmarkName, bool isHidden) { Bookmark bm = doc.Range.Bookmarks[bookmarkName]; diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with Ranges.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with Ranges.cs index f63f28ae7..bc2ae4bcb 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with Ranges.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with Ranges.cs @@ -9,6 +9,7 @@ internal class WorkingWithRanges : DocsExamplesBase public void RangesDeleteText() { //ExStart:RangesDeleteText + //GistId:9164e9c0658006e51db723b0742c12fc Document doc = new Document(MyDir + "Document.docx"); doc.Sections[0].Range.Delete(); //ExEnd:RangesDeleteText @@ -18,6 +19,7 @@ public void RangesDeleteText() public void RangesGetText() { //ExStart:RangesGetText + //GistId:9164e9c0658006e51db723b0742c12fc Document doc = new Document(MyDir + "Document.docx"); string text = doc.Range.Text; //ExEnd:RangesGetText diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with SDT.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with SDT.cs index a650d0f3b..3021996d6 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with SDT.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with SDT.cs @@ -12,23 +12,25 @@ namespace DocsExamples.Programming_with_Documents.Contents_Management internal class WorkingWithSdt : DocsExamplesBase { [Test] - public void CheckBoxTypeContentControl() + public void SdtCheckBox() { - //ExStart:CheckBoxTypeContentControl + //ExStart:SdtCheckBox + //GistId:089defec1b191de967e6099effeabda7 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); StructuredDocumentTag sdtCheckBox = new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline); builder.InsertNode(sdtCheckBox); - doc.Save(ArtifactsDir + "WorkingWithSdt.CheckBoxTypeContentControl.docx", SaveFormat.Docx); - //ExEnd:CheckBoxTypeContentControl + doc.Save(ArtifactsDir + "WorkingWithSdt.SdtCheckBox.docx", SaveFormat.Docx); + //ExEnd:SdtCheckBox } [Test] public void CurrentStateOfCheckBox() { - //ExStart:SetCurrentStateOfCheckBox + //ExStart:CurrentStateOfCheckBox + //GistId:089defec1b191de967e6099effeabda7 Document doc = new Document(MyDir + "Structured document tags.docx"); // Get the first content control from the document. @@ -39,13 +41,14 @@ public void CurrentStateOfCheckBox() sdtCheckBox.Checked = true; doc.Save(ArtifactsDir + "WorkingWithSdt.CurrentStateOfCheckBox.docx"); - //ExEnd:SetCurrentStateOfCheckBox + //ExEnd:CurrentStateOfCheckBox } [Test] - public void ModifyContentControls() + public void ModifySdt() { - //ExStart:ModifyContentControls + //ExStart:ModifySdt + //GistId:089defec1b191de967e6099effeabda7 Document doc = new Document(MyDir + "Structured document tags.docx"); foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true)) @@ -79,14 +82,15 @@ public void ModifyContentControls() } } - doc.Save(ArtifactsDir + "WorkingWithSdt.ModifyContentControls.docx"); - //ExEnd:ModifyContentControls + doc.Save(ArtifactsDir + "WorkingWithSdt.ModifySdt.docx"); + //ExEnd:ModifySdt } [Test] - public void ComboBoxContentControl() + public void SdtComboBox() { - //ExStart:ComboBoxContentControl + //ExStart:SdtComboBox + //GistId:089defec1b191de967e6099effeabda7 Document doc = new Document(); StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.ComboBox, MarkupLevel.Block); @@ -95,14 +99,15 @@ public void ComboBoxContentControl() sdt.ListItems.Add(new SdtListItem("Item 2", "2")); doc.FirstSection.Body.AppendChild(sdt); - doc.Save(ArtifactsDir + "WorkingWithSdt.ComboBoxContentControl.docx"); - //ExEnd:ComboBoxContentControl + doc.Save(ArtifactsDir + "WorkingWithSdt.SdtComboBox.docx"); + //ExEnd:SdtComboBox } [Test] - public void RichTextBoxContentControl() + public void SdtRichTextBox() { - //ExStart:RichTextBoxContentControl + //ExStart:SdtRichTextBox + //GistId:089defec1b191de967e6099effeabda7 Document doc = new Document(); StructuredDocumentTag sdtRichText = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block); @@ -115,40 +120,43 @@ public void RichTextBoxContentControl() sdtRichText.GetChildNodes(NodeType.Any, false).Add(para); doc.FirstSection.Body.AppendChild(sdtRichText); - doc.Save(ArtifactsDir + "WorkingWithSdt.RichTextBoxContentControl.docx"); - //ExEnd:RichTextBoxContentControl + doc.Save(ArtifactsDir + "WorkingWithSdt.SdtRichTextBox.docx"); + //ExEnd:SdtRichTextBox } [Test] - public void SetContentControlColor() + public void SdtColor() { - //ExStart:SetContentControlColor + //ExStart:SdtColor + //GistId:089defec1b191de967e6099effeabda7 Document doc = new Document(MyDir + "Structured document tags.docx"); StructuredDocumentTag sdt = (StructuredDocumentTag) doc.GetChild(NodeType.StructuredDocumentTag, 0, true); sdt.Color = Color.Red; - doc.Save(ArtifactsDir + "WorkingWithSdt.SetContentControlColor.docx"); - //ExEnd:SetContentControlColor + doc.Save(ArtifactsDir + "WorkingWithSdt.SdtColor.docx"); + //ExEnd:SdtColor } [Test] - public void ClearContentsControl() + public void ClearSdt() { - //ExStart:ClearContentsControl + //ExStart:ClearSdt + //GistId:089defec1b191de967e6099effeabda7 Document doc = new Document(MyDir + "Structured document tags.docx"); StructuredDocumentTag sdt = (StructuredDocumentTag) doc.GetChild(NodeType.StructuredDocumentTag, 0, true); sdt.Clear(); - doc.Save(ArtifactsDir + "WorkingWithSdt.ClearContentsControl.doc"); - //ExEnd:ClearContentsControl + doc.Save(ArtifactsDir + "WorkingWithSdt.ClearSdt.doc"); + //ExEnd:ClearSdt } [Test] - public void BindSdTtoCustomXmlPart() + public void BindSdtToCustomXmlPart() { - //ExStart:BindSDTtoCustomXmlPart + //ExStart:BindSdtToCustomXmlPart + //GistId:089defec1b191de967e6099effeabda7 Document doc = new Document(); CustomXmlPart xmlPart = doc.CustomXmlParts.Add(Guid.NewGuid().ToString("B"), "Hello, World!"); @@ -158,28 +166,30 @@ public void BindSdTtoCustomXmlPart() sdt.XmlMapping.SetMapping(xmlPart, "/root[1]/text[1]", ""); - doc.Save(ArtifactsDir + "WorkingWithSdt.BindSDTtoCustomXmlPart.doc"); - //ExEnd:BindSDTtoCustomXmlPart + doc.Save(ArtifactsDir + "WorkingWithSdt.BindSdtToCustomXmlPart.doc"); + //ExEnd:BindSdtToCustomXmlPart } [Test] - public void SetContentControlStyle() + public void SdtStyle() { - //ExStart:SetContentControlStyle + //ExStart:SdtStyle + //GistId:089defec1b191de967e6099effeabda7 Document doc = new Document(MyDir + "Structured document tags.docx"); StructuredDocumentTag sdt = (StructuredDocumentTag) doc.GetChild(NodeType.StructuredDocumentTag, 0, true); Style style = doc.Styles[StyleIdentifier.Quote]; sdt.Style = style; - doc.Save(ArtifactsDir + "WorkingWithSdt.SetContentControlStyle.docx"); - //ExEnd:SetContentControlStyle + doc.Save(ArtifactsDir + "WorkingWithSdt.SdtStyle.docx"); + //ExEnd:SdtStyle } [Test] - public void CreatingTableRepeatingSectionMappedToCustomXmlPart() + public void RepeatingSectionMappedToCustomXmlPart() { - //ExStart:CreatingTableRepeatingSectionMappedToCustomXmlPart + //ExStart:RepeatingSectionMappedToCustomXmlPart + //GistId:089defec1b191de967e6099effeabda7 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -221,8 +231,8 @@ public void CreatingTableRepeatingSectionMappedToCustomXmlPart() authorSdt.XmlMapping.SetMapping(xmlPart, "/books[1]/book[1]/author[1]", ""); row.AppendChild(authorSdt); - doc.Save(ArtifactsDir + "WorkingWithSdt.CreatingTableRepeatingSectionMappedToCustomXmlPart.docx"); - //ExEnd:CreatingTableRepeatingSectionMappedToCustomXmlPart + doc.Save(ArtifactsDir + "WorkingWithSdt.RepeatingSectionMappedToCustomXmlPart.docx"); + //ExEnd:RepeatingSectionMappedToCustomXmlPart } [Test] @@ -239,9 +249,10 @@ public void MultiSection() } [Test] - public void StructuredDocumentTagRangeStartXmlMapping() + public void SdtRangeStartXmlMapping() { - //ExStart:StructuredDocumentTagRangeStartXmlMapping + //ExStart:SdtRangeStartXmlMapping + //GistId:089defec1b191de967e6099effeabda7 Document doc = new Document(MyDir + "Multi-section structured document tags.docx"); // Construct an XML part that contains data and add it to the document's CustomXmlPart collection. @@ -258,8 +269,8 @@ public void StructuredDocumentTagRangeStartXmlMapping() // This XPath will point to the contents second "" element of the first "" element of our CustomXmlPart. sdtRangeStart.XmlMapping.SetMapping(xmlPart, "/root[1]/text[2]", null); - doc.Save(ArtifactsDir + "WorkingWithSdt.StructuredDocumentTagRangeStartXmlMapping.docx"); - //ExEnd:StructuredDocumentTagRangeStartXmlMapping + doc.Save(ArtifactsDir + "WorkingWithSdt.SdtRangeStartXmlMapping.docx"); + //ExEnd:SdtRangeStartXmlMapping } } } \ No newline at end of file diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with styles and themes.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with styles and themes.cs index fb23d4e38..63de9d924 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with styles and themes.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with styles and themes.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Drawing; using Aspose.Words; using NUnit.Framework; @@ -11,6 +11,7 @@ internal class WorkingWithStylesAndThemes : DocsExamplesBase public void AccessStyles() { //ExStart:AccessStyles + //GistId:a73b495f610523670f0847331ef4d6fc Document doc = new Document(); string styleName = ""; @@ -37,6 +38,7 @@ public void AccessStyles() public void CopyStyles() { //ExStart:CopyStyles + //GistId:a73b495f610523670f0847331ef4d6fc Document doc = new Document(); Document target = new Document(MyDir + "Rendering.docx"); @@ -50,6 +52,7 @@ public void CopyStyles() public void GetThemeProperties() { //ExStart:GetThemeProperties + //GistId:a73b495f610523670f0847331ef4d6fc Document doc = new Document(); Aspose.Words.Themes.Theme theme = doc.Theme; @@ -57,25 +60,27 @@ public void GetThemeProperties() Console.WriteLine(theme.MajorFonts.Latin); Console.WriteLine(theme.MinorFonts.EastAsian); Console.WriteLine(theme.Colors.Accent1); - //ExEnd:GetThemeProperties + //ExEnd:GetThemeProperties } [Test] public void SetThemeProperties() { //ExStart:SetThemeProperties + //GistId:a73b495f610523670f0847331ef4d6fc Document doc = new Document(); Aspose.Words.Themes.Theme theme = doc.Theme; theme.MinorFonts.Latin = "Times New Roman"; theme.Colors.Hyperlink = Color.Gold; - //ExEnd:SetThemeProperties + //ExEnd:SetThemeProperties } [Test] public void InsertStyleSeparator() { //ExStart:InsertStyleSeparator + //GistId:4b5526c3c0d9cad73e05fb4b18d2c3d2 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with table of content.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with table of content.cs index 193ac6508..1415f85be 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with table of content.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Contents Management/Working with table of content.cs @@ -1,5 +1,7 @@ using Aspose.Words; +using Aspose.Words.Fields; using NUnit.Framework; +using System; namespace DocsExamples.Programming_with_Documents.Contents_Management { @@ -8,17 +10,19 @@ class WorkingWithTableOfContent : DocsExamplesBase [Test] public void ChangeStyleOfTocLevel() { - //ExStart:ChangeStyleOfTOCLevel + //ExStart:ChangeStyleOfTocLevel + //GistId:db118a3e1559b9c88355356df9d7ea10 Document doc = new Document(); // Retrieve the style used for the first level of the TOC and change the formatting of the style. doc.Styles[StyleIdentifier.Toc1].Font.Bold = true; - //ExEnd:ChangeStyleOfTOCLevel + //ExEnd:ChangeStyleOfTocLevel } [Test] public void ChangeTocTabStops() { - //ExStart:ChangeTOCTabStops + //ExStart:ChangeTocTabStops + //GistId:db118a3e1559b9c88355356df9d7ea10 Document doc = new Document(MyDir + "Table of contents.docx"); foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true)) @@ -41,7 +45,36 @@ public void ChangeTocTabStops() } doc.Save(ArtifactsDir + "WorkingWithTableOfContent.ChangeTocTabStops.docx"); - //ExEnd:ChangeTOCTabStops + //ExEnd:ChangeTocTabStops + } + + [Test] + public void ExtractToc() + { + //ExStart:ExtractToc + //GistId:db118a3e1559b9c88355356df9d7ea10 + Document doc = new Document(MyDir + "Table of contents.docx"); + + foreach (Field field in doc.Range.Fields) + { + if (field.Type.Equals(FieldType.FieldHyperlink)) + { + FieldHyperlink hyperlink = (FieldHyperlink)field; + if (hyperlink.SubAddress != null && hyperlink.SubAddress.StartsWith("_Toc")) + { + Paragraph tocItem = (Paragraph)field.Start.GetAncestor(NodeType.Paragraph); + Console.WriteLine(tocItem.ToString(SaveFormat.Text).Trim()); + Console.WriteLine("------------------"); + if (tocItem != null) + { + Bookmark bm = doc.Range.Bookmarks[hyperlink.SubAddress]; + Paragraph pointer = (Paragraph)bm.BookmarkStart.GetAncestor(NodeType.Paragraph); + Console.WriteLine(pointer.ToString(SaveFormat.Text)); + } + } + } + } + //ExEnd:ExtractToc } } } \ No newline at end of file diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Protect or Encrypt Document/Document protection.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Protect or Encrypt Document/Document protection.cs index 2c04b6f00..941e7df53 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Protect or Encrypt Document/Document protection.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Protect or Encrypt Document/Document protection.cs @@ -9,6 +9,7 @@ class DocumentProtection : DocsExamplesBase public void PasswordProtection() { //ExStart:PasswordProtection + //GistId:856ba85fa704fa728b0ec20aafddd16b Document doc = new Document(); // Apply document protection. @@ -22,6 +23,7 @@ public void PasswordProtection() public void AllowOnlyFormFieldsProtect() { //ExStart:AllowOnlyFormFieldsProtect + //GistId:856ba85fa704fa728b0ec20aafddd16b // Insert two sections with some text. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -39,6 +41,7 @@ public void AllowOnlyFormFieldsProtect() public void RemoveDocumentProtection() { //ExStart:RemoveDocumentProtection + //GistId:856ba85fa704fa728b0ec20aafddd16b Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -57,6 +60,7 @@ public void RemoveDocumentProtection() public void UnrestrictedEditableRegions() { //ExStart:UnrestrictedEditableRegions + //GistId:856ba85fa704fa728b0ec20aafddd16b // Upload a document and make it as read-only. Document doc = new Document(MyDir + "Document.docx"); DocumentBuilder builder = new DocumentBuilder(doc); @@ -86,6 +90,7 @@ public void UnrestrictedEditableRegions() public void UnrestrictedSection() { //ExStart:UnrestrictedSection + //GistId:856ba85fa704fa728b0ec20aafddd16b // Insert two sections with some text. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -120,6 +125,7 @@ public void GetProtectionType() public void ReadOnlyProtection() { //ExStart:ReadOnlyProtection + //GistId:7cf6735e83804ba8942663695b22ee42 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -141,6 +147,7 @@ public void ReadOnlyProtection() public void RemoveReadOnlyRestriction() { //ExStart:RemoveReadOnlyRestriction + //GistId:7cf6735e83804ba8942663695b22ee42 Document doc = new Document(); // Enter a password that's up to 15 characters long. diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Split Documents/Split document.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Split Documents/Split document.cs index 504bba13f..a59bdb107 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Split Documents/Split document.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Split Documents/Split document.cs @@ -29,18 +29,20 @@ public void ByHeadings() public void BySectionsHtml() { Document doc = new Document(MyDir + "Rendering.docx"); - + //ExStart:SplitDocumentBySectionsHtml + //GistId:6759a1a6b7f448798751d54922a8efcb HtmlSaveOptions options = new HtmlSaveOptions { DocumentSplitCriteria = DocumentSplitCriteria.SectionBreak }; //ExEnd:SplitDocumentBySectionsHtml - - doc.Save(ArtifactsDir + "SplitDocument.BySectionsHtml.html", options); + + doc.Save(ArtifactsDir + "SplitDocument.BySections.html", options); } [Test] public void BySections() { //ExStart:SplitDocumentBySections + //GistId:6759a1a6b7f448798751d54922a8efcb Document doc = new Document(MyDir + "Big document.docx"); for (int i = 0; i < doc.Sections.Count; i++) @@ -64,6 +66,7 @@ public void BySections() public void PageByPage() { //ExStart:SplitDocumentPageByPage + //GistId:6759a1a6b7f448798751d54922a8efcb Document doc = new Document(MyDir + "Big document.docx"); int pageCount = doc.PageCount; @@ -80,6 +83,7 @@ public void PageByPage() } //ExStart:MergeSplitDocuments + //GistId:6759a1a6b7f448798751d54922a8efcb private void MergeDocuments() { // Find documents using for merge. @@ -114,6 +118,7 @@ private void MergeDocuments() public void ByPageRange() { //ExStart:SplitDocumentByPageRange + //GistId:6759a1a6b7f448798751d54922a8efcb Document doc = new Document(MyDir + "Big document.docx"); // Get part of the document. diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Comments.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Comments.cs index edaa8658e..c4ec9d5bb 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Comments.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Comments.cs @@ -11,6 +11,7 @@ internal class WorkingWithComments : DocsExamplesBase public void AddComments() { //ExStart:AddComments + //GistId:70902b20df8b1f6b0459f676e21623bb //ExStart:CreateSimpleDocumentUsingDocumentBuilder Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -31,6 +32,7 @@ public void AddComments() public void AnchorComment() { //ExStart:AnchorComment + //GistId:70902b20df8b1f6b0459f676e21623bb Document doc = new Document(); Paragraph para1 = new Paragraph(doc); @@ -66,6 +68,7 @@ public void AnchorComment() public void AddRemoveCommentReply() { //ExStart:AddRemoveCommentReply + //GistId:70902b20df8b1f6b0459f676e21623bb Document doc = new Document(MyDir + "Comments.docx"); Comment comment = (Comment) doc.GetChild(NodeType.Comment, 0, true); @@ -81,6 +84,7 @@ public void AddRemoveCommentReply() public void ProcessComments() { //ExStart:ProcessComments + //GistId:70902b20df8b1f6b0459f676e21623bb Document doc = new Document(MyDir + "Comments.docx"); // Extract the information about the comments of all the authors. @@ -107,6 +111,7 @@ public void ProcessComments() } //ExStart:ExtractComments + //GistId:70902b20df8b1f6b0459f676e21623bb List ExtractComments(Document doc) { List collectedComments = new List(); @@ -123,6 +128,7 @@ List ExtractComments(Document doc) //ExEnd:ExtractComments //ExStart:ExtractCommentsByAuthor + //GistId:70902b20df8b1f6b0459f676e21623bb List ExtractComments(Document doc, string authorName) { List collectedComments = new List(); @@ -140,15 +146,16 @@ List ExtractComments(Document doc, string authorName) //ExEnd:ExtractCommentsByAuthor //ExStart:RemoveComments + //GistId:70902b20df8b1f6b0459f676e21623bb void RemoveComments(Document doc) { NodeCollection comments = doc.GetChildNodes(NodeType.Comment, true); - comments.Clear(); } //ExEnd:RemoveComments //ExStart:RemoveCommentsByAuthor + //GistId:70902b20df8b1f6b0459f676e21623bb void RemoveComments(Document doc, string authorName) { NodeCollection comments = doc.GetChildNodes(NodeType.Comment, true); @@ -164,6 +171,7 @@ void RemoveComments(Document doc, string authorName) //ExEnd:RemoveCommentsByAuthor //ExStart:CommentResolvedAndReplies + //GistId:70902b20df8b1f6b0459f676e21623bb void CommentResolvedAndReplies(Document doc) { NodeCollection comments = doc.GetChildNodes(NodeType.Comment, true); @@ -180,5 +188,30 @@ void CommentResolvedAndReplies(Document doc) } } //ExEnd:CommentResolvedAndReplies + + [Test] + public void RemoveRangeText() + { + //ExStart:RemoveRangeText + //GistId:70902b20df8b1f6b0459f676e21623bb + Document doc = new Document(MyDir + "Comments.docx"); + + CommentRangeStart commentStart = (CommentRangeStart)doc.GetChild(NodeType.CommentRangeStart, 0, true); + Node currentNode = commentStart; + + bool isRemoving = true; + while (currentNode != null && isRemoving) + { + if (currentNode.NodeType == NodeType.CommentRangeEnd) + isRemoving = false; + + Node nextNode = currentNode.NextPreOrder(doc); + currentNode.Remove(); + currentNode = nextNode; + } + + doc.Save(ArtifactsDir + "WorkingWithComments.RemoveRangeText.docx"); + //ExEnd:RemoveRangeText + } } } diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Add content using DocumentBuilder.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Add content using DocumentBuilder.cs index 3b60cbb09..531e3f7a8 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Add content using DocumentBuilder.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Add content using DocumentBuilder.cs @@ -29,9 +29,9 @@ public void CreateNewDocument() } [Test] - public void DocumentBuilderInsertBookmark() + public void InsertBookmark() { - //ExStart:DocumentBuilderInsertBookmark + //ExStart:InsertBookmark Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -39,14 +39,14 @@ public void DocumentBuilderInsertBookmark() builder.Writeln("This is just a fine bookmark."); builder.EndBookmark("FineBookmark"); - doc.Save(ArtifactsDir + "AddContentUsingDocumentBuilder.DocumentBuilderInsertBookmark.docx"); - //ExEnd:DocumentBuilderInsertBookmark + doc.Save(ArtifactsDir + "AddContentUsingDocumentBuilder.InsertBookmark.docx"); + //ExEnd:InsertBookmark } [Test] public void BuildTable() { - //ExStart:BuildTable + //ExStart:BuildTable Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -85,6 +85,7 @@ public void BuildTable() public void InsertHorizontalRule() { //ExStart:InsertHorizontalRule + //GistId:ad463bf5f128fe6e6c1485df3c046a4c Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -99,6 +100,7 @@ public void InsertHorizontalRule() public void HorizontalRuleFormat() { //ExStart:HorizontalRuleFormat + //GistId:ad463bf5f128fe6e6c1485df3c046a4c DocumentBuilder builder = new DocumentBuilder(); Shape shape = builder.InsertHorizontalRule(); @@ -137,6 +139,7 @@ public void InsertBreak() public void InsertTextInputFormField() { //ExStart:InsertTextInputFormField + //GistId:b09907fef4643433271e4e0e912921b0 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -150,6 +153,7 @@ public void InsertTextInputFormField() public void InsertCheckBoxFormField() { //ExStart:InsertCheckBoxFormField + //GistId:b09907fef4643433271e4e0e912921b0 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -163,6 +167,7 @@ public void InsertCheckBoxFormField() public void InsertComboBoxFormField() { //ExStart:InsertComboBoxFormField + //GistId:b09907fef4643433271e4e0e912921b0 string[] items = { "One", "Two", "Three" }; Document doc = new Document(); @@ -195,6 +200,7 @@ public void InsertHtml() public void InsertHyperlink() { //ExStart:InsertHyperlink + //GistId:0213851d47551e83af42233f4d075cf6 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -214,6 +220,7 @@ public void InsertHyperlink() public void InsertTableOfContents() { //ExStart:InsertTableOfContents + //GistId:db118a3e1559b9c88355356df9d7ea10 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -252,6 +259,7 @@ public void InsertTableOfContents() builder.Writeln("Heading 3.3"); //ExStart:UpdateFields + //GistId:db118a3e1559b9c88355356df9d7ea10 // The newly inserted table of contents will be initially empty. // It needs to be populated by updating the fields in the document. doc.UpdateFields(); @@ -265,6 +273,7 @@ public void InsertTableOfContents() public void InsertInlineImage() { //ExStart:InsertInlineImage + //GistId:6f849e51240635a6322ab0460938c922 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -278,6 +287,7 @@ public void InsertInlineImage() public void InsertFloatingImage() { //ExStart:InsertFloatingImage + //GistId:6f849e51240635a6322ab0460938c922 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -298,6 +308,7 @@ public void InsertFloatingImage() public void InsertParagraph() { //ExStart:InsertParagraph + //GistId:ecf2c438314e6c8318ca9833c7f62326 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -320,22 +331,24 @@ public void InsertParagraph() } [Test] - public void InsertTCField() + public void InsertTcField() { - //ExStart:InsertTCField + //ExStart:InsertTcField + //GistId:db118a3e1559b9c88355356df9d7ea10 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.InsertField("TC \"Entry Text\" \\f t"); - doc.Save(ArtifactsDir + "AddContentUsingDocumentBuilder.InsertTCField.docx"); - //ExEnd:InsertTCField + doc.Save(ArtifactsDir + "AddContentUsingDocumentBuilder.InsertTcField.docx"); + //ExEnd:InsertTcField } [Test] - public void InsertTCFieldsAtText() + public void InsertTcFieldsAtText() { - //ExStart:InsertTCFieldsAtText + //ExStart:InsertTcFieldsAtText + //GistId:db118a3e1559b9c88355356df9d7ea10 Document doc = new Document(); FindReplaceOptions options = new FindReplaceOptions(); @@ -343,7 +356,7 @@ public void InsertTCFieldsAtText() options.ReplacingCallback = new InsertTCFieldHandler("Chapter 1", "\\l 1"); doc.Range.Replace(new Regex("The Beginning"), "", options); - //ExEnd:InsertTCFieldsAtText + //ExEnd:InsertTcFieldsAtText } //ExStart:InsertTCFieldHandler @@ -396,7 +409,9 @@ public void CursorPosition() public void MoveToNode() { //ExStart:MoveToNode + //GistId:1a2c340d1a9dde6fe70c2733084d9aab //ExStart:MoveToBookmark + //GistId:1a2c340d1a9dde6fe70c2733084d9aab Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -434,6 +449,7 @@ public void MoveToNode() public void MoveToDocumentStartEnd() { //ExStart:MoveToDocumentStartEnd + //GistId:1a2c340d1a9dde6fe70c2733084d9aab Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -444,13 +460,14 @@ public void MoveToDocumentStartEnd() // Move the cursor position to the end of your document. builder.MoveToDocumentEnd(); Console.WriteLine("\nThis is the end of the document."); - //ExEnd:MoveToDocumentStartEnd + //ExEnd:MoveToDocumentStartEnd } [Test] public void MoveToSection() { //ExStart:MoveToSection + //GistId:1a2c340d1a9dde6fe70c2733084d9aab Document doc = new Document(); doc.AppendChild(new Section(doc)); @@ -474,13 +491,14 @@ public void MoveToSection() Assert.AreEqual(2, paragraphs.IndexOf(builder.CurrentParagraph)); builder.Writeln("This is a new third paragraph. "); Assert.AreEqual(3, paragraphs.IndexOf(builder.CurrentParagraph)); - //ExEnd:MoveToSection + //ExEnd:MoveToSection } [Test] public void MoveToHeadersFooters() { //ExStart:MoveToHeadersFooters + //GistId:1a2c340d1a9dde6fe70c2733084d9aab Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -515,13 +533,14 @@ public void MoveToParagraph() builder.MoveToParagraph(2, 0); builder.Writeln("This is the 3rd paragraph."); - //ExEnd:MoveToParagraph + //ExEnd:MoveToParagraph } [Test] public void MoveToTableCell() { //ExStart:MoveToTableCell + //GistId:1a2c340d1a9dde6fe70c2733084d9aab Document doc = new Document(MyDir + "Tables.docx"); DocumentBuilder builder = new DocumentBuilder(doc); @@ -532,25 +551,27 @@ public void MoveToTableCell() Assert.AreEqual(table.Rows[2].Cells[3], builder.CurrentNode.ParentNode.ParentNode); Assert.AreEqual("Cell contents added by DocumentBuilderCell 3 contents\a", table.Rows[2].Cells[3].GetText().Trim()); - //ExEnd:MoveToTableCell + //ExEnd:MoveToTableCell } [Test] public void MoveToBookmarkEnd() { //ExStart:MoveToBookmarkEnd + //GistId:ecf2c438314e6c8318ca9833c7f62326 Document doc = new Document(MyDir + "Bookmarks.docx"); DocumentBuilder builder = new DocumentBuilder(doc); builder.MoveToBookmark("MyBookmark1", false, true); builder.Writeln("This is a bookmark."); - //ExEnd:MoveToBookmarkEnd + //ExEnd:MoveToBookmarkEnd } [Test] public void MoveToMergeField() { //ExStart:MoveToMergeField + //GistId:1a2c340d1a9dde6fe70c2733084d9aab Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -568,7 +589,7 @@ public void MoveToMergeField() // we will need to move it to a field's FieldStart or FieldSeparator node using the DocumentBuilder.MoveTo() method. Assert.AreEqual(field.End, builder.CurrentNode.PreviousSibling); builder.Write(" Text immediately after the field."); - //ExEnd:MoveToMergeField - } + //ExEnd:MoveToMergeField + } } } \ No newline at end of file diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Clone and combine documents.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Clone and combine documents.cs index af5fd317e..05770d0c3 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Clone and combine documents.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Clone and combine documents.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -12,14 +12,36 @@ namespace DocsExamples.Programming_with_Documents.Working_with_Document internal class CloneAndCombineDocuments : DocsExamplesBase { [Test] - public void CloningDocument() + public void CloneDocument() { - //ExStart:CloningDocument - Document doc = new Document(MyDir + "Document.docx"); + //ExStart:CloneDocument + //GistId:b2f62f736a2090163de7b0f221cf46d4 + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + builder.Writeln("This is the original document before applying the clone method"); + // Clone the document. Document clone = doc.Clone(); + + // Edit the cloned document. + builder = new DocumentBuilder(clone); + builder.Write("Section 1"); + builder.InsertBreak(BreakType.SectionBreakNewPage); + builder.Write("Section 2"); + + // This shows what is in the document originally. The document has two sections. + Assert.AreEqual("Section 1\fSection 2This is the original document before applying the clone method", clone.GetText().Trim()); + + // Duplicate the last section and append the copy to the end of the document. + int lastSectionIdx = clone.Sections.Count - 1; + Section newSection = clone.Sections[lastSectionIdx].Clone(); + clone.Sections.Add(newSection); + + // Check what the document contains after we changed it. + Assert.AreEqual("Section 1\fSection 2This is the original document before applying the clone method" + + "\r\fSection 2This is the original document before applying the clone method", clone.GetText().Trim()); clone.Save(ArtifactsDir + "CloneAndCombineDocuments.CloningDocument.docx"); - //ExEnd:CloningDocument + //ExEnd:CloneDocument } [Test] diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Compare documents.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Compare documents.cs index 7c3f5b83b..0a50caeaa 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Compare documents.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Compare documents.cs @@ -11,6 +11,7 @@ internal class CompareDocument : DocsExamplesBase public void CompareForEqual() { //ExStart:CompareForEqual + //GistId:66cba61d079d8ef1e676820633ba4586 Document docA = new Document(MyDir + "Document.docx"); Document docB = docA.Clone(); @@ -18,13 +19,14 @@ public void CompareForEqual() docA.Compare(docB, "user", DateTime.Now); Console.WriteLine(docA.Revisions.Count == 0 ? "Documents are equal" : "Documents are not equal"); - //ExEnd:CompareForEqual + //ExEnd:CompareForEqual } [Test] public void CompareOptions() { //ExStart:CompareOptions + //GistId:66cba61d079d8ef1e676820633ba4586 Document docA = new Document(MyDir + "Document.docx"); Document docB = docA.Clone(); @@ -43,7 +45,7 @@ public void CompareOptions() docA.Compare(docB, "user", DateTime.Now, options); Console.WriteLine(docA.Revisions.Count == 0 ? "Documents are equal" : "Documents are not equal"); - //ExEnd:CompareOptions + //ExEnd:CompareOptions } [Test] @@ -73,7 +75,7 @@ public void ComparisonGranularity() CompareOptions compareOptions = new CompareOptions { Granularity = Granularity.CharLevel }; builderA.Document.Compare(builderB.Document, "author", DateTime.Now, compareOptions); - //ExEnd:ComparisonGranularity + //ExEnd:ComparisonGranularity } } } \ No newline at end of file diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Document formatting.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Document formatting.cs index a14b058ed..546f2be41 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Document formatting.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Document formatting.cs @@ -1,5 +1,7 @@ using System; using Aspose.Words; +using Aspose.Words.Layout; +using Aspose.Words.Tables; using NUnit.Framework; namespace DocsExamples.Programming_with_Documents.Working_with_Document @@ -10,6 +12,7 @@ internal class DocumentFormatting : DocsExamplesBase public void SpaceBetweenAsianAndLatinText() { //ExStart:SpaceBetweenAsianAndLatinText + //GistId:4f54ffd5c7580f0d146b53e52d986f38 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -28,6 +31,7 @@ public void SpaceBetweenAsianAndLatinText() public void AsianTypographyLineBreakGroup() { //ExStart:AsianTypographyLineBreakGroup + //GistId:4f54ffd5c7580f0d146b53e52d986f38 Document doc = new Document(MyDir + "Asian typography.docx"); ParagraphFormat format = doc.FirstSection.Body.Paragraphs[0].ParagraphFormat; @@ -43,6 +47,7 @@ public void AsianTypographyLineBreakGroup() public void ParagraphFormatting() { //ExStart:ParagraphFormatting + //GistId:4b5526c3c0d9cad73e05fb4b18d2c3d2 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -65,6 +70,7 @@ public void ParagraphFormatting() public void MultilevelListFormatting() { //ExStart:MultilevelListFormatting + //GistId:a1dfeba1e0480d5b277a61742c8921af Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -96,6 +102,7 @@ public void MultilevelListFormatting() public void ApplyParagraphStyle() { //ExStart:ApplyParagraphStyle + //GistId:4b5526c3c0d9cad73e05fb4b18d2c3d2 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -110,6 +117,7 @@ public void ApplyParagraphStyle() public void ApplyBordersAndShadingToParagraph() { //ExStart:ApplyBordersAndShadingToParagraph + //GistId:4b5526c3c0d9cad73e05fb4b18d2c3d2 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -172,6 +180,7 @@ public void SnapToGrid() public void GetParagraphStyleSeparator() { //ExStart:GetParagraphStyleSeparator + //GistId:4b5526c3c0d9cad73e05fb4b18d2c3d2 Document doc = new Document(MyDir + "Document.docx"); foreach (Paragraph paragraph in doc.GetChildNodes(NodeType.Paragraph, true)) @@ -183,5 +192,84 @@ public void GetParagraphStyleSeparator() } //ExEnd:GetParagraphStyleSeparator } + + [Test] + //ExStart:GetParagraphLines + //GistId:4b5526c3c0d9cad73e05fb4b18d2c3d2 + public void GetParagraphLines() + { + Document doc = new Document(MyDir + "Properties.docx"); + + LayoutCollector collector = new LayoutCollector(doc); + LayoutEnumerator enumerator = new LayoutEnumerator(doc); + foreach (Paragraph paragraph in doc.GetChildNodes(NodeType.Paragraph, true)) + { + ProcessParagraph(paragraph, collector, enumerator); + } + } + + private static void ProcessParagraph(Paragraph paragraph, LayoutCollector collector, LayoutEnumerator enumerator) + { + object paragraphBreak = collector.GetEntity(paragraph); + if (paragraphBreak == null) + return; + + object stopEntity = GetStopEntity(paragraph, collector, enumerator); + + enumerator.Current = paragraphBreak; + enumerator.MoveParent(); + + int lineCount = CountLines(enumerator, stopEntity); + + string paragraphText = GetTruncatedText(paragraph.GetText()); + Console.WriteLine($"Paragraph '{paragraphText}' has {lineCount} line(-s)."); + } + + private static object GetStopEntity(Paragraph paragraph, LayoutCollector collector, LayoutEnumerator enumerator) + { + Node previousNode = paragraph.PreviousSibling; + if (previousNode == null) + return null; + + if (previousNode is Paragraph prevParagraph) + { + enumerator.Current = collector.GetEntity(prevParagraph); // Para break. + enumerator.MoveParent(); // Last line. + return enumerator.Current; + } + else if (previousNode is Table table) + { + enumerator.Current = collector.GetEntity(table.LastRow.LastCell.LastParagraph); // Cell break. + enumerator.MoveParent(); // Cell. + enumerator.MoveParent(); // Row. + return enumerator.Current; + } + else + { + throw new InvalidOperationException("Unsupported node type encountered."); + } + } + /// + /// We move from line to line in a paragraph. + /// When paragraph spans multiple pages the we will follow across them. + /// + private static int CountLines(LayoutEnumerator enumerator, object stopEntity) + { + int count = 1; + while (enumerator.Current != stopEntity) + { + if (!enumerator.MovePreviousLogical()) + break; + count++; + } + return count; + } + + private static string GetTruncatedText(string text) + { + int MaxChars = 16; + return text.Length > MaxChars ? $"{text.Substring(0, MaxChars)}..." : text; + } + //ExEnd:GetParagraphLines } } \ No newline at end of file diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Working with WebExtension.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Working with WebExtension.cs index 909f8797a..0afa29cb6 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Working with WebExtension.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Working with WebExtension.cs @@ -1,4 +1,4 @@ -using System; +using System; using Aspose.Words; using Aspose.Words.WebExtensions; using NUnit.Framework; @@ -8,9 +8,10 @@ namespace DocsExamples.Programming_with_Documents.Working_with_Document internal class WorkingWithWebExtension : DocsExamplesBase { [Test] - public void UsingWebExtensionTaskPanes() + public void WebExtensionTaskPanes() { - //ExStart:UsingWebExtensionTaskPanes + //ExStart:WebExtensionTaskPanes + //GistId:8c31c018ea71c92828223776b1a113f7 Document doc = new Document(); TaskPane taskPane = new TaskPane(); @@ -28,11 +29,12 @@ public void UsingWebExtensionTaskPanes() taskPane.WebExtension.Bindings.Add(new WebExtensionBinding("UnnamedBinding_0_1506535429545", WebExtensionBindingType.Text, "194740422")); - doc.Save(ArtifactsDir + "WorkingWithWebExtension.UsingWebExtensionTaskPanes.docx"); - //ExEnd:UsingWebExtensionTaskPanes - + doc.Save(ArtifactsDir + "WorkingWithWebExtension.WebExtensionTaskPanes.docx"); + //ExEnd:WebExtensionTaskPanes + //ExStart:GetListOfAddins - doc = new Document(ArtifactsDir + "WorkingWithWebExtension.UsingWebExtensionTaskPanes.docx"); + //GistId:8c31c018ea71c92828223776b1a113f7 + doc = new Document(ArtifactsDir + "WorkingWithWebExtension.WebExtensionTaskPanes.docx"); Console.WriteLine("Task panes sources:\n"); diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Working with document options and settings.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Working with document options and settings.cs index 52466e902..dc30fb394 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Working with document options and settings.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Working with document options and settings.cs @@ -10,15 +10,16 @@ namespace DocsExamples.Programming_with_Documents.Working_with_Document internal class WorkingWithDocumentOptionsAndSettings : DocsExamplesBase { [Test] - public void OptimizeForMsWord() + public void OptimizeFor() { - //ExStart:OptimizeForMsWord + //ExStart:OptimizeFor + //GistId:5d2997d42c1f1fad79b18873f170855f Document doc = new Document(MyDir + "Document.docx"); doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2016); - doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.OptimizeForMsWord.docx"); - //ExEnd:OptimizeForMsWord + doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.OptimizeFor.docx"); + //ExEnd:OptimizeFor } [Test] @@ -37,7 +38,8 @@ public void ShowGrammaticalAndSpellingErrors() [Test] public void CleanupUnusedStylesAndLists() { - //ExStart:CleanupUnusedStylesandLists + //ExStart:CleanupUnusedStylesAndLists + //GistId:669f3d08f45b14f75f9d2cb17fa1056a Document doc = new Document(MyDir + "Unused styles.docx"); // Combined with the built-in styles, the document now has eight styles. @@ -54,13 +56,14 @@ public void CleanupUnusedStylesAndLists() $"Count of lists after Cleanup is the same: {doc.Lists.Count}"); doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.CleanupUnusedStylesAndLists.docx"); - //ExEnd:CleanupUnusedStylesandLists + //ExEnd:CleanupUnusedStylesAndLists } [Test] public void CleanupDuplicateStyle() { //ExStart:CleanupDuplicateStyle + //GistId:669f3d08f45b14f75f9d2cb17fa1056a Document doc = new Document(MyDir + "Document.docx"); // Count of styles before Cleanup. @@ -81,6 +84,7 @@ public void CleanupDuplicateStyle() public void ViewOptions() { //ExStart:SetViewOption + //GistId:5d2997d42c1f1fad79b18873f170855f Document doc = new Document(MyDir + "Document.docx"); doc.ViewOptions.ViewType = ViewType.PageLayout; @@ -94,6 +98,7 @@ public void ViewOptions() public void DocumentPageSetup() { //ExStart:DocumentPageSetup + //GistId:5d2997d42c1f1fad79b18873f170855f Document doc = new Document(MyDir + "Document.docx"); // Set the layout mode for a section allowing to define the document grid behavior. @@ -130,6 +135,7 @@ public void AddEditingLanguage() public void SetRussianAsDefaultEditingLanguage() { //ExStart:SetRussianAsDefaultEditingLanguage + //GistId:5d2997d42c1f1fad79b18873f170855f LoadOptions loadOptions = new LoadOptions(); loadOptions.LanguagePreferences.DefaultEditingLanguage = EditingLanguage.Russian; diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Working with document properties.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Working with document properties.cs index a74c1e113..da02fcbab 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Working with document properties.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Document/Working with document properties.cs @@ -12,6 +12,7 @@ internal class DocumentPropertiesAndVariables : DocsExamplesBase public void GetVariables() { //ExStart:GetVariables + //GistId:0593a8803015363f3026f648332e7026 Document doc = new Document(MyDir + "Document.docx"); string variables = ""; @@ -20,23 +21,20 @@ public void GetVariables() string name = entry.Key; string value = entry.Value; if (variables == "") - { variables = "Name: " + name + "," + "Value: {1}" + value; - } else - { variables = variables + "Name: " + name + "," + "Value: {1}" + value; - } } - //ExEnd:GetVariables Console.WriteLine("\nDocument have following variables " + variables); + //ExEnd:GetVariables } [Test] public void EnumerateProperties() { - //ExStart:EnumerateProperties + //ExStart:EnumerateProperties + //GistId:0593a8803015363f3026f648332e7026 Document doc = new Document(MyDir + "Properties.docx"); Console.WriteLine("1. Document name: {0}", doc.OriginalFileName); @@ -53,9 +51,10 @@ public void EnumerateProperties() } [Test] - public void AddCustomDocumentProperties() + public void AddCustomProperties() { - //ExStart:AddCustomDocumentProperties + //ExStart:AddCustomProperties + //GistId:0593a8803015363f3026f648332e7026 Document doc = new Document(MyDir + "Properties.docx"); CustomDocumentProperties customDocumentProperties = doc.CustomDocumentProperties; @@ -67,22 +66,24 @@ public void AddCustomDocumentProperties() customDocumentProperties.Add("Authorized Date", DateTime.Today); customDocumentProperties.Add("Authorized Revision", doc.BuiltInDocumentProperties.RevisionNumber); customDocumentProperties.Add("Authorized Amount", 123.45); - //ExEnd:AddCustomDocumentProperties + //ExEnd:AddCustomProperties } [Test] - public void RemoveCustomDocumentProperties() + public void RemoveCustomProperties() { - //ExStart:CustomRemove + //ExStart:RemoveCustomProperties + //GistId:0593a8803015363f3026f648332e7026 Document doc = new Document(MyDir + "Properties.docx"); doc.CustomDocumentProperties.Remove("Authorized Date"); - //ExEnd:CustomRemove + //ExEnd:RemoveCustomProperties } [Test] public void RemovePersonalInformation() { - //ExStart:RemovePersonalInformation + //ExStart:RemovePersonalInformation + //GistId:0593a8803015363f3026f648332e7026 Document doc = new Document(MyDir + "Properties.docx") { RemovePersonalInformation = true }; doc.Save(ArtifactsDir + "DocumentPropertiesAndVariables.RemovePersonalInformation.docx"); @@ -92,7 +93,8 @@ public void RemovePersonalInformation() [Test] public void ConfiguringLinkToContent() { - //ExStart:ConfiguringLinkToContent + //ExStart:ConfiguringLinkToContent + //GistId:0593a8803015363f3026f648332e7026 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -107,9 +109,7 @@ public void ConfiguringLinkToContent() customProperty = customProperties["Bookmark"]; bool isLinkedToContent = customProperty.IsLinkToContent; - string linkSource = customProperty.LinkSource; - string customPropertyValue = customProperty.Value.ToString(); //ExEnd:ConfiguringLinkToContent } @@ -118,6 +118,7 @@ public void ConfiguringLinkToContent() public void ConvertBetweenMeasurementUnits() { //ExStart:ConvertBetweenMeasurementUnits + //GistId:f266e937d2c656f9441071e9a7b053c1 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -135,6 +136,7 @@ public void ConvertBetweenMeasurementUnits() public void UseControlCharacters() { //ExStart:UseControlCharacters + //GistId:6269ddb6427f9ad20623d975774a615e const string text = "test\r"; // Replace "\r" control character with "\r\n". string replace = text.Replace(ControlChar.Cr, ControlChar.CrLf); diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Fields.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Fields.cs index ad7bb30b7..ea2d9ab5f 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Fields.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Fields.cs @@ -1,7 +1,7 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Runtime.InteropServices.ComTypes; using System.Threading; using Aspose.Words; using Aspose.Words.Fields; @@ -14,6 +14,8 @@ internal class WorkingWithFields : DocsExamplesBase [Test] public void FieldCode() { + //ExStart:FieldCode + //GistId:7c2b7b650a88375b1d438746f78f0d64 Document doc = new Document(MyDir + "Hyperlinks.docx"); foreach (Field field in doc.Range.Fields) @@ -21,12 +23,14 @@ public void FieldCode() string fieldCode = field.GetFieldCode(); string fieldResult = field.Result; } + //ExEnd:FieldCode } [Test] public void ChangeFieldUpdateCultureSource() { //ExStart:ChangeFieldUpdateCultureSource + //GistId:9e90defe4a7bcafb004f73a2ef236986 //ExStart:DocumentBuilderInsertField Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -50,20 +54,22 @@ public void ChangeFieldUpdateCultureSource() [Test] public void SpecifyLocaleAtFieldLevel() { - //ExStart:SpecifylocaleAtFieldlevel + //ExStart:SpecifyLocaleAtFieldLevel + //GistId:1cf07762df56f15067d6aef90b14b3db DocumentBuilder builder = new DocumentBuilder(); Field field = builder.InsertField(FieldType.FieldDate, true); field.LocaleId = 1049; - builder.Document.Save(ArtifactsDir + "WorkingWithFields.SpecifylocaleAtFieldlevel.docx"); - //ExEnd:SpecifylocaleAtFieldlevel + builder.Document.Save(ArtifactsDir + "WorkingWithFields.SpecifyLocaleAtFieldLevel.docx"); + //ExEnd:SpecifyLocaleAtFieldLevel } [Test] public void ReplaceHyperlinks() { //ExStart:ReplaceHyperlinks + //GistId:0213851d47551e83af42233f4d075cf6 Document doc = new Document(MyDir + "Hyperlinks.docx"); foreach (Field field in doc.Range.Fields) @@ -89,6 +95,7 @@ public void ReplaceHyperlinks() public void RenameMergeFields() { //ExStart:RenameMergeFields + //GistId:bf0f8a6b40b69a5274ab3553315e147f Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -113,6 +120,7 @@ public void RenameMergeFields() public void RemoveField() { //ExStart:RemoveField + //GistId:8c604665c1b97795df7a1e665f6b44ce Document doc = new Document(MyDir + "Various fields.docx"); Field field = doc.Range.Fields[0]; @@ -124,15 +132,17 @@ public void RemoveField() public void UnlinkFields() { //ExStart:UnlinkFields + //GistId:f3592014d179ecb43905e37b2a68bc92 Document doc = new Document(MyDir + "Various fields.docx"); doc.UnlinkFields(); //ExEnd:UnlinkFields } [Test] - public void InsertTOAFieldWithoutDocumentBuilder() + public void InsertToaFieldWithoutDocumentBuilder() { - //ExStart:InsertTOAFieldWithoutDocumentBuilder + //ExStart:InsertToaFieldWithoutDocumentBuilder + //GistId:1cf07762df56f15067d6aef90b14b3db Document doc = new Document(); Paragraph para = new Paragraph(doc); @@ -154,14 +164,15 @@ public void InsertTOAFieldWithoutDocumentBuilder() fieldToa.Update(); - doc.Save(ArtifactsDir + "WorkingWithFields.InsertTOAFieldWithoutDocumentBuilder.docx"); - //ExEnd:InsertTOAFieldWithoutDocumentBuilder + doc.Save(ArtifactsDir + "WorkingWithFields.InsertToaFieldWithoutDocumentBuilder.docx"); + //ExEnd:InsertToaFieldWithoutDocumentBuilder } [Test] public void InsertNestedFields() { //ExStart:InsertNestedFields + //GistId:1cf07762df56f15067d6aef90b14b3db Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -186,9 +197,10 @@ public void InsertNestedFields() } [Test] - public void InsertMergeFieldUsingDOM() + public void InsertMergeFieldUsingDom() { - //ExStart:InsertMergeFieldUsingDOM + //ExStart:InsertMergeFieldUsingDom + //GistId:1cf07762df56f15067d6aef90b14b3db Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -211,14 +223,15 @@ public void InsertMergeFieldUsingDOM() field.Update(); - doc.Save(ArtifactsDir + "WorkingWithFields.InsertMergeFieldUsingDOM.docx"); - //ExEnd:InsertMergeFieldUsingDOM + doc.Save(ArtifactsDir + "WorkingWithFields.InsertMergeFieldUsingDom.docx"); + //ExEnd:InsertMergeFieldUsingDom } [Test] - public void InsertMailMergeAddressBlockFieldUsingDOM() + public void InsertAddressBlockFieldUsingDom() { - //ExStart:InsertMailMergeAddressBlockFieldUsingDOM + //ExStart:InsertAddressBlockFieldUsingDom + //GistId:1cf07762df56f15067d6aef90b14b3db Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -241,14 +254,15 @@ public void InsertMailMergeAddressBlockFieldUsingDOM() field.Update(); - doc.Save(ArtifactsDir + "WorkingWithFields.InsertMailMergeAddressBlockFieldUsingDOM.docx"); - //ExEnd:InsertMailMergeAddressBlockFieldUsingDOM + doc.Save(ArtifactsDir + "WorkingWithFields.InsertAddressBlockFieldUsingDom.docx"); + //ExEnd:InsertAddressBlockFieldUsingDom } [Test] public void InsertFieldIncludeTextWithoutDocumentBuilder() { //ExStart:InsertFieldIncludeTextWithoutDocumentBuilder + //GistId:1cf07762df56f15067d6aef90b14b3db Document doc = new Document(); Paragraph para = new Paragraph(doc); @@ -271,6 +285,7 @@ public void InsertFieldIncludeTextWithoutDocumentBuilder() public void InsertFieldNone() { //ExStart:InsertFieldNone + //GistId:1cf07762df56f15067d6aef90b14b3db Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -284,6 +299,7 @@ public void InsertFieldNone() public void InsertField() { //ExStart:InsertField + //GistId:1cf07762df56f15067d6aef90b14b3db Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -296,6 +312,8 @@ public void InsertField() [Test] public void InsertFieldUsingFieldBuilder() { + //ExStart:InsertFieldUsingFieldBuilder + //GistId:1cf07762df56f15067d6aef90b14b3db Document doc = new Document(); // Prepare IF field with two nested MERGEFIELD fields: { IF "left expression" = "right expression" "Firstname: { MERGEFIELD firstname }" "Lastname: { MERGEFIELD lastname }"} @@ -312,17 +330,19 @@ public void InsertFieldUsingFieldBuilder() .AddText("Lastname: ") .AddField(new FieldBuilder(FieldType.FieldMergeField).AddArgument("lastname"))); - // Insert IF field in exact location + // Insert IF field in exact location Field field = fieldBuilder.BuildAndInsert(doc.FirstSection.Body.FirstParagraph); field.Update(); doc.Save(ArtifactsDir + "Field.InsertFieldUsingFieldBuilder.docx"); + //ExEnd:InsertFieldUsingFieldBuilder } [Test] public void InsertAuthorField() { //ExStart:InsertAuthorField + //GistId:1cf07762df56f15067d6aef90b14b3db Document doc = new Document(); Paragraph para = (Paragraph) doc.GetChild(NodeType.Paragraph, 0, true); @@ -339,9 +359,10 @@ public void InsertAuthorField() } [Test] - public void InsertASKFieldWithOutDocumentBuilder() + public void InsertAskFieldWithoutDocumentBuilder() { - //ExStart:InsertASKFieldWithOutDocumentBuilder + //ExStart:InsertAskFieldWithoutDocumentBuilder + //GistId:1cf07762df56f15067d6aef90b14b3db Document doc = new Document(); Paragraph para = (Paragraph) doc.GetChild(NodeType.Paragraph, 0, true); @@ -359,14 +380,15 @@ public void InsertASKFieldWithOutDocumentBuilder() field.Update(); - doc.Save(ArtifactsDir + "WorkingWithFields.InsertASKFieldWithOutDocumentBuilder.docx"); - //ExEnd:InsertASKFieldWithOutDocumentBuilder + doc.Save(ArtifactsDir + "WorkingWithFields.InsertAskFieldWithoutDocumentBuilder.docx"); + //ExEnd:InsertAskFieldWithoutDocumentBuilder } [Test] - public void InsertAdvanceFieldWithOutDocumentBuilder() + public void InsertAdvanceFieldWithoutDocumentBuilder() { - //ExStart:InsertAdvanceFieldWithOutDocumentBuilder + //ExStart:InsertAdvanceFieldWithoutDocumentBuilder + //GistId:1cf07762df56f15067d6aef90b14b3db Document doc = new Document(); Paragraph para = (Paragraph) doc.GetChild(NodeType.Paragraph, 0, true); @@ -388,8 +410,8 @@ public void InsertAdvanceFieldWithOutDocumentBuilder() field.Update(); - doc.Save(ArtifactsDir + "WorkingWithFields.InsertAdvanceFieldWithOutDocumentBuilder.docx"); - //ExEnd:InsertAdvanceFieldWithOutDocumentBuilder + doc.Save(ArtifactsDir + "WorkingWithFields.InsertAdvanceFieldWithoutDocumentBuilder.docx"); + //ExEnd:InsertAdvanceFieldWithoutDocumentBuilder } [Test] @@ -429,7 +451,8 @@ public void DeleteFields() [Test] public void FieldUpdateCulture() { - //ExStart:FieldUpdateCultureProvider + //ExStart:FieldUpdateCulture + //GistId:79b46682fbfd7f02f64783b163ed95fc Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -439,10 +462,11 @@ public void FieldUpdateCulture() doc.FieldOptions.FieldUpdateCultureProvider = new FieldUpdateCultureProvider(); doc.Save(ArtifactsDir + "WorkingWithFields.FieldUpdateCulture.pdf"); - //ExEnd:FieldUpdateCultureProvider + //ExEnd:FieldUpdateCulture } - //ExStart:FieldUpdateCultureProviderGetCulture + //ExStart:FieldUpdateCultureProvider + //GistId:79b46682fbfd7f02f64783b163ed95fc class FieldUpdateCultureProvider : IFieldUpdateCultureProvider { public CultureInfo GetCulture(string name, Field field) @@ -492,13 +516,15 @@ public CultureInfo GetCulture(string name, Field field) } } } - //ExEnd:FieldUpdateCultureProviderGetCulture + //ExEnd:FieldUpdateCultureProvider [Test] public void FieldDisplayResults() { //ExStart:FieldDisplayResults + //GistId:bf0f8a6b40b69a5274ab3553315e147f //ExStart:UpdateDocFields + //GistId:08db64c4d86842c4afd1ecb925ed07c4 Document document = new Document(MyDir + "Various fields.docx"); document.UpdateFields(); @@ -510,22 +536,24 @@ public void FieldDisplayResults() } [Test] - public void EvaluateIFCondition() + public void EvaluateIfCondition() { - //ExStart:EvaluateIFCondition + //ExStart:EvaluateIfCondition + //GistId:79b46682fbfd7f02f64783b163ed95fc DocumentBuilder builder = new DocumentBuilder(); FieldIf field = (FieldIf) builder.InsertField("IF 1 = 1", null); FieldIfComparisonResult actualResult = field.EvaluateCondition(); Console.WriteLine(actualResult); - //ExEnd:EvaluateIFCondition + //ExEnd:EvaluateIfCondition } [Test] - public void ConvertFieldsInParagraph() + public void UnlinkFieldsInParagraph() { - //ExStart:ConvertFieldsInParagraph + //ExStart:UnlinkFieldsInParagraph + //GistId:f3592014d179ecb43905e37b2a68bc92 Document doc = new Document(MyDir + "Linked fields.docx"); // Pass the appropriate parameters to convert all IF fields to text that are encountered only in the last @@ -533,41 +561,44 @@ public void ConvertFieldsInParagraph() doc.FirstSection.Body.LastParagraph.Range.Fields.Where(f => f.Type == FieldType.FieldIf).ToList() .ForEach(f => f.Unlink()); - doc.Save(ArtifactsDir + "WorkingWithFields.TestFile.docx"); - //ExEnd:ConvertFieldsInParagraph + doc.Save(ArtifactsDir + "WorkingWithFields.UnlinkFieldsInParagraph.docx"); + //ExEnd:UnlinkFieldsInParagraph } [Test] - public void ConvertFieldsInDocument() + public void UnlinkFieldsInDocument() { - //ExStart:ConvertFieldsInDocument + //ExStart:UnlinkFieldsInDocument + //GistId:f3592014d179ecb43905e37b2a68bc92 Document doc = new Document(MyDir + "Linked fields.docx"); // Pass the appropriate parameters to convert all IF fields encountered in the document (including headers and footers) to text. doc.Range.Fields.Where(f => f.Type == FieldType.FieldIf).ToList().ForEach(f => f.Unlink()); // Save the document with fields transformed to disk - doc.Save(ArtifactsDir + "WorkingWithFields.ConvertFieldsInDocument.docx"); - //ExEnd:ConvertFieldsInDocument + doc.Save(ArtifactsDir + "WorkingWithFields.UnlinkFieldsInDocument.docx"); + //ExEnd:UnlinkFieldsInDocument } [Test] - public void ConvertFieldsInBody() + public void UnlinkFieldsInBody() { - //ExStart:ConvertFieldsInBody + //ExStart:UnlinkFieldsInBody + //GistId:f3592014d179ecb43905e37b2a68bc92 Document doc = new Document(MyDir + "Linked fields.docx"); // Pass the appropriate parameters to convert PAGE fields encountered to text only in the body of the first section. doc.FirstSection.Body.Range.Fields.Where(f => f.Type == FieldType.FieldPage).ToList().ForEach(f => f.Unlink()); - doc.Save(ArtifactsDir + "WorkingWithFields.ConvertFieldsInBody.docx"); - //ExEnd:ConvertFieldsInBody + doc.Save(ArtifactsDir + "WorkingWithFields.UnlinkFieldsInBody.docx"); + //ExEnd:UnlinkFieldsInBody } [Test] public void ChangeLocale() { //ExStart:ChangeLocale + //GistId:9e90defe4a7bcafb004f73a2ef236986 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -584,6 +615,153 @@ public void ChangeLocale() doc.Save(ArtifactsDir + "WorkingWithFields.ChangeLocale.docx"); //ExEnd:ChangeLocale + } + + //ExStart:ConvertFieldsToStaticText + //GistId:f3592014d179ecb43905e37b2a68bc92 + /// + /// Converts any fields of the specified type found in the descendants of the node into static text. + /// + /// The node in which all descendants of the specified FieldType will be converted to static text. + /// The FieldType of the field to convert to static text. + private void ConvertFieldsToStaticText(CompositeNode compositeNode, FieldType targetFieldType) + { + compositeNode.Range.Fields.Cast().Where(f => f.Type == targetFieldType).ToList().ForEach(f => f.Unlink()); } + //ExEnd:ConvertFieldsToStaticText + + [Test] + public void FieldResultFormatting() + { + //ExStart:FieldResultFormatting + //GistId:79b46682fbfd7f02f64783b163ed95fc + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + FieldResultFormatter formatter = new FieldResultFormatter("${0}", "Date: {0}", "Item # {0}:"); + doc.FieldOptions.ResultFormatter = formatter; + + // Our field result formatter applies a custom format to newly created fields of three types of formats. + // Field result formatters apply new formatting to fields as they are updated, + // which happens as soon as we create them using this InsertField method overload. + // 1 - Numeric: + builder.InsertField(" = 2 + 3 \\# $###"); + + Assert.AreEqual("$5", doc.Range.Fields[0].Result); + Assert.AreEqual(1, formatter.CountFormatInvocations(FieldResultFormatter.FormatInvocationType.Numeric)); + + // 2 - Date/time: + builder.InsertField("DATE \\@ \"d MMMM yyyy\""); + + Assert.IsTrue(doc.Range.Fields[1].Result.StartsWith("Date: ")); + Assert.AreEqual(1, formatter.CountFormatInvocations(FieldResultFormatter.FormatInvocationType.DateTime)); + + // 3 - General: + builder.InsertField("QUOTE \"2\" \\* Ordinal"); + + Assert.AreEqual("Item # 2:", doc.Range.Fields[2].Result); + Assert.AreEqual(1, formatter.CountFormatInvocations(FieldResultFormatter.FormatInvocationType.General)); + + formatter.PrintFormatInvocations(); + //ExEnd:FieldResultFormatting + } + + //ExStart:FieldResultFormatter + //GistId:79b46682fbfd7f02f64783b163ed95fc + /// + /// When fields with formatting are updated, this formatter will override their formatting + /// with a custom format, while tracking every invocation. + /// + private class FieldResultFormatter : IFieldResultFormatter + { + public FieldResultFormatter(string numberFormat, string dateFormat, string generalFormat) + { + mNumberFormat = numberFormat; + mDateFormat = dateFormat; + mGeneralFormat = generalFormat; + } + + public string FormatNumeric(double value, string format) + { + if (string.IsNullOrEmpty(mNumberFormat)) + return null; + + string newValue = String.Format(mNumberFormat, value); + FormatInvocations.Add(new FormatInvocation(FormatInvocationType.Numeric, value, format, newValue)); + return newValue; + } + + public string FormatDateTime(DateTime value, string format, CalendarType calendarType) + { + if (string.IsNullOrEmpty(mDateFormat)) + return null; + + string newValue = String.Format(mDateFormat, value); + FormatInvocations.Add(new FormatInvocation(FormatInvocationType.DateTime, $"{value} ({calendarType})", format, newValue)); + return newValue; + } + + public string Format(string value, GeneralFormat format) + { + return Format((object)value, format); + } + + public string Format(double value, GeneralFormat format) + { + return Format((object)value, format); + } + + private string Format(object value, GeneralFormat format) + { + if (string.IsNullOrEmpty(mGeneralFormat)) + return null; + + string newValue = String.Format(mGeneralFormat, value); + FormatInvocations.Add(new FormatInvocation(FormatInvocationType.General, value, format.ToString(), newValue)); + return newValue; + } + + public int CountFormatInvocations(FormatInvocationType formatInvocationType) + { + if (formatInvocationType == FormatInvocationType.All) + return FormatInvocations.Count; + return FormatInvocations.Count(f => f.FormatInvocationType == formatInvocationType); + } + + public void PrintFormatInvocations() + { + foreach (FormatInvocation f in FormatInvocations) + Console.WriteLine($"Invocation type:\t{f.FormatInvocationType}\n" + + $"\tOriginal value:\t\t{f.Value}\n" + + $"\tOriginal format:\t{f.OriginalFormat}\n" + + $"\tNew value:\t\t\t{f.NewValue}\n"); + } + + private readonly string mNumberFormat; + private readonly string mDateFormat; + private readonly string mGeneralFormat; + private List FormatInvocations { get; } = new List(); + + private class FormatInvocation + { + public FormatInvocationType FormatInvocationType { get; } + public object Value { get; } + public string OriginalFormat { get; } + public string NewValue { get; } + + public FormatInvocation(FormatInvocationType formatInvocationType, object value, string originalFormat, string newValue) + { + Value = value; + FormatInvocationType = formatInvocationType; + OriginalFormat = originalFormat; + NewValue = newValue; + } + } + + public enum FormatInvocationType + { + Numeric, DateTime, General, All + } + } + //ExEnd:FieldResultFormatter } } \ No newline at end of file diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Fonts.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Fonts.cs index 4fc5b056e..f28112bd9 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Fonts.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Fonts.cs @@ -37,6 +37,7 @@ public void FontFormatting() public void GetFontLineSpacing() { //ExStart:GetFontLineSpacing + //GistId:7cb86f131b74afcbebc153f0039e3947 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -69,7 +70,8 @@ public void CheckDMLTextEffect() [Test] public void SetFontFormatting() { - //ExStart:DocumentBuilderSetFontFormatting + //ExStart:SetFontFormatting + //GistId:7cb86f131b74afcbebc153f0039e3947 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -85,13 +87,14 @@ public void SetFontFormatting() builder.Writeln("I'm a very nice formatted string."); doc.Save(ArtifactsDir + "WorkingWithFonts.SetFontFormatting.docx"); - //ExEnd:DocumentBuilderSetFontFormatting + //ExEnd:SetFontFormatting } [Test] public void SetFontEmphasisMark() { //ExStart:SetFontEmphasisMark + //GistId:7cb86f131b74afcbebc153f0039e3947 Document document = new Document(); DocumentBuilder builder = new DocumentBuilder(document); diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Footnote and Endnote.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Footnote and Endnote.cs index 2dc4641d6..46e25458d 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Footnote and Endnote.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Footnote and Endnote.cs @@ -7,35 +7,38 @@ namespace DocsExamples.Programming_with_Documents internal class WorkingWithFootnotes : DocsExamplesBase { [Test] - public void SetFootNoteColumns() + public void SetFootnoteColumns() { - //ExStart:SetFootNoteColumns + //ExStart:SetFootnoteColumns + //GistId:3b39c2019380ee905e7d9596494916a4 Document doc = new Document(MyDir + "Document.docx"); // Specify the number of columns with which the footnotes area is formatted. doc.FootnoteOptions.Columns = 3; - doc.Save(ArtifactsDir + "WorkingWithFootnotes.SetFootNoteColumns.docx"); - //ExEnd:SetFootNoteColumns + doc.Save(ArtifactsDir + "WorkingWithFootnotes.SetFootnoteColumns.docx"); + //ExEnd:SetFootnoteColumns } [Test] - public void SetFootnoteAndEndNotePosition() + public void SetFootnoteAndEndnotePosition() { - //ExStart:SetFootnoteAndEndNotePosition + //ExStart:SetFootnoteAndEndnotePosition + //GistId:3b39c2019380ee905e7d9596494916a4 Document doc = new Document(MyDir + "Document.docx"); doc.FootnoteOptions.Position = FootnotePosition.BeneathText; doc.EndnoteOptions.Position = EndnotePosition.EndOfSection; - doc.Save(ArtifactsDir + "WorkingWithFootnotes.SetFootnoteAndEndNotePosition.docx"); - //ExEnd:SetFootnoteAndEndNotePosition + doc.Save(ArtifactsDir + "WorkingWithFootnotes.SetFootnoteAndEndnotePosition.docx"); + //ExEnd:SetFootnoteAndEndnotePosition } [Test] public void SetEndnoteOptions() { //ExStart:SetEndnoteOptions + //GistId:3b39c2019380ee905e7d9596494916a4 Document doc = new Document(MyDir + "Document.docx"); DocumentBuilder builder = new DocumentBuilder(doc); diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with FormFields.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with FormFields.cs index 3a188f894..3e0608689 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with FormFields.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with FormFields.cs @@ -11,6 +11,7 @@ internal class WorkingWithFormFields : DocsExamplesBase public void InsertFormFields() { //ExStart:InsertFormFields + //GistId:b09907fef4643433271e4e0e912921b0 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -23,18 +24,20 @@ public void InsertFormFields() public void FormFieldsWorkWithProperties() { //ExStart:FormFieldsWorkWithProperties + //GistId:b09907fef4643433271e4e0e912921b0 Document doc = new Document(MyDir + "Form fields.docx"); FormField formField = doc.Range.FormFields[3]; if (formField.Type == FieldType.FieldFormTextInput) formField.Result = "My name is " + formField.Name; - //ExEnd:FormFieldsWorkWithProperties + //ExEnd:FormFieldsWorkWithProperties } [Test] public void FormFieldsGetFormFieldsCollection() { //ExStart:FormFieldsGetFormFieldsCollection + //GistId:b09907fef4643433271e4e0e912921b0 Document doc = new Document(MyDir + "Form fields.docx"); FormFieldCollection formFields = doc.Range.FormFields; @@ -45,7 +48,9 @@ public void FormFieldsGetFormFieldsCollection() public void FormFieldsGetByName() { //ExStart:FormFieldsFontFormatting + //GistId:b09907fef4643433271e4e0e912921b0 //ExStart:FormFieldsGetByName + //GistId:b09907fef4643433271e4e0e912921b0 Document doc = new Document(MyDir + "Form fields.docx"); FormFieldCollection documentFormFields = doc.Range.FormFields; diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Charts.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Charts.cs index 2f1bdb476..e3cbe3103 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Charts.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Charts.cs @@ -1,4 +1,5 @@ using System; +using System.Drawing; using Aspose.Words; using Aspose.Words.Drawing; using Aspose.Words.Drawing.Charts; @@ -12,6 +13,7 @@ internal class WorkingWithCharts : DocsExamplesBase public void FormatNumberOfDataLabel() { //ExStart:FormatNumberOfDataLabel + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -45,6 +47,7 @@ public void FormatNumberOfDataLabel() public void CreateChartUsingShape() { //ExStart:CreateChartUsingShape + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -68,6 +71,7 @@ public void CreateChartUsingShape() public void InsertSimpleColumnChart() { //ExStart:InsertSimpleColumnChart + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -75,11 +79,12 @@ public void InsertSimpleColumnChart() Shape shape = builder.InsertChart(ChartType.Column, 432, 252); Chart chart = shape.Chart; - //ExStart:ChartSeriesCollection + //ExStart:ChartSeriesCollection + //GistId:23d39c0b874655d7e7354f1ecc122e39 ChartSeriesCollection seriesColl = chart.Series; Console.WriteLine(seriesColl.Count); - //ExEnd:ChartSeriesCollection + //ExEnd:ChartSeriesCollection // Delete default generated series. seriesColl.Clear(); @@ -102,6 +107,7 @@ public void InsertSimpleColumnChart() public void InsertColumnChart() { //ExStart:InsertColumnChart + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -118,6 +124,7 @@ public void InsertColumnChart() public void InsertAreaChart() { //ExStart:InsertAreaChart + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -142,6 +149,7 @@ public void InsertAreaChart() public void InsertBubbleChart() { //ExStart:InsertBubbleChart + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -159,6 +167,7 @@ public void InsertBubbleChart() public void InsertScatterChart() { //ExStart:InsertScatterChart + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -172,9 +181,10 @@ public void InsertScatterChart() } [Test] - public void DefineXYAxisProperties() + public void DefineAxisProperties() { - //ExStart:DefineXYAxisProperties + //ExStart:DefineAxisProperties + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -212,14 +222,15 @@ public void DefineXYAxisProperties() yAxis.Scaling.Minimum = new AxisBound(100); yAxis.Scaling.Maximum = new AxisBound(700); - doc.Save(ArtifactsDir + "WorkingWithCharts.DefineXYAxisProperties.docx"); - //ExEnd:DefineXYAxisProperties + doc.Save(ArtifactsDir + "WorkingWithCharts.DefineAxisProperties.docx"); + //ExEnd:DefineAxisProperties } [Test] public void DateTimeValuesToAxis() { - //ExStart:SetDateTimeValuesToAxis + //ExStart:DateTimeValuesToAxis + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -247,13 +258,14 @@ public void DateTimeValuesToAxis() xAxis.MinorTickMark = AxisTickMark.Outside; doc.Save(ArtifactsDir + "WorkingWithCharts.DateTimeValuesToAxis.docx"); - //ExEnd:SetDateTimeValuesToAxis + //ExEnd:DateTimeValuesToAxis } [Test] public void NumberFormatForAxis() { - //ExStart:SetNumberFormatForAxis + //ExStart:NumberFormatForAxis + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -270,13 +282,14 @@ public void NumberFormatForAxis() chart.AxisY.NumberFormat.FormatCode = "#,##0"; doc.Save(ArtifactsDir + "WorkingWithCharts.NumberFormatForAxis.docx"); - //ExEnd:SetNumberFormatForAxis + //ExEnd:NumberFormatForAxis } [Test] public void BoundsOfAxis() { - //ExStart:SetboundsOfAxis + //ExStart:BoundsOfAxis + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -294,13 +307,14 @@ public void BoundsOfAxis() chart.AxisY.Scaling.Maximum = new AxisBound(6); doc.Save(ArtifactsDir + "WorkingWithCharts.BoundsOfAxis.docx"); - //ExEnd:SetboundsOfAxis + //ExEnd:BoundsOfAxis } [Test] public void IntervalUnitBetweenLabelsOnAxis() { - //ExStart:SetIntervalUnitBetweenLabelsOnAxis + //ExStart:IntervalUnitBetweenLabelsOnAxis + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -317,13 +331,14 @@ public void IntervalUnitBetweenLabelsOnAxis() chart.AxisX.TickLabels.Spacing = 2; doc.Save(ArtifactsDir + "WorkingWithCharts.IntervalUnitBetweenLabelsOnAxis.docx"); - //ExEnd:SetIntervalUnitBetweenLabelsOnAxis + //ExEnd:IntervalUnitBetweenLabelsOnAxis } [Test] public void HideChartAxis() { //ExStart:HideChartAxis + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -347,6 +362,7 @@ public void HideChartAxis() public void TickMultiLineLabelAlignment() { //ExStart:TickMultiLineLabelAlignment + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -364,6 +380,7 @@ public void TickMultiLineLabelAlignment() public void ChartDataLabel() { //ExStart:WorkWithChartDataLabel + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -393,6 +410,7 @@ public void ChartDataLabel() public void DefaultOptionsForDataLabels() { //ExStart:DefaultOptionsForDataLabels + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -420,6 +438,7 @@ public void DefaultOptionsForDataLabels() public void SingleChartDataPoint() { //ExStart:WorkWithSingleChartDataPoint + //GistId:23d39c0b874655d7e7354f1ecc122e39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -460,6 +479,7 @@ public void SingleChartSeries() Chart chart = shape.Chart; //ExStart:WorkWithSingleChartSeries + //GistId:23d39c0b874655d7e7354f1ecc122e39 ChartSeries series0 = chart.Series[0]; ChartSeries series1 = chart.Series[1]; @@ -471,7 +491,8 @@ public void SingleChartSeries() series1.Smooth = true; //ExEnd:WorkWithSingleChartSeries - //ExStart:ChartDataPoint + //ExStart:ChartDataPoint + //GistId:23d39c0b874655d7e7354f1ecc122e39 // Specifies whether by default the parent element shall inverts its colors if the value is negative. series0.InvertIfNegative = true; @@ -480,9 +501,74 @@ public void SingleChartSeries() series1.Marker.Symbol = MarkerSymbol.Star; series1.Marker.Size = 10; - //ExEnd:ChartDataPoint + //ExEnd:ChartDataPoint doc.Save(ArtifactsDir + "WorkingWithCharts.SingleChartSeries.docx"); } + + [Test] + public void FillFormatting() + { + //ExStart:FillFormatting + //GistId:23d39c0b874655d7e7354f1ecc122e39 + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + + Shape shape = builder.InsertChart(ChartType.Column, 432, 252); + + Chart chart = shape.Chart; + ChartSeriesCollection seriesColl = chart.Series; + + // Delete default generated series. + seriesColl.Clear(); + + // Create category names array. + string[] categories = new string[] { "AW Category 1", "AW Category 2" }; + + // Adding new series. Value and category arrays must be the same size. + ChartSeries series1 = seriesColl.Add("AW Series 1", categories, new double[] { 1, 2 }); + ChartSeries series2 = seriesColl.Add("AW Series 2", categories, new double[] { 3, 4 }); + ChartSeries series3 = seriesColl.Add("AW Series 3", categories, new double[] { 5, 6 }); + + // Set series color. + series1.Format.Fill.ForeColor = Color.Red; + series2.Format.Fill.ForeColor = Color.Yellow; + series3.Format.Fill.ForeColor = Color.Blue; + + doc.Save(ArtifactsDir + "WorkingWithCharts.FillFormatting.docx"); + //ExEnd:FillFormatting + } + + [Test] + public void StrokeFormatting() + { + //ExStart:StrokeFormatting + //GistId:23d39c0b874655d7e7354f1ecc122e39 + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + + Shape shape = builder.InsertChart(ChartType.Line, 432, 252); + + Chart chart = shape.Chart; + ChartSeriesCollection seriesColl = chart.Series; + + // Delete default generated series. + seriesColl.Clear(); + + // Adding new series. + ChartSeries series1 = seriesColl.Add("AW Series 1", new double[] { 0.7, 1.8, 2.6 }, + new double[] { 2.7, 3.2, 0.8 }); + ChartSeries series2 = seriesColl.Add("AW Series 2", new double[] { 0.5, 1.5, 2.5 }, + new double[] { 3, 1, 2 }); + + // Set series color. + series1.Format.Stroke.ForeColor = Color.Red; + series1.Format.Stroke.Weight = 5; + series2.Format.Stroke.ForeColor = Color.LightGreen; + series2.Format.Stroke.Weight = 5; + + doc.Save(ArtifactsDir + "WorkingWithCharts.StrokeFormatting.docx"); + //ExEnd:StrokeFormatting + } } } diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Images.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Images.cs index a97344cee..4fc392ffb 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Images.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Images.cs @@ -9,11 +9,12 @@ using Aspose.Words; using Aspose.Words.Drawing; using Aspose.Words.Layout; +using Aspose.Words.Saving; using NUnit.Framework; namespace DocsExamples.Programming_with_Documents.Working_with_Graphic_Elements { - internal class WorkingWithImages : DocsExamplesBase + public class WorkingWithImages : DocsExamplesBase { [Test] public void AddImageToEachPage() @@ -86,6 +87,7 @@ public void AddImageToPage(Paragraph para, int page, string imagesDir) public void InsertBarcodeImage() { //ExStart:InsertBarcodeImage + //GistId:6f849e51240635a6322ab0460938c922 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -107,11 +109,12 @@ public void InsertBarcodeImage() // Save the document as a PDF to disk // You can also save this directly to a stream - doc.Save(ArtifactsDir + "InsertBarcodeImage.docx"); + doc.Save(ArtifactsDir + "WorkingWithImages.InsertBarcodeImage.docx"); //ExEnd:InsertBarcodeImage } //ExStart:InsertBarcodeIntoFooter + //GistId:6f849e51240635a6322ab0460938c922 private void InsertBarcodeIntoFooter(DocumentBuilder builder, Section section, HeaderFooterType footerType) { @@ -160,16 +163,55 @@ public void CompressImages() if (count != 1) Console.WriteLine("We expected to have only 1 image resampled in this test document!"); - doc.Save(ArtifactsDir + "CompressImages.docx"); + doc.Save(ArtifactsDir + "WorkingWithImages.CompressImages.docx"); // Verify that the first image was compressed by checking the new PPI. - doc = new Document(ArtifactsDir + "CompressImages.docx"); + doc = new Document(ArtifactsDir + "WorkingWithImages.CompressImages.docx"); Shape shape = (Shape) doc.GetChild(NodeType.Shape, 0, true); double imagePpi = shape.ImageData.ImageSize.WidthPixels / ConvertUtil.PointToInch(shape.SizeInPoints.Width); Debug.Assert(imagePpi < 150, "Image was not resampled successfully."); } + + [Test] + public void CropImages() + { + //ExStart:CropImages + //GistId:6f849e51240635a6322ab0460938c922 + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + + Image img = Image.FromFile(ImagesDir + "Logo.jpg"); + + int effectiveWidth = img.Width - 570; + int effectiveHeight = img.Height - 571; + + Shape croppedImage = builder.InsertImage(img, + ConvertUtil.PixelToPoint(img.Width - effectiveWidth), + ConvertUtil.PixelToPoint(img.Height - effectiveHeight)); + + double widthRatio = croppedImage.Width / ConvertUtil.PixelToPoint(img.Width); + double heightRatio = croppedImage.Height / ConvertUtil.PixelToPoint(img.Height); + + if (widthRatio < 1) + croppedImage.ImageData.CropRight = 1 - widthRatio; + + if (heightRatio < 1) + croppedImage.ImageData.CropBottom = 1 - heightRatio; + + float leftToWidth = (float)124 / img.Width; + float topToHeight = (float)90 / img.Height; + + croppedImage.ImageData.CropLeft = leftToWidth; + croppedImage.ImageData.CropRight = croppedImage.ImageData.CropRight - leftToWidth; + + croppedImage.ImageData.CropTop = topToHeight; + croppedImage.ImageData.CropBottom = croppedImage.ImageData.CropBottom - topToHeight; + + croppedImage.GetShapeRenderer().Save(ArtifactsDir + "WorkingWithImages.CropImages.jpg", new ImageSaveOptions(SaveFormat.Jpeg)); + //ExEnd:CropImages + } } public class Resampler diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with OfficeMath.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with OfficeMath.cs index 5360491ad..6c90484f1 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with OfficeMath.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with OfficeMath.cs @@ -10,6 +10,7 @@ internal class WorkingWithOfficeMath : DocsExamplesBase public void MathEquations() { //ExStart:MathEquations + //GistId:e19d5874b376b07466fd7a397d554648 Document doc = new Document(MyDir + "Office math.docx"); OfficeMath officeMath = (OfficeMath) doc.GetChild(NodeType.OfficeMath, 0, true); diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Shapes.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Shapes.cs index d772beed5..8b39526a4 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Shapes.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Shapes.cs @@ -15,6 +15,7 @@ internal class WorkingWithShapes : DocsExamplesBase public void AddGroupShape() { //ExStart:AddGroupShape + //GistId:072edc4bbb0dd0eebf1f61f610bd8d36 Document doc = new Document(); doc.EnsureMinimum(); @@ -43,6 +44,7 @@ public void AddGroupShape() public void InsertShape() { //ExStart:InsertShape + //GistId:ad463bf5f128fe6e6c1485df3c046a4c Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -68,6 +70,7 @@ public void InsertShape() public void AspectRatioLocked() { //ExStart:AspectRatioLocked + //GistId:ad463bf5f128fe6e6c1485df3c046a4c Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -82,6 +85,7 @@ public void AspectRatioLocked() public void LayoutInCell() { //ExStart:LayoutInCell + //GistId:ad463bf5f128fe6e6c1485df3c046a4c Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -133,6 +137,7 @@ public void LayoutInCell() public void AddCornersSnipped() { //ExStart:AddCornersSnipped + //GistId:ad463bf5f128fe6e6c1485df3c046a4c Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -151,6 +156,7 @@ public void AddCornersSnipped() public void GetActualShapeBoundsPoints() { //ExStart:GetActualShapeBoundsPoints + //GistId:ad463bf5f128fe6e6c1485df3c046a4c Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -166,6 +172,7 @@ public void GetActualShapeBoundsPoints() public void VerticalAnchor() { //ExStart:VerticalAnchor + //GistId:ad463bf5f128fe6e6c1485df3c046a4c Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -183,6 +190,7 @@ public void VerticalAnchor() public void DetectSmartArtShape() { //ExStart:DetectSmartArtShape + //GistId:ad463bf5f128fe6e6c1485df3c046a4c Document doc = new Document(MyDir + "SmartArt.docx"); int count = doc.GetChildNodes(NodeType.Shape, true).Cast().Count(shape => shape.HasSmartArt); @@ -197,6 +205,7 @@ public void UpdateSmartArtDrawing() Document doc = new Document(MyDir + "SmartArt.docx"); //ExStart:UpdateSmartArtDrawing + //GistId:683cdbe52b97598d9d4ee4695b4f83c9 foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true)) if (shape.HasSmartArt) shape.UpdateSmartArtDrawing(); diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Watermark.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Watermark.cs index 7f7eac5ca..0ddfb6a4b 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Watermark.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Graphic Elements/Working with Watermark.cs @@ -8,9 +8,10 @@ namespace DocsExamples.Programming_with_Documents.Working_with_Graphic_Elements internal class WorkWithWatermark : DocsExamplesBase { [Test] - public void AddTextWatermarkWithSpecificOptions() + public void AddTextWatermark() { - //ExStart:AddTextWatermarkWithSpecificOptions + //ExStart:AddTextWatermark + //GistId:1f690a31c188a851d80d7aed4ff7e44c Document doc = new Document(MyDir + "Document.docx"); TextWatermarkOptions options = new TextWatermarkOptions() @@ -24,15 +25,16 @@ public void AddTextWatermarkWithSpecificOptions() doc.Watermark.SetText("Test", options); - doc.Save(ArtifactsDir + "WorkWithWatermark.AddTextWatermarkWithSpecificOptions.docx"); - //ExEnd:AddTextWatermarkWithSpecificOptions + doc.Save(ArtifactsDir + "WorkWithWatermark.AddTextWatermark.docx"); + //ExEnd:AddTextWatermark } #if NET48 [Test] - public void AddImageWatermarkWithSpecificOptions() + public void AddImageWatermark() { - //ExStart:AddImageWatermarkWithSpecificOptions + //ExStart:AddImageWatermark + //GistId:1f690a31c188a851d80d7aed4ff7e44c Document doc = new Document(MyDir + "Document.docx"); ImageWatermarkOptions options = new ImageWatermarkOptions @@ -44,13 +46,14 @@ public void AddImageWatermarkWithSpecificOptions() doc.Watermark.SetImage(Image.FromFile(ImagesDir + "Transparent background logo.png"), options); doc.Save(ArtifactsDir + "WorkWithWatermark.AddImageWatermark.docx"); - //ExEnd:AddImageWatermarkWithSpecificOptions + //ExEnd:AddImageWatermark } [Test] - public void RemoveWatermarkFromDocument() + public void RemoveDocumentWatermark() { - //ExStart:RemoveWatermarkFromDocument + //ExStart:RemoveDocumentWatermark + //GistId:1f690a31c188a851d80d7aed4ff7e44c Document doc = new Document(); // Add a plain text watermark. @@ -73,12 +76,13 @@ public void RemoveWatermarkFromDocument() if (doc.Watermark.Type == WatermarkType.Text) doc.Watermark.Remove(); - doc.Save(ArtifactsDir + "WorkWithWatermark.RemoveWatermarkFromDocument.docx"); - //ExEnd:RemoveWatermarkFromDocument + doc.Save(ArtifactsDir + "WorkWithWatermark.RemoveDocumentWatermark.docx"); + //ExEnd:RemoveDocumentWatermark } #endif - //ExStart:AddWatermark + //ExStart:AddDocumentWatermark + //GistId:1f690a31c188a851d80d7aed4ff7e44c [Test] public void AddAndRemoveWatermark() { @@ -87,7 +91,7 @@ public void AddAndRemoveWatermark() InsertWatermarkText(doc, "CONFIDENTIAL"); doc.Save(ArtifactsDir + "WorkWithWatermark.AddWatermark.docx"); - RemoveWatermarkText(doc); + RemoveWatermarkShape(doc); doc.Save(ArtifactsDir + "WorkWithWatermark.RemoveWatermark.docx"); } @@ -98,8 +102,11 @@ public void AddAndRemoveWatermark() /// Text of the watermark. private void InsertWatermarkText(Document doc, string watermarkText) { + //ExStart:SetShapeName + //GistId:1f690a31c188a851d80d7aed4ff7e44c // Create a watermark shape, this will be a WordArt shape. Shape watermark = new Shape(doc, ShapeType.TextPlainText) { Name = "Watermark" }; + //ExEnd:SetShapeName watermark.TextPath.Text = watermarkText; watermark.TextPath.FontFamily = "Arial"; @@ -150,22 +157,23 @@ private void InsertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, // Insert a clone of the watermark into the header. header.AppendChild(watermarkPara.Clone(true)); } - //ExEnd:AddWatermark - - //ExStart:RemoveWatermark - private void RemoveWatermarkText(Document doc) + //ExEnd:AddDocumentWatermark + + //ExStart:RemoveWatermarkShape + //GistId:1f690a31c188a851d80d7aed4ff7e44c + private void RemoveWatermarkShape(Document doc) { foreach (HeaderFooter hf in doc.GetChildNodes(NodeType.HeaderFooter, true)) { foreach (Shape shape in hf.GetChildNodes(NodeType.Shape, true)) { - if (shape.Name.Contains("WaterMark")) + if (shape.Name.Contains("Watermark")) { shape.Remove(); } } } } - //ExEnd:RemoveWatermark + //ExEnd:RemoveWatermarkShape } } diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Hyphenation.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Hyphenation.cs index 6ce0ed93d..acdb438cf 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Hyphenation.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Hyphenation.cs @@ -8,33 +8,36 @@ namespace DocsExamples.Programming_with_Documents internal class WorkingWithHyphenation : DocsExamplesBase { [Test] - public void HyphenateWordsOfLanguages() + public void HyphenateWords() { - //ExStart:HyphenateWordsOfLanguages + //ExStart:HyphenateWords + //GistId:a52aacf87a36f7881ba29d25de92fb83 Document doc = new Document(MyDir + "German text.docx"); Hyphenation.RegisterDictionary("en-US", MyDir + "hyph_en_US.dic"); Hyphenation.RegisterDictionary("de-CH", MyDir + "hyph_de_CH.dic"); - doc.Save(ArtifactsDir + "WorkingWithHyphenation.HyphenateWordsOfLanguages.pdf"); - //ExEnd:HyphenateWordsOfLanguages + doc.Save(ArtifactsDir + "WorkingWithHyphenation.HyphenateWords.pdf"); + //ExEnd:HyphenateWords } [Test] - public void LoadHyphenationDictionaryForLanguage() + public void LoadHyphenationDictionary() { - //ExStart:LoadHyphenationDictionaryForLanguage + //ExStart:LoadHyphenationDictionary + //GistId:a52aacf87a36f7881ba29d25de92fb83 Document doc = new Document(MyDir + "German text.docx"); Stream stream = File.OpenRead(MyDir + "hyph_de_CH.dic"); Hyphenation.RegisterDictionary("de-CH", stream); - doc.Save(ArtifactsDir + "WorkingWithHyphenation.LoadHyphenationDictionaryForLanguage.pdf"); - //ExEnd:LoadHyphenationDictionaryForLanguage + doc.Save(ArtifactsDir + "WorkingWithHyphenation.LoadHyphenationDictionary.pdf"); + //ExEnd:LoadHyphenationDictionary } - [Test] + [Test] //ExStart:CustomHyphenation + //GistId:a52aacf87a36f7881ba29d25de92fb83 public void HyphenationCallback() { try 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 9fafafeec..f8fee950b 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with List.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with List.cs @@ -13,6 +13,7 @@ internal class WorkingWithList : DocsExamplesBase public void RestartListAtEachSection() { //ExStart:RestartListAtEachSection + //GistId:a1dfeba1e0480d5b277a61742c8921af Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Markdown.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Markdown.cs index 8d923f62f..96279cda8 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Markdown.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Markdown.cs @@ -11,6 +11,7 @@ internal class WorkingWithMarkdown : DocsExamplesBase public void BoldText() { //ExStart:BoldText + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. DocumentBuilder builder = new DocumentBuilder(); @@ -24,6 +25,7 @@ public void BoldText() public void ItalicText() { //ExStart:ItalicText + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. DocumentBuilder builder = new DocumentBuilder(); @@ -37,6 +39,7 @@ public void ItalicText() public void Strikethrough() { //ExStart:Strikethrough + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. DocumentBuilder builder = new DocumentBuilder(); @@ -70,6 +73,7 @@ public void InlineCode() public void Autolink() { //ExStart:Autolink + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. DocumentBuilder builder = new DocumentBuilder(); @@ -83,6 +87,7 @@ public void Autolink() public void Link() { //ExStart:Link + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. DocumentBuilder builder = new DocumentBuilder(); @@ -95,6 +100,7 @@ public void Link() public void Image() { //ExStart:Image + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. DocumentBuilder builder = new DocumentBuilder(); @@ -108,6 +114,7 @@ public void Image() public void HorizontalRule() { //ExStart:HorizontalRule + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. DocumentBuilder builder = new DocumentBuilder(); @@ -120,16 +127,36 @@ public void HorizontalRule() public void Heading() { //ExStart:Heading + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. - DocumentBuilder builder = new DocumentBuilder(); + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); // By default Heading styles in Word may have Bold and Italic formatting. //If we do not want to be emphasized, set these properties explicitly to false. builder.Font.Bold = false; builder.Font.Italic = false; - builder.ParagraphFormat.StyleName = "Heading 1"; - builder.Writeln("This is an H1 tag"); + builder.Writeln("The following produces headings:"); + builder.ParagraphFormat.Style = doc.Styles["Heading 1"]; + builder.Writeln("Heading1"); + builder.ParagraphFormat.Style = doc.Styles["Heading 2"]; + builder.Writeln("Heading2"); + builder.ParagraphFormat.Style = doc.Styles["Heading 3"]; + builder.Writeln("Heading3"); + builder.ParagraphFormat.Style = doc.Styles["Heading 4"]; + builder.Writeln("Heading4"); + builder.ParagraphFormat.Style = doc.Styles["Heading 5"]; + builder.Writeln("Heading5"); + builder.ParagraphFormat.Style = doc.Styles["Heading 6"]; + builder.Writeln("Heading6"); + + // Note, emphases are also allowed inside Headings: + builder.Font.Bold = true; + builder.ParagraphFormat.Style = doc.Styles["Heading 1"]; + builder.Writeln("Bold Heading1"); + + doc.Save(ArtifactsDir + "WorkingWithMarkdown.Heading.md"); //ExEnd:Heading } @@ -137,6 +164,7 @@ public void Heading() public void SetextHeading() { //ExStart:SetextHeading + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. DocumentBuilder builder = new DocumentBuilder(); @@ -167,13 +195,14 @@ public void SetextHeading() builder.Writeln("Setext Heading level 2"); //ExEnd:SetextHeading - builder.Document.Save(ArtifactsDir + "Test.md"); + builder.Document.Save(ArtifactsDir + "WorkingWithMarkdown.SetextHeading.md"); } [Test] public void IndentedCode() { //ExStart:IndentedCode + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. DocumentBuilder builder = new DocumentBuilder(); @@ -187,6 +216,7 @@ public void IndentedCode() public void FencedCode() { //ExStart:FencedCode + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. DocumentBuilder builder = new DocumentBuilder(); @@ -204,8 +234,10 @@ public void FencedCode() public void Quote() { //ExStart:Quote + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. - DocumentBuilder builder = new DocumentBuilder(); + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); // By default a document stores blockquote style for the first level. builder.ParagraphFormat.StyleName = "Quote"; @@ -216,6 +248,8 @@ public void Quote() builder.ParagraphFormat.Style = quoteLevel2; builder.Document.Styles["Quote1"].BaseStyleName = "Quote"; builder.Writeln("1. Nested blockquote"); + + doc.Save(ArtifactsDir + "WorkingWithMarkdown.Quote.md"); //ExEnd:Quote } @@ -223,6 +257,7 @@ public void Quote() public void BulletedList() { //ExStart:BulletedList + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. DocumentBuilder builder = new DocumentBuilder(); @@ -243,6 +278,7 @@ public void BulletedList() public void OrderedList() { //ExStart:OrderedList + //GistId:0697355b7f872839932388d269ed6a63 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -262,6 +298,7 @@ public void OrderedList() public void Table() { //ExStart:Table + //GistId:0697355b7f872839932388d269ed6a63 // Use a document builder to add content to the document. DocumentBuilder builder = new DocumentBuilder(); @@ -285,6 +322,7 @@ public void Table() public void ReadMarkdownDocument() { //ExStart:ReadMarkdownDocument + //GistId:19de942ef8827201c1dca99f76c59133 Document doc = new Document(MyDir + "Quotes.md"); // Let's remove Heading formatting from a Quote in the very last paragraph. @@ -299,6 +337,7 @@ public void ReadMarkdownDocument() public void Emphases() { //ExStart:Emphases + //GistId:19de942ef8827201c1dca99f76c59133 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Node.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Node.cs index f0bb7553a..556418345 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Node.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Node.cs @@ -8,51 +8,47 @@ namespace DocsExamples.Programming_with_Documents internal class WorkingWithNode : DocsExamplesBase { [Test] - public void UseNodeType() + public void GetNodeType() { - //ExStart:UseNodeType + //ExStart:GetNodeType + //GistId:3e9d92093b2f5995f984791bfc10c944 Document doc = new Document(); - NodeType type = doc.NodeType; - //ExEnd:UseNodeType + //ExEnd:GetNodeType } [Test] public void GetParentNode() { - //ExStart:GetParentNode + //ExStart:GetParentNode + //GistId:3e9d92093b2f5995f984791bfc10c944 Document doc = new Document(); - // The section is the first child node of the document. Node section = doc.FirstChild; - // The section's parent node is the document. Console.WriteLine("Section parent is the document: " + (doc == section.ParentNode)); - //ExEnd:GetParentNode + //ExEnd:GetParentNode } [Test] public void OwnerDocument() { //ExStart:OwnerDocument + //GistId:3e9d92093b2f5995f984791bfc10c944 Document doc = new Document(); // Creating a new node of any type requires a document passed into the constructor. Paragraph para = new Paragraph(doc); - // The new paragraph node does not yet have a parent. Console.WriteLine("Paragraph has no parent node: " + (para.ParentNode == null)); - // But the paragraph node knows its document. Console.WriteLine("Both nodes' documents are the same: " + (para.Document == doc)); - // The fact that a node always belongs to a document allows us to access and modify // properties that reference the document-wide data, such as styles or lists. para.ParagraphFormat.StyleName = "Heading 1"; - // Now add the paragraph to the main text of the first section. doc.FirstSection.Body.AppendChild(para); - + // The paragraph node is now a child of the Body node. Console.WriteLine("Paragraph has a parent node: " + (para.ParentNode != null)); //ExEnd:OwnerDocument @@ -61,7 +57,8 @@ public void OwnerDocument() [Test] public void EnumerateChildNodes() { - //ExStart:EnumerateChildNodes + //ExStart:EnumerateChildNodes + //GistId:3e9d92093b2f5995f984791bfc10c944 Document doc = new Document(); Paragraph paragraph = (Paragraph) doc.GetChild(NodeType.Paragraph, 0, true); @@ -80,10 +77,10 @@ public void EnumerateChildNodes() [Test] //ExStart:RecurseAllNodes + //GistId:3e9d92093b2f5995f984791bfc10c944 public void RecurseAllNodes() { Document doc = new Document(MyDir + "Paragraphs.docx"); - // Invoke the recursive function that will walk the tree. TraverseAllNodes(doc); } @@ -110,19 +107,17 @@ public void TraverseAllNodes(CompositeNode parentNode) public void TypedAccess() { //ExStart:TypedAccess + //GistId:3e9d92093b2f5995f984791bfc10c944 Document doc = new Document(); Section section = doc.FirstSection; Body body = section.Body; - // Quick typed access to all Table child nodes contained in the Body. TableCollection tables = body.Tables; - foreach (Table table in tables) { // Quick typed access to the first row of the table. table.FirstRow?.Remove(); - // Quick typed access to the last row of the table. table.LastRow?.Remove(); } diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with OleObjects and ActiveX.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with OleObjects and ActiveX.cs index 7546f5a22..7cf51ee2d 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with OleObjects and ActiveX.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with OleObjects and ActiveX.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Runtime.InteropServices.ComTypes; using Aspose.Words; using Aspose.Words.Drawing; using Aspose.Words.Drawing.Ole; @@ -12,20 +13,22 @@ class WorkingWithOleObjectsAndActiveX : DocsExamplesBase [Test] public void InsertOleObject() { - //ExStart:DocumentBuilderInsertOleObject + //ExStart:InsertOleObject + //GistId:4996b573cf231d9f66ab0d1f3f981222 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.InsertOleObject("http://www.aspose.com", "htmlfile", true, true, null); doc.Save(ArtifactsDir + "WorkingWithOleObjectsAndActiveX.InsertOleObject.docx"); - //ExEnd:DocumentBuilderInsertOleObject + //ExEnd:InsertOleObject } [Test] public void InsertOleObjectWithOlePackage() { //ExStart:InsertOleObjectwithOlePackage + //GistId:4996b573cf231d9f66ab0d1f3f981222 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -41,16 +44,18 @@ public void InsertOleObjectWithOlePackage() } //ExEnd:InsertOleObjectwithOlePackage - //ExStart:GetAccessToOLEObjectRawData + //ExStart:GetAccessToOleObjectRawData + //GistId:4996b573cf231d9f66ab0d1f3f981222 Shape oleShape = (Shape) doc.GetChild(NodeType.Shape, 0, true); byte[] oleRawData = oleShape.OleFormat.GetRawData(); - //ExEnd:GetAccessToOLEObjectRawData + //ExEnd:GetAccessToOleObjectRawData } [Test] public void InsertOleObjectAsIcon() { - //ExStart:InsertOLEObjectAsIcon + //ExStart:InsertOleObjectAsIcon + //GistId:4996b573cf231d9f66ab0d1f3f981222 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -58,13 +63,14 @@ public void InsertOleObjectAsIcon() "My embedded file"); doc.Save(ArtifactsDir + "WorkingWithOleObjectsAndActiveX.InsertOleObjectAsIcon.docx"); - //ExEnd:InsertOLEObjectAsIcon + //ExEnd:InsertOleObjectAsIcon } [Test] public void InsertOleObjectAsIconUsingStream() { - //ExStart:InsertOLEObjectAsIconUsingStream + //ExStart:InsertOleObjectAsIconUsingStream + //GistId:4996b573cf231d9f66ab0d1f3f981222 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -72,7 +78,7 @@ public void InsertOleObjectAsIconUsingStream() builder.InsertOleObjectAsIcon(stream, "Package", ImagesDir + "Logo icon.ico", "My embedded file"); doc.Save(ArtifactsDir + "WorkingWithOleObjectsAndActiveX.InsertOleObjectAsIconUsingStream.docx"); - //ExEnd:InsertOLEObjectAsIconUsingStream + //ExEnd:InsertOleObjectAsIconUsingStream } [Test] @@ -105,5 +111,47 @@ public void ReadActiveXControlProperties() properties = properties + "\nTotal ActiveX Controls found: " + doc.GetChildNodes(NodeType.Shape, true).Count; Console.WriteLine("\n" + properties); } + + [Test] + public void InsertOnlineVideo() + { + //ExStart:InsertOnlineVideo + //GistId:4996b573cf231d9f66ab0d1f3f981222 + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + + string url = "https://youtu.be/t_1LYZ102RA"; + double width = 360; + double height = 270; + + Shape shape = builder.InsertOnlineVideo(url, width, height); + + doc.Save(ArtifactsDir + "WorkingWithOleObjectsAndActiveX.InsertOnlineVideo.docx"); + //ExEnd:InsertOnlineVideo + } + + [Test] + public void InsertOnlineVideoWithEmbedHtml() + { + //ExStart:InsertOnlineVideoWithEmbedHtml + //GistId:4996b573cf231d9f66ab0d1f3f981222 + Document doc = new Document(); + DocumentBuilder builder = new DocumentBuilder(doc); + + double width = 360; + double height = 270; + + string videoUrl = "https://vimeo.com/52477838"; + string videoEmbedCode = + ""; + + byte[] thumbnailImageBytes = File.ReadAllBytes(ImagesDir + "Logo.jpg"); + + builder.InsertOnlineVideo(videoUrl, videoEmbedCode, thumbnailImageBytes, width, height); + + doc.Save(ArtifactsDir + "WorkingWithOleObjectsAndActiveX.InsertOnlineVideoWithEmbedHtml.docx"); + //ExEnd:InsertOnlineVideoWithEmbedHtml + } } } \ No newline at end of file diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Revisions.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Revisions.cs index ca4619066..9bdf136b7 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Revisions.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Revisions.cs @@ -14,6 +14,7 @@ internal class WorkingWithRevisions : DocsExamplesBase public void AcceptRevisions() { //ExStart:AcceptAllRevisions + //GistId:e8d71fde166d275d0fc9471c56c3ad39 Document doc = new Document(); Body body = doc.FirstSection.Body; Paragraph para = body.FirstParagraph; @@ -172,6 +173,7 @@ public void AccessRevisedVersion() public void MoveNodeInTrackedDocument() { //ExStart:MoveNodeInTrackedDocument + //GistId:e8d71fde166d275d0fc9471c56c3ad39 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Paragraph 1"); @@ -210,6 +212,7 @@ public void MoveNodeInTrackedDocument() public void ShapeRevision() { //ExStart:ShapeRevision + //GistId:e8d71fde166d275d0fc9471c56c3ad39 Document doc = new Document(); // Insert an inline shape without tracking revisions. diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Textboxes.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Textboxes.cs index da8463e7b..643cdc155 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Textboxes.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with Textboxes.cs @@ -8,9 +8,10 @@ namespace DocsExamples.Programming_with_Documents internal class WorkingWithTextboxes { [Test] - public void CreateALink() + public void CreateLink() { - //ExStart:CreateALink + //ExStart:CreateLink + //GistId:68b6041746b3d6bf5137cff8e6385b5f Document doc = new Document(); Shape shape1 = new Shape(doc, ShapeType.TextBox); @@ -21,39 +22,35 @@ public void CreateALink() if (textBox1.IsValidLinkTarget(textBox2)) textBox1.Next = textBox2; - //ExEnd:CreateALink + //ExEnd:CreateLink } [Test] public void CheckSequence() { //ExStart:CheckSequence + //GistId:68b6041746b3d6bf5137cff8e6385b5f Document doc = new Document(); Shape shape = new Shape(doc, ShapeType.TextBox); TextBox textBox = shape.TextBox; if (textBox.Next != null && textBox.Previous == null) - { Console.WriteLine("The head of the sequence"); - } if (textBox.Next != null && textBox.Previous != null) - { Console.WriteLine("The Middle of the sequence."); - } if (textBox.Next == null && textBox.Previous != null) - { Console.WriteLine("The Tail of the sequence."); - } //ExEnd:CheckSequence } [Test] - public void BreakALink() + public void BreakLink() { - //ExStart:BreakALink + //ExStart:BreakLink + //GistId:68b6041746b3d6bf5137cff8e6385b5f Document doc = new Document(); Shape shape = new Shape(doc, ShapeType.TextBox); @@ -67,7 +64,7 @@ public void BreakALink() // Break a link, which leads to this textbox. textBox.Previous?.BreakForwardLink(); - //ExEnd:BreakALink + //ExEnd:BreakLink } } } \ No newline at end of file diff --git a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with VBA Macros.cs b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with VBA Macros.cs index 421455a46..a9492a7f7 100644 --- a/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with VBA Macros.cs +++ b/Examples/DocsExamples/DocsExamples/Programming with Documents/Working with VBA Macros.cs @@ -12,6 +12,7 @@ internal class WorkingWithVba : DocsExamplesBase public void CreateVbaProject() { //ExStart:CreateVbaProject + //GistId:d9bac4ed890f81ea3de392ecfeedbc55 Document doc = new Document(); VbaProject project = new VbaProject(); @@ -35,6 +36,7 @@ public void CreateVbaProject() public void ReadVbaMacros() { //ExStart:ReadVbaMacros + //GistId:d9bac4ed890f81ea3de392ecfeedbc55 Document doc = new Document(MyDir + "VBA project.docm"); if (doc.VbaProject != null) @@ -51,6 +53,7 @@ public void ReadVbaMacros() public void ModifyVbaMacros() { //ExStart:ModifyVbaMacros + //GistId:d9bac4ed890f81ea3de392ecfeedbc55 Document doc = new Document(MyDir + "VBA project.docm"); VbaProject project = doc.VbaProject; @@ -67,6 +70,7 @@ public void ModifyVbaMacros() public void CloneVbaProject() { //ExStart:CloneVbaProject + //GistId:d9bac4ed890f81ea3de392ecfeedbc55 Document doc = new Document(MyDir + "VBA project.docm"); Document destDoc = new Document { VbaProject = doc.VbaProject.Clone() }; @@ -78,6 +82,7 @@ public void CloneVbaProject() public void CloneVbaModule() { //ExStart:CloneVbaModule + //GistId:d9bac4ed890f81ea3de392ecfeedbc55 Document doc = new Document(MyDir + "VBA project.docm"); Document destDoc = new Document { VbaProject = new VbaProject() }; @@ -89,9 +94,10 @@ public void CloneVbaModule() } [Test] - public void RemoveBrokenRef() + public void RemoveVbaReferences() { - //ExStart:RemoveReferenceFromCollectionOfReferences + //ExStart:RemoveVbaReferences + //GistId:d9bac4ed890f81ea3de392ecfeedbc55 Document doc = new Document(MyDir + "VBA project.docm"); // Find and remove the reference with some LibId path. @@ -106,10 +112,11 @@ public void RemoveBrokenRef() references.RemoveAt(i); } - doc.Save(ArtifactsDir + "WorkingWithVba.RemoveBrokenRef.docm"); - //ExEnd:RemoveReferenceFromCollectionOfReferences + doc.Save(ArtifactsDir + "WorkingWithVba.RemoveVbaReferences.docm"); + //ExEnd:RemoveVbaReferences } //ExStart:GetLibIdAndReferencePath + //GistId:d9bac4ed890f81ea3de392ecfeedbc55 /// /// Returns string representing LibId path of a specified reference. /// diff --git a/Examples/DocsExamples/DocsExamples/Rendering and Printing/Print documents.cs b/Examples/DocsExamples/DocsExamples/Rendering and Printing/Print documents.cs index 8cb53077c..a0e77668c 100644 --- a/Examples/DocsExamples/DocsExamples/Rendering and Printing/Print documents.cs +++ b/Examples/DocsExamples/DocsExamples/Rendering and Printing/Print documents.cs @@ -319,7 +319,7 @@ private XpsPrintHelper() { } - //ExStart:XpsPrint_PrintDocument + //ExStart:XpsPrint_PrintDocument /// /// Sends an Aspose.Words document to a printer using the XpsPrint API. /// @@ -345,7 +345,7 @@ public static void Print(Document document, string printerName, string jobName, } //ExEnd:XpsPrint_PrintDocument - //ExStart:XpsPrint_PrintStream + //ExStart:XpsPrint_PrintStream /// /// Sends a stream that contains a document in the XPS format to a printer using the XpsPrint API. /// Has no dependency on Aspose.Words, can be used in any project. diff --git a/Examples/DocsExamples/DocumentExplorer/DocumentExplorer.csproj b/Examples/DocsExamples/DocumentExplorer/DocumentExplorer.csproj index eb8fc886b..cade5bc86 100644 --- a/Examples/DocsExamples/DocumentExplorer/DocumentExplorer.csproj +++ b/Examples/DocsExamples/DocumentExplorer/DocumentExplorer.csproj @@ -141,7 +141,7 @@ - 24.10.0 + 25.2.0 diff --git a/Examples/DocsExamples/PluginsExamples/PluginsExamples.csproj b/Examples/DocsExamples/PluginsExamples/PluginsExamples.csproj index 3916c8dde..8d1e2ed70 100644 --- a/Examples/DocsExamples/PluginsExamples/PluginsExamples.csproj +++ b/Examples/DocsExamples/PluginsExamples/PluginsExamples.csproj @@ -11,10 +11,10 @@ - - + + - + diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Add table.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Add table.cs index 6d370d2ad..971172618 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Add table.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Add table.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -9,12 +14,11 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features public class AddTable : TestUtil { [Test] - public void AddTableFeature() + public void CreateTable() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); - // Build a 2x2 table. builder.StartTable(); builder.InsertCell(); builder.Write("Row 1, Cell 1 Content."); @@ -29,7 +33,7 @@ public void AddTableFeature() builder.EndRow(); builder.EndTable(); - doc.Save(ArtifactsDir + "Add table - Aspose.Words.docx"); + doc.Save(ArtifactsDir + "CreateTable - Aspose.Words.docx"); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Change or replace header and footer.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Change or replace header and footer.cs index e4ff0b36c..2472f5ee7 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Change or replace header and footer.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Change or replace header and footer.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -9,7 +14,7 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features public class ChangeOrReplaceHeaderAndFooter : TestUtil { [Test] - public void ChangeOrReplaceHeaderAndFooterFeature() + public void CreateHeaderFooter() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -19,7 +24,7 @@ public void ChangeOrReplaceHeaderAndFooterFeature() builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary); builder.Write("Aspose.Words Footer"); - doc.Save(ArtifactsDir + "Change or replace header and footer - Aspose.Words.docx"); + doc.Save(ArtifactsDir + "Create header footer - Aspose.Words.docx"); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Change text in a table.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Change text in a table.cs index ac1f4c9f0..169893ca8 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Change text in a table.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Change text in a table.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using Aspose.Words.Replacing; @@ -11,23 +16,21 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features class ChangeTextInATable : TestUtil { [Test] - public void ChangeTextInATableFeature() + public void ReplaceText() { Document doc = new Document(MyDir + "Change text in a table.docx"); // Get the first table in the document. Table table = (Table)doc.GetChild(NodeType.Table, 0, true); - // Replace any instances of our string in the last cell of the table only. FindReplaceOptions options = new FindReplaceOptions { MatchCase = true, FindWholeWordsOnly = true }; - table.Rows[1].Cells[2].Range.Replace("Mr", "test", options); - doc.Save(ArtifactsDir + "Change text in a table - Aspose.Words.docx"); + doc.Save(ArtifactsDir + "Replace text - Aspose.Words.docx"); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Convert from docm to docx.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Convert from docm to docx.cs index 95001c136..a3a4d514c 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Convert from docm to docx.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Convert from docm to docx.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -9,10 +14,10 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features public class ConvertFromDocmToDocx : TestUtil { [Test] - public void ConvertFromDocmToDocxFeature() + public void DocmToDocxConversion() { - Document doc = new Document(MyDir + "Convert from docm to docx.docm"); - doc.Save(ArtifactsDir + "Convert from docm to docx - Aspose.Words.docx", SaveFormat.Docx); + Document doc = new Document(MyDir + "Docm to Docx conversion.docm"); + doc.Save(ArtifactsDir + "Docm to Docx conversion - Aspose.Words.docx"); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Create a document.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Create a document.cs index 023146e63..58bba8b00 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Create a document.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Create a document.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -9,14 +14,14 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features public class CreateADocument : TestUtil { [Test] - public void CreateADocumentFeature() + public void CreateNewDocument() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello World!"); - doc.Save(ArtifactsDir + "Create a document - Aspose.Words.docx"); + doc.Save(ArtifactsDir + "Create new document - Aspose.Words.docx"); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Create and add a paragraph style.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Create and add a paragraph style.cs index fefba59e3..1dafb3e00 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Create and add a paragraph style.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Create and add a paragraph style.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -9,7 +14,7 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features public class CreateAndAddAParagraphStyle : TestUtil { [Test] - public void CreateAndAddAParagraphStyleFeature() + public void ParagraphCustomStyle() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); @@ -24,12 +29,12 @@ public void CreateAndAddAParagraphStyleFeature() font.Spacing = 5; font.Underline = Underline.Double; - builder.ParagraphFormat.Style = doc.Styles["MyStyle"]; - builder.MoveToDocumentEnd(); + + builder.ParagraphFormat.Style = doc.Styles["MyStyle"]; builder.Writeln("This string is formatted using the new style."); - doc.Save(ArtifactsDir + "Create and add a paragraph style - Aspose.Words.docx"); + doc.Save(ArtifactsDir + "Paragraph custom style - Aspose.Words.docx"); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Extract image from word document.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Extract image from word document.cs index b160293a2..549e3ec41 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Extract image from word document.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Extract image from word document.cs @@ -1,7 +1,10 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// -using System.Collections.Generic; -using System.IO; using System.Linq; using Aspose.Words; using Aspose.Words.Drawing; @@ -13,26 +16,23 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features public class ExtractImageFromWordDocument : TestUtil { [Test] - public void ExtractImageFromWordDocumentFeature() + public void ExtractImage() { Document doc = new Document(MyDir + "Extract image.docx"); - // Save the document to memory and reload it. - using (MemoryStream stream = new MemoryStream()) - { - doc.Save(stream, SaveFormat.Doc); - Document doc2 = new Document(stream); - - // "Shape" nodes that have the "HasImage" flag set contain and display images. - IEnumerable shapes = doc2.GetChildNodes(NodeType.Shape, true) - .OfType().Where(s => s.HasImage); + // Get the collection of shapes from the document, + // and save the image data of every shape with an image as a file to the local file system. + NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true); - int imageIndex = 0; - foreach (Shape shape in shapes) + int imageIndex = 0; + foreach (Shape shape in shapes.OfType()) + { + if (shape.HasImage) { + // The image data of shapes may contain images of many possible image formats. + // We can determine a file extension for each image automatically, based on its format. string imageFileName = - $"Image.ExportImages.{imageIndex}_Aspose.Words_{FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType)}"; - + $"ExtractImage.{imageIndex}.Aspose.Words{FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType)}"; shape.ImageData.Save(ArtifactsDir + imageFileName); imageIndex++; } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/All field update.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/All field update.cs index 2a256027f..9e3bf863b 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/All field update.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/All field update.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert document to EPUB.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert document to EPUB.cs index a5ae724b8..32ada353e 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert document to EPUB.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert document to EPUB.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using Aspose.Words.Saving; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert to Mhtml email.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert to Mhtml email.cs index 9a99476c3..281033164 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert to Mhtml email.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert to Mhtml email.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.IO; using Aspose.Email; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert to Rtf.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert to Rtf.cs index 4f3738ad5..b1ac7a947 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert to Rtf.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert to Rtf.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -12,7 +17,6 @@ public class ConvertToRtf : TestUtil public static void ConvertToRtfFeature() { Document doc = new Document(MyDir + "Document.docx"); - doc.Save(ArtifactsDir + "Convert to Rtf - Aspose.Words.rtf"); } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert to byte array.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert to byte array.cs index 709373255..63815b523 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert to byte array.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Convert to byte array.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.IO; using Aspose.Words; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Converting document to Pdf.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Converting document to Pdf.cs index ce4b793bd..3b9cefa1f 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Converting document to Pdf.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Converting document to Pdf.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -12,8 +17,7 @@ public class ConvertingDocumentToPdf : TestUtil public static void ConvertingDocumentToPdfFeature() { Document doc = new Document(MyDir + "Document.docx"); - - doc.Save(ArtifactsDir + "Converting document to Pdf - Aspose.Words.pdf", SaveFormat.Pdf); + doc.Save(ArtifactsDir + "Converting document to Pdf - Aspose.Words.pdf"); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Execute simple mail merge.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Execute simple mail merge.cs index 2a6736ff7..b2d664d14 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Execute simple mail merge.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Execute simple mail merge.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -15,8 +20,8 @@ public static void ExecuteSimpleMailMergeFeature() // Fill the fields in the document with user data. doc.MailMerge.Execute( - new string[] { "Name", "City" }, - new object[] { "Zeeshan", "Islamabad" }); + ["Name", "City"], + ["Zeeshan", "Islamabad"]); // Send the document in Word format to the client browser with an option to save to disk or open inside the current browser. doc.Save(ArtifactsDir + "Execute simple mail merge - Aspose.Words.docx"); diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Find and replace.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Find and replace.cs index d8e927b63..6b8ca9dcc 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Find and replace.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Find and replace.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.Text.RegularExpressions; using Aspose.Words; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Insert table of content.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Insert table of content.cs index 6cbafe367..2e086f609 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Insert table of content.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Insert table of content.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Inserting form fields.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Inserting form fields.cs index 1320afd0f..f78f7ef90 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Inserting form fields.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Inserting form fields.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Joining multiple documents.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Joining multiple documents.cs index f00d63835..de9543884 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Joining multiple documents.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Joining multiple documents.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Joining tables.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Joining tables.cs index c2ceadae8..71f682385 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Joining tables.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Joining tables.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using Aspose.Words.Tables; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Keeping the content from split.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Keeping the content from split.cs index a595ac0f0..63f360fb6 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Keeping the content from split.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Keeping the content from split.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -19,9 +24,7 @@ public static void KeepingTheContentFromSplitFeature() // Iterate through all sections in the source document. foreach (Paragraph para in srcDoc.GetChildNodes(NodeType.Paragraph, true)) - { para.ParagraphFormat.KeepWithNext = true; - } dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting); dstDoc.Save(ArtifactsDir + "Keeping the content from split - Aspose.Words.docx"); diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Mail merge from xml using DataSet.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Mail merge from xml using DataSet.cs index 26c5967b3..b022f908f 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Mail merge from xml using DataSet.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Mail merge from xml using DataSet.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.Data; using Aspose.Words; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Nested mail merge regions.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Nested mail merge regions.cs index 9c2a31a14..3cad43175 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Nested mail merge regions.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Nested mail merge regions.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.Data; using Aspose.Words; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Obtaining form fields.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Obtaining form fields.cs index cf882e90b..493df09bc 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Obtaining form fields.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Obtaining form fields.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using Aspose.Words.Fields; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Print document via Xps Api.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Print document via Xps Api.cs index 29e684e4a..4051e8795 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Print document via Xps Api.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Print document via Xps Api.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System; using Aspose.Words; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Render shapes.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Render shapes.cs index 224031efc..6f99f59f3 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Render shapes.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Render shapes.cs @@ -1,10 +1,15 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.Drawing; -using System.Drawing.Imaging; using System.IO; using Aspose.Words; using Aspose.Words.Drawing; +using Aspose.Words.Layout; using Aspose.Words.Rendering; using Aspose.Words.Saving; using Aspose.Words.Tables; @@ -19,19 +24,18 @@ public class RenderShapes : TestUtil public void RenderShapeAsEmf() { Document doc = new Document(MyDir + "Rendering.docx"); - // Retrieve the target shape from the document. Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true); //ExStart:RenderShapeAsEmf + //GistId:7fc867ac8ef1b729b6f70580fbc5b3f9 ShapeRenderer render = shape.GetShapeRenderer(); - ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.Emf) { Scale = 1.5f }; - render.Save(ArtifactsDir + "RenderShape.RenderShapeAsEmf - Aspose.Words.emf", imageOptions); + render.Save(ArtifactsDir + "RenderShape.RenderShapeAsEmf.emf", imageOptions); //ExEnd:RenderShapeAsEmf } @@ -43,42 +47,40 @@ public void RenderShapeAsJpeg() Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true); //ExStart:RenderShapeAsJpeg + //GistId:7fc867ac8ef1b729b6f70580fbc5b3f9 ShapeRenderer render = new ShapeRenderer(shape); - ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.Jpeg) { // Output the image in gray scale ImageColorMode = ImageColorMode.Grayscale, - // Reduce the brightness a bit (default is 0.5f) ImageBrightness = 0.45f }; - using (FileStream stream = new FileStream(ArtifactsDir + "RenderShape.RenderShapeAsJpeg - Aspose.Words.jpg", FileMode.Create)) + using (FileStream stream = new FileStream(ArtifactsDir + "RenderShape.RenderShapeAsJpeg.jpg", FileMode.Create)) { render.Save(stream, imageOptions); } //ExEnd:RenderShapeAsJpeg } - +#if NET48 || JAVA [Test] //ExStart:RenderShapeToGraphics + //GistId:7fc867ac8ef1b729b6f70580fbc5b3f9 public void RenderShapeToGraphics() { Document doc = new Document(MyDir + "Rendering.docx"); - - Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true); - + + Shape shape = (Shape) doc.GetChild(NodeType.Shape, 0, true); ShapeRenderer render = shape.GetShapeRenderer(); // Find the size that the shape will be rendered to at the specified scale and resolution. Size shapeSizeInPixels = render.GetSizeInPixels(1.0f, 96.0f); - // Rotating the shape may result in clipping as the image canvas is too small. Find the longest side // and make sure that the graphics canvas is large enough to compensate for this. int maxSide = System.Math.Max(shapeSizeInPixels.Width, shapeSizeInPixels.Height); - using (Bitmap image = new Bitmap((int)(maxSide * 1.25), (int)(maxSide * 1.25))) + using (Bitmap image = new Bitmap((int) (maxSide * 1.25), (int) (maxSide * 1.25))) { // Rendering to a graphics object means we can specify settings and transformations to be applied to the rendered shape. // In our case we will rotate the rendered shape. @@ -87,21 +89,44 @@ public void RenderShapeToGraphics() // Clear the shape with the background color of the document. graphics.Clear(shape.Document.PageColor); // Center the rotation using the translation method below. - graphics.TranslateTransform((float)image.Width / 8, (float)image.Height / 2); + graphics.TranslateTransform((float) image.Width / 8, (float) image.Height / 2); // Rotate the image by 45 degrees. graphics.RotateTransform(45); // Undo the translation. - graphics.TranslateTransform(-(float)image.Width / 8, -(float)image.Height / 2); + graphics.TranslateTransform(-(float) image.Width / 8, -(float) image.Height / 2); // Render the shape onto the graphics object. render.RenderToSize(graphics, 0, 0, shapeSizeInPixels.Width, shapeSizeInPixels.Height); } - image.Save(ArtifactsDir + "RenderShape.RenderShapeToGraphics - Aspose.Words.png", ImageFormat.Png); + image.Save(ArtifactsDir + "RenderShape.RenderShapeToGraphics.png", ImageFormat.Png); } } //ExEnd:RenderShapeToGraphics + [Test] + public void FindShapeSizes() + { + Document doc = new Document(MyDir + "Rendering.docx"); + + Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true); + + //ExStart:FindShapeSizes + //GistId:7fc867ac8ef1b729b6f70580fbc5b3f9 + Size shapeRenderedSize = shape.GetShapeRenderer().GetSizeInPixels(1.0f, 96.0f); + + using (Bitmap image = new Bitmap(shapeRenderedSize.Width, shapeRenderedSize.Height)) + { + using (Graphics graphics = Graphics.FromImage(image)) + { + // Render shape onto the graphics object using the RenderToScale + // or RenderToSize methods of ShapeRenderer class. + } + } + //ExEnd:FindShapeSizes + } +#endif + [Test] public void RenderCellToImage() { @@ -109,7 +134,8 @@ public void RenderCellToImage() //ExStart:RenderCellToImage Cell cell = (Cell)doc.GetChild(NodeType.Cell, 2, true); - RenderNode(cell, ArtifactsDir + "RenderShape.RenderCellToImage - Aspose.Words.png", null); + Document tmp = ConvertToImage(doc, cell); + tmp.Save(ArtifactsDir + "RenderShape.RenderCellToImage.png"); //ExEnd:RenderCellToImage } @@ -120,7 +146,8 @@ public void RenderRowToImage() //ExStart:RenderRowToImage Row row = (Row)doc.GetChild(NodeType.Row, 0, true); - RenderNode(row, ArtifactsDir + "RenderShape.RenderRowToImage - Aspose.Words.png", null); + Document tmp = ConvertToImage(doc, row); + tmp.Save(ArtifactsDir + "RenderShape.RenderRowToImage.png"); //ExEnd:RenderRowToImage } @@ -141,150 +168,108 @@ public void RenderParagraphToImage() PaperColor = Color.LightPink }; - RenderNode(textBoxShape.LastParagraph, ArtifactsDir + "RenderShape.RenderParagraphToImage - Aspose.Words.png", options); + Document tmp = ConvertToImage(doc, textBoxShape.LastParagraph); + tmp.Save(ArtifactsDir + "RenderShape.RenderParagraphToImage.png"); //ExEnd:RenderParagraphToImage } - [Test] - public void FindShapeSizes() - { - Document doc = new Document(MyDir + "Rendering.docx"); - - Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true); - - //ExStart:FindShapeSizes - Size shapeRenderedSize = shape.GetShapeRenderer().GetSizeInPixels(1.0f, 96.0f); - - using (Bitmap image = new Bitmap(shapeRenderedSize.Width, shapeRenderedSize.Height)) - { - using (Graphics graphics = Graphics.FromImage(image)) - { - // Render shape onto the graphics object using the RenderToScale or RenderToSize methods of ShapeRenderer class. - } - } - //ExEnd:FindShapeSizes - } - [Test] public void RenderShapeImage() { Document doc = new Document(MyDir + "Rendering.docx"); Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true); - //ExStart:RenderShapeImage - shape.GetShapeRenderer().Save(ArtifactsDir + "RenderShape.RenderShapeImage - Aspose.Words.jpg", null); + //GistId:7fc867ac8ef1b729b6f70580fbc5b3f9 + shape.GetShapeRenderer().Save(ArtifactsDir + "RenderShape.RenderShapeImage.jpg", new ImageSaveOptions(SaveFormat.Jpeg)); //ExEnd:RenderShapeImage } /// - /// Renders any node in a document to the path specified using the image save options. + /// Renders any node in a document into an image. /// + /// The current document. /// The node to render. - /// The path to save the rendered image to. - /// The image options to use during rendering. This can be null. - public void RenderNode(Node node, string filePath, ImageSaveOptions imageOptions) + private static Document ConvertToImage(Document doc, CompositeNode node) { - if (imageOptions == null) - imageOptions = new ImageSaveOptions(FileFormatUtil.ExtensionToSaveFormat(Path.GetExtension(filePath))); - - // Store the paper color to be used on the final image and change to transparent. - // This will cause any content around the rendered node to be removed later on. - Color savePaperColor = imageOptions.PaperColor; - imageOptions.PaperColor = Color.Transparent; - - // There a bug which affects the cache of a cloned node. - // To avoid this, we clone the entire document, including all nodes, - // finding the matching node in the cloned document and rendering that instead. - Document doc = (Document)node.Document.Clone(true); - node = doc.GetChild(NodeType.Any, node.Document.GetChildNodes(NodeType.Any, true).IndexOf(node), true); - - // Create a temporary shape to store the target node in. This shape will be rendered to retrieve - // the rendered content of the node. - Shape shape = new Shape(doc, ShapeType.TextBox); - Section parentSection = (Section)node.GetAncestor(NodeType.Section); - - // Assume that the node cannot be larger than the page in size. - shape.Width = parentSection.PageSetup.PageWidth; - shape.Height = parentSection.PageSetup.PageHeight; - shape.FillColor = Color.Transparent; - - // Don't draw a surronding line on the shape. - shape.Stroked = false; - - // Move up through the DOM until we find a suitable node to insert into a Shape - // (a node with a parent can contain paragraphs, tables the same as a shape). Each parent node is cloned - // on the way up so even a descendant node passed to this method can be rendered. Since we are working - // with the actual nodes of the document we need to clone the target node into the temporary shape. - Node currentNode = node; - while (!(currentNode.ParentNode is InlineStory || currentNode.ParentNode is Story || - currentNode.ParentNode is ShapeBase)) - { - CompositeNode parent = (CompositeNode)currentNode.ParentNode.Clone(false); - currentNode = currentNode.ParentNode; - parent.AppendChild(node.Clone(true)); - node = parent; // Store this new node to be inserted into the shape. - } + Document tmp = CreateTemporaryDocument(doc, node); + AppendNodeContent(tmp, node); + AdjustDocumentLayout(tmp); + return tmp; + } - // We must add the shape to the document tree to have it rendered. - shape.AppendChild(node.Clone(true)); - parentSection.Body.FirstParagraph.AppendChild(shape); + /// + /// Creates a temporary document for further rendering. + /// + private static Document CreateTemporaryDocument(Document doc, CompositeNode node) + { + Document tmp = (Document)doc.Clone(false); + tmp.Sections.Add(tmp.ImportNode(node.GetAncestor(NodeType.Section), false, ImportFormatMode.UseDestinationStyles)); + tmp.FirstSection.AppendChild(new Body(tmp)); + tmp.FirstSection.PageSetup.TopMargin = 0; + tmp.FirstSection.PageSetup.BottomMargin = 0; - // Render the shape to stream so we can take advantage of the effects of the ImageSaveOptions class. - // Retrieve the rendered image and remove the shape from the document. - MemoryStream stream = new MemoryStream(); - ShapeRenderer renderer = shape.GetShapeRenderer(); - renderer.Save(stream, imageOptions); - shape.Remove(); + return tmp; + } - Rectangle crop = renderer.GetOpaqueBoundsInPixels(imageOptions.Scale, imageOptions.HorizontalResolution, - imageOptions.VerticalResolution); + /// + /// Adds a node to a temporary document. + /// + private static void AppendNodeContent(Document tmp, CompositeNode node) + { + if (node is HeaderFooter headerFooter) + foreach (Node hfNode in headerFooter.GetChildNodes(NodeType.Any, false)) + tmp.FirstSection.Body.AppendChild(tmp.ImportNode(hfNode, true, ImportFormatMode.UseDestinationStyles)); + else + AppendNonHeaderFooterContent(tmp, node); + } - using (Bitmap renderedImage = new Bitmap(stream)) + private static void AppendNonHeaderFooterContent(Document tmp, CompositeNode node) + { + Node parentNode = node.ParentNode; + while (!(parentNode is InlineStory || parentNode is Story || parentNode is ShapeBase)) { - Bitmap croppedImage = new Bitmap(crop.Width, crop.Height); - croppedImage.SetResolution(imageOptions.HorizontalResolution, imageOptions.VerticalResolution); - - // Create the final image with the proper background color. - using (Graphics g = Graphics.FromImage(croppedImage)) - { - g.Clear(savePaperColor); - g.DrawImage(renderedImage, new Rectangle(0, 0, croppedImage.Width, croppedImage.Height), crop.X, - crop.Y, crop.Width, crop.Height, GraphicsUnit.Pixel); + CompositeNode parent = (CompositeNode)parentNode.Clone(false); + parent.AppendChild(node.Clone(true)); + node = parent; - croppedImage.Save(filePath); - } + parentNode = parentNode.ParentNode; } + + tmp.FirstSection.Body.AppendChild(tmp.ImportNode(node, true, ImportFormatMode.UseDestinationStyles)); } /// - /// Finds the minimum bounding box around non-transparent pixels in a Bitmap. + /// Adjusts the layout of the document to fit the content area. /// - public Rectangle FindBoundingBoxAroundNode(Bitmap originalBitmap) + private static void AdjustDocumentLayout(Document tmp) { - Point min = new Point(int.MaxValue, int.MaxValue); - Point max = new Point(int.MinValue, int.MinValue); + LayoutEnumerator enumerator = new LayoutEnumerator(tmp); + RectangleF rect = RectangleF.Empty; + rect = CalculateVisibleRect(enumerator, rect); + + tmp.FirstSection.PageSetup.PageHeight = rect.Height; + tmp.UpdatePageLayout(); + } - for (int x = 0; x < originalBitmap.Width; ++x) + /// + /// Calculates the visible area of the content. + /// + private static RectangleF CalculateVisibleRect(LayoutEnumerator enumerator, RectangleF rect) + { + RectangleF result = rect; + do { - for (int y = 0; y < originalBitmap.Height; ++y) + if (enumerator.MoveFirstChild()) { - // Note that you can speed up this part of the algorithm using LockBits and unsafe code instead of GetPixel. - Color pixelColor = originalBitmap.GetPixel(x, y); - - // For each pixel that is not transparent, calculate the bounding box around it. - if (pixelColor.ToArgb() != Color.Empty.ToArgb()) - { - min.X = System.Math.Min(x, min.X); - min.Y = System.Math.Min(y, min.Y); - max.X = System.Math.Max(x, max.X); - max.Y = System.Math.Max(y, max.Y); - } + if (enumerator.Type == LayoutEntityType.Line || enumerator.Type == LayoutEntityType.Span) + result = result.IsEmpty ? enumerator.Rectangle : RectangleF.Union(result, enumerator.Rectangle); + result = CalculateVisibleRect(enumerator, result); + enumerator.MoveParent(); } - } + } while (enumerator.MoveNext()); - // Add one pixel to the width and height to avoid clipping. - return new Rectangle(min.X, min.Y, max.X - min.X + 1, max.Y - min.Y + 1); + return result; } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Save as multipage tiff.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Save as multipage tiff.cs index fd4b7ab97..577fba6ff 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Save as multipage tiff.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Save as multipage tiff.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using Aspose.Words.Saving; @@ -8,19 +13,18 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features.Features_missing_in_OpenXML { [TestFixture] public class SaveAsMultiPageTiff : TestUtil - - { - [Test] - public static void SaveAsMultiPageTiffFeature() { - Document doc = new Document(MyDir + "Rendering.docx"); + [Test] + public static void SaveAsMultiPageTiffFeature() + { + Document doc = new Document(MyDir + "Rendering.docx"); - ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff); - options.PageSet = new PageSet(new PageRange(0, doc.PageCount)); - options.TiffCompression = TiffCompression.Ccitt4; - options.Resolution = 160; + ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff); + options.PageSet = new PageSet(new PageRange(0, doc.PageCount)); + options.TiffCompression = TiffCompression.Ccitt4; + options.Resolution = 160; - doc.Save(ArtifactsDir + "Save as multipage tiff - Aspose.Words.tiff", options); - } + doc.Save(ArtifactsDir + "Save as multipage tiff - Aspose.Words.tiff", options); + } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Save doc as png.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Save doc as png.cs index 867196a55..3421cc6d8 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Save doc as png.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Save doc as png.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using Aspose.Words.Saving; @@ -21,7 +26,7 @@ public static void SaveDocAsPngFeature() for (int i = 0; i < doc.PageCount; i++) { options.PageSet = new PageSet(i); - doc.Save(string.Format(ArtifactsDir + i + " Save doc as png - Aspose.Words.png", i), options); + doc.Save(ArtifactsDir + $"Save doc as png ({i}) - Aspose.Words.png", options); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Splitting tables.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Splitting tables.cs index 73cb73198..2a2f11352 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Splitting tables.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Splitting tables.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using Aspose.Words.Tables; @@ -16,21 +21,16 @@ public static void SplittingTablesFeature() // Get the first table in the document. Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true); - // We will split the table at the third row (inclusive). Row row = firstTable.Rows[2]; - // Create a new container for the split table. Table table = (Table)firstTable.Clone(false); - // Insert the container after the original. firstTable.ParentNode.InsertAfter(table, firstTable); - // Add a buffer paragraph to ensure the tables stay apart. firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable); Row currentRow; - do { currentRow = firstTable.LastRow; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Xps print helper.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Xps print helper.cs index 25cc46a51..bf33369f5 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Xps print helper.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Features missing in OpenXML/Xps print helper.cs @@ -5,6 +5,7 @@ // "as is", without warranty of any kind, either expressed or implied. ////////////////////////////////////////////////////////////////////////// +using Aspose.Words; using System; using System.ComponentModel; using System.IO; @@ -32,17 +33,20 @@ private XpsPrintHelper() /// Job name. Can be null. /// True to wait for the job to complete. False to return immediately after submitting the job. /// Thrown if any error occurs. - public static void Print(Aspose.Words.Document document, string printerName, string jobName, bool isWait) + public static void Print(Document document, string printerName, string jobName, bool isWait) { + Console.WriteLine("Print"); if (document == null) - throw new ArgumentNullException("document"); + throw new ArgumentNullException(nameof(document)); - // Use Aspose.Words to convert the document to XPS and store in a memory stream. + // Use Aspose.Words to convert the document to XPS and store it in a memory stream. MemoryStream stream = new MemoryStream(); - document.Save(stream, Aspose.Words.SaveFormat.Xps); - stream.Position = 0; + document.Save(stream, SaveFormat.Xps); + stream.Position = 0; + Console.WriteLine("Saved as Xps"); Print(stream, printerName, jobName, isWait); + Console.WriteLine("After Print"); } /// @@ -57,37 +61,38 @@ public static void Print(Aspose.Words.Document document, string printerName, str public static void Print(Stream stream, string printerName, string jobName, bool isWait) { if (stream == null) - throw new ArgumentNullException("stream"); + throw new ArgumentNullException(nameof(stream)); if (printerName == null) - throw new ArgumentNullException("printerName"); + throw new ArgumentNullException(nameof(printerName)); // Create an event that we will wait on until the job is complete. IntPtr completionEvent = CreateEvent(IntPtr.Zero, true, false, null); if (completionEvent == IntPtr.Zero) throw new Win32Exception(); - try - { - IXpsPrintJob job; - IXpsPrintJobStream jobStream; - StartJob(printerName, jobName, completionEvent, out job, out jobStream); + Console.WriteLine("StartJob"); + StartJob(printerName, jobName, completionEvent, out IXpsPrintJob job, out IXpsPrintJobStream jobStream); + Console.WriteLine("Done StartJob"); - CopyJob(stream, job, jobStream); + Console.WriteLine("Start CopyJob"); + CopyJob(stream, jobStream); + Console.WriteLine("End CopyJob"); - if (isWait) - { - WaitForJob(completionEvent); - CheckJobStatus(job); - } - } - finally + Console.WriteLine("Start Wait"); + if (isWait) { - if (completionEvent != IntPtr.Zero) - CloseHandle(completionEvent); + WaitForJob(completionEvent); + CheckJobStatus(job); } + Console.WriteLine("End Wait"); + + if (completionEvent != IntPtr.Zero) + CloseHandle(completionEvent); + Console.WriteLine("Close Handle"); } - private static void StartJob(string printerName, string jobName, IntPtr completionEvent, out IXpsPrintJob job, out IXpsPrintJobStream jobStream) + private static void StartJob(string printerName, string jobName, IntPtr completionEvent, out IXpsPrintJob job, + out IXpsPrintJobStream jobStream) { int result = StartXpsPrintJob(printerName, jobName, null, IntPtr.Zero, completionEvent, null, 0, out job, out jobStream, IntPtr.Zero); @@ -95,39 +100,29 @@ private static void StartJob(string printerName, string jobName, IntPtr completi throw new Win32Exception(result); } - private static void CopyJob(Stream stream, IXpsPrintJob job, IXpsPrintJobStream jobStream) + private static void CopyJob(Stream stream, IXpsPrintJobStream jobStream) { - try - { - byte[] buff = new byte[4096]; - while (true) - { - uint read = (uint)stream.Read(buff, 0, buff.Length); - if (read == 0) - break; - - uint written; - jobStream.Write(buff, read, out written); - - if (read != written) - throw new Exception("Failed to copy data to the print job stream."); - } - - // Indicate that the entire document has been copied. - jobStream.Close(); - } - catch (Exception) + byte[] buff = new byte[4096]; + while (true) { - // Cancel the job if we had any trouble submitting it. - job.Cancel(); - throw; + uint read = (uint)stream.Read(buff, 0, buff.Length); + if (read == 0) + break; + + jobStream.Write(buff, read, out uint written); + + if (read != written) + throw new Exception("Failed to copy data to the print job stream."); } + + // Indicate that the entire document has been copied. + jobStream.Close(); } private static void WaitForJob(IntPtr completionEvent) { - const int INFINITE = -1; - switch (WaitForSingleObject(completionEvent, INFINITE)) + const int infinite = -1; + switch (WaitForSingleObject(completionEvent, infinite)) { case WAIT_RESULT.WAIT_OBJECT_0: // Expected result, do nothing. @@ -141,8 +136,7 @@ private static void WaitForJob(IntPtr completionEvent) private static void CheckJobStatus(IXpsPrintJob job) { - XPS_JOB_STATUS jobStatus; - job.GetJobStatus(out jobStatus); + job.GetJobStatus(out XPS_JOB_STATUS jobStatus); switch (jobStatus.completion) { case XPS_JOB_COMPLETION.XPS_JOB_COMPLETED: @@ -157,22 +151,23 @@ private static void CheckJobStatus(IXpsPrintJob job) [DllImport("XpsPrint.dll", EntryPoint = "StartXpsPrintJob")] private static extern int StartXpsPrintJob( - [MarshalAs(UnmanagedType.LPWStr)] String printerName, - [MarshalAs(UnmanagedType.LPWStr)] String jobName, - [MarshalAs(UnmanagedType.LPWStr)] String outputFileName, - IntPtr progressEvent, // HANDLE - IntPtr completionEvent, // HANDLE + [MarshalAs(UnmanagedType.LPWStr)] string printerName, + [MarshalAs(UnmanagedType.LPWStr)] string jobName, + [MarshalAs(UnmanagedType.LPWStr)] string outputFileName, + IntPtr progressEvent, + IntPtr completionEvent, [MarshalAs(UnmanagedType.LPArray)] byte[] printablePagesOn, - UInt32 printablePagesOnCount, + uint printablePagesOnCount, out IXpsPrintJob xpsPrintJob, out IXpsPrintJobStream documentStream, - IntPtr printTicketStream); // This is actually "out IXpsPrintJobStream", but we don't use it and just want to pass null, hence IntPtr. + IntPtr printTicketStream); // "out IXpsPrintJobStream", we don't use it and just want to pass null, hence IntPtr. [DllImport("Kernel32.dll", SetLastError = true)] - private static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName); + private static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, + string lpName); [DllImport("Kernel32.dll", SetLastError = true, ExactSpelling = true)] - private static extern WAIT_RESULT WaitForSingleObject(IntPtr handle, Int32 milliseconds); + private static extern WAIT_RESULT WaitForSingleObject(IntPtr handle, int milliseconds); [DllImport("Kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] @@ -189,20 +184,22 @@ private static extern int StartXpsPrintJob( /// So the hack is that we obtain the ISequentialStream interface but work with it as /// with the IXpsPrintJobStream interface. /// - [Guid("0C733A30-2A1C-11CE-ADE5-00AA0044773D")] // This is IID of ISequenatialSteam. + [Guid("0C733A30-2A1C-11CE-ADE5-00AA0044773D")] // This is IID of ISequenatialSteam. [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - interface IXpsPrintJobStream + internal interface IXpsPrintJobStream { // ISequentualStream methods. void Read([MarshalAs(UnmanagedType.LPArray)] byte[] pv, uint cb, out uint pcbRead); + void Write([MarshalAs(UnmanagedType.LPArray)] byte[] pv, uint cb, out uint pcbWritten); + // IXpsPrintJobStream methods. void Close(); } [Guid("5ab89b06-8194-425f-ab3b-d7a96e350161")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - interface IXpsPrintJob + internal interface IXpsPrintJob { void Cancel(); void GetJobStatus(out XPS_JOB_STATUS jobStatus); @@ -211,12 +208,12 @@ interface IXpsPrintJob [StructLayout(LayoutKind.Sequential)] struct XPS_JOB_STATUS { - public UInt32 jobId; - public Int32 currentDocument; - public Int32 currentPage; - public Int32 currentPageTotal; + public uint jobId; + public int currentDocument; + public int currentPage; + public int currentPageTotal; public XPS_JOB_COMPLETION completion; - public Int32 jobStatus; // UInt32 + public int jobStatus; }; enum XPS_JOB_COMPLETION @@ -232,6 +229,6 @@ enum WAIT_RESULT WAIT_OBJECT_0 = 0, WAIT_ABANDONED = 0x80, WAIT_TIMEOUT = 0x102, - WAIT_FAILED = -1 // 0xFFFFFFFF + WAIT_FAILED = -1 } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Get and set bookmark text.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Get and set bookmark text.cs index 7b9fc1432..d97e86758 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Get and set bookmark text.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Get and set bookmark text.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -9,16 +14,15 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features public class GetAndSetBookmarkText : TestUtil { [Test] - public void GetAndSetBookmarkTextFeature() + public void BookmarkText() { - Document doc = new Document(MyDir + "Get and set bookmark text.docx"); + Document doc = new Document(MyDir + "Bookmark.docx"); // Rename a bookmark and edit its text. Bookmark bookmark = doc.Range.Bookmarks["MyBookmark"]; - bookmark.Name = "RenamedBookmark"; bookmark.Text = "This is a new bookmarked text."; - doc.Save(ArtifactsDir + "Get and set bookmark text - Aspose.Words.docx"); + doc.Save(ArtifactsDir + "Bookmark text - Aspose.Words.docx"); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Insert a comment.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Insert a comment.cs index 444195f8d..55a9952fc 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Insert a comment.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Insert a comment.cs @@ -1,7 +1,13 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; +using System; namespace AsposeWordsVSOpenXML.AsposeWords_features { @@ -9,38 +15,27 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features public class InsertAComment : TestUtil { [Test] - public void InsertACommentFeature() + public void InsertComment() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); - Comment comment = new Comment(doc); - - // Insert some text into the comment. - Paragraph commentParagraph = new Paragraph(doc); - commentParagraph.AppendChild(new Run(doc, "This is comment!!!")); - comment.AppendChild(commentParagraph); - - // Create a "CommentRangeStart" and "CommentRangeEnd". - int commentId = 0; - CommentRangeStart start = new CommentRangeStart(doc, commentId); - CommentRangeEnd end = new CommentRangeEnd(doc, commentId); - - builder.Write("This text is before the comment. "); - - // Insert comment and comment range start. - builder.InsertNode(comment); - builder.InsertNode(start); - - // Insert some more text. - builder.Write("This text is commented. "); - - // Insert end of comment range. - builder.InsertNode(end); - - builder.Write("This text is after the comment."); - - doc.Save(ArtifactsDir + "Insert a comment - Aspose.Words.docx"); + Comment newComment = new Comment(doc) + { + Author = "Aspose.Words", + Initial = "AW", + DateTime = DateTime.Now + }; + newComment.SetText("Comment regarding text."); + + // Add text to the document, warp it in a comment range, and then add your comment. + Paragraph para = doc.FirstSection.Body.FirstParagraph; + para.AppendChild(new CommentRangeStart(doc, newComment.Id)); + para.AppendChild(new Run(doc, "Commented text.")); + para.AppendChild(new CommentRangeEnd(doc, newComment.Id)); + para.AppendChild(newComment); + + doc.Save(ArtifactsDir + "Insert comment - Aspose.Words.docx"); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Insert picture in word document.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Insert picture in word document.cs index d050c75b5..5e03b4292 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Insert picture in word document.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Insert picture in word document.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using Aspose.Words.Drawing; @@ -10,7 +15,7 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features public class InsertPictureInWordDocument : TestUtil { [Test] - public void InsertPictureInWordDocumentFeature() + public void InsertPicture() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Open and add text to word document.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Open and add text to word document.cs index ae5668d7a..755df049e 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Open and add text to word document.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Open and add text to word document.cs @@ -1,6 +1,10 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// -using System.Drawing; using Aspose.Words; using NUnit.Framework; @@ -10,21 +14,16 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features public class OpenAndAddTextToWordDocument : TestUtil { [Test] - public void OpenAndAddTextToWordDocumentFeature() + public void AddText() { Document doc = new Document(MyDir + "Document.docx"); DocumentBuilder builder = new DocumentBuilder(doc); - global::Aspose.Words.Font font = builder.Font; - font.Size = 16; - font.Bold = true; - font.Color = Color.Blue; - font.Name = "Arial"; - font.Underline = Underline.Dash; + builder.MoveToDocumentEnd(); + builder.Writeln(); + builder.Write("This is the text added to the end of the document."); - builder.Write("Formatted text."); - - doc.Save(ArtifactsDir + "Open and add text - Aspose.Words.docx"); + doc.Save(ArtifactsDir + "Add text - Aspose.Words.docx"); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Open document from stream.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Open document from stream.cs index 1ca30af7a..75edb71ce 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Open document from stream.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Open document from stream.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.IO; using Aspose.Words; @@ -10,18 +15,17 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features public class OpenDocumentFromStream : TestUtil { [Test] - public void OpenDocumentFromStreamFeature() + public void AddTextStream() { - Stream stream = File.Open(MyDir + "Document.docx", FileMode.Open); - - using (stream) + using (Stream stream = File.Open(MyDir + "Document.docx", FileMode.Open)) { Document doc = new Document(stream); DocumentBuilder builder = new DocumentBuilder(doc); - builder.Writeln("Append text in body - Open and add to wordprocessing stream"); + builder.Writeln(); + builder.Write("This is the text added to the end of the document."); - doc.Save(ArtifactsDir + "Open document from stream - Aspose.Words.docx"); + doc.Save(ArtifactsDir + "Add text stream - Aspose.Words.docx"); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Open read only access.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Open read only access.cs index b520410b0..5f231f253 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Open read only access.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Open read only access.cs @@ -1,6 +1,12 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; +using Aspose.Words.Loading; using NUnit.Framework; namespace AsposeWordsVSOpenXML.AsposeWords_features @@ -9,14 +15,15 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features class OpenReadOnlyAccess : TestUtil { [Test] - public void OpenReadOnlyAccessFeature() + public void OpenReadOnly() { Document doc = new Document(MyDir + "Open ReadOnly access.docx", new LoadOptions("1234")); DocumentBuilder builder = new DocumentBuilder(doc); - builder.Writeln("Append text in body - Open ReadOnly access"); + builder.Writeln(); + builder.Write("This is the text added to the end of the document."); - doc.Save(ArtifactsDir + "Open ReadOnly access - Aspose.Words.docx"); + doc.Save(ArtifactsDir + "Open encrypted - Aspose.Words.docx"); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove comments.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove comments.cs index 09da6bc96..e1fda023f 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove comments.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove comments.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -9,31 +14,23 @@ namespace AsposeWordsVSOpenXML.AsposeWords_features public class DeleteCommentsByAllOrASpecificAuthor : TestUtil { [Test] - public void DeleteCommentsByAllOrASpecificAuthorFeature() - { - RemoveComments(""); - } - - private void RemoveComments(string authorName) + private void RemoveComments() { Document doc = new Document(MyDir + "Comments.docx"); // Collect all comments in the document. NodeCollection comments = doc.GetChildNodes(NodeType.Comment, true); - if (authorName == "") - { + + string authorName = string.Empty; + if (authorName.Equals(string.Empty)) // Remove all comments. comments.Clear(); - } else { - // Look through all comments and remove those written by the authorName author. - for (int i = comments.Count - 1; i >= 0; i--) - { - Comment comment = (Comment)comments[i]; - if (comment.Author == authorName) + // Remove comments by author name. + foreach (Comment comment in comments) + if (comment.Author.Equals(authorName)) comment.Remove(); - } } doc.Save(ArtifactsDir + "Remove comments - Aspose.Words.docx"); diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove header footer.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove header footer.cs index e39cde971..67cedea93 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove header footer.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove header footer.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -12,15 +17,8 @@ public class RemoveHeaderFooter : TestUtil public void RemoveHeaderFooterFeature() { Document doc = new Document(MyDir + "Document.docx"); - foreach (Section section in doc) - { - section.HeadersFooters.RemoveAt(0); - - // Odd pages use the primary footer. - HeaderFooter footer = section.HeadersFooters[HeaderFooterType.FooterPrimary]; - - footer?.Remove(); - } + foreach (HeaderFooter headerFooter in doc.GetChildNodes(NodeType.HeaderFooter, true)) + headerFooter.Remove(); doc.Save(ArtifactsDir + "Remove header and footer - Aspose.Words.docx"); } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove hidden text.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove hidden text.cs index 02dea5453..918ce31fa 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove hidden text.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove hidden text.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -13,10 +18,10 @@ public void RemoveHiddenTextFeature() { Document doc = new Document(MyDir + "Remove hidden text.docx"); - foreach (Paragraph par in doc.GetChildNodes(NodeType.Paragraph, true)) + foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true)) { - par.ParagraphBreakFont.Hidden = false; - foreach (Run run in par.GetChildNodes(NodeType.Run, true)) + para.ParagraphBreakFont.Hidden = false; + foreach (Run run in para.GetChildNodes(NodeType.Run, true)) { if (run.Font.Hidden) run.Font.Hidden = false; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove page breaks.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove page breaks.cs index 4cd7f47d4..051cc0b2d 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove page breaks.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove page breaks.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; @@ -13,19 +18,14 @@ public void RemovePageBreaksFeature() { Document doc = new Document(MyDir + "Remove page breaks.docx"); - // Retrieve all paragraphs in the document. - NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true); - - foreach (Paragraph para in paragraphs) + // Remove all page breaks. + foreach (Paragraph paragraph in doc.GetChildNodes(NodeType.Paragraph, true)) { - // If the paragraph has a page break set before, then clear it. - if (para.ParagraphFormat.PageBreakBefore) - para.ParagraphFormat.PageBreakBefore = false; - - // Check all runs in the paragraph for page breaks and remove them. - foreach (Run run in para.Runs) + foreach (Run run in paragraph.Runs) + { if (run.Text.Contains(ControlChar.PageBreak)) - run.Text = run.Text.Replace(ControlChar.PageBreak, string.Empty); + run.Text = run.Text.Replace(ControlChar.PageBreak.ToString(), string.Empty); + } } doc.Save(ArtifactsDir + "Remove page breaks - Aspose.Words.docx"); diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove section breaks.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove section breaks.cs index 14f3129ee..897089060 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove section breaks.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Remove section breaks.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using Aspose.Words; using NUnit.Framework; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Retrieve comments.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Retrieve comments.cs index e5dae3b30..219032d85 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Retrieve comments.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Retrieve comments.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System; using System.Collections; diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Search and replace text.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Search and replace text.cs index 9de4b0009..2fbc2e1b9 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Search and replace text.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWords features/Search and replace text.cs @@ -1,6 +1,10 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// -using System.Text.RegularExpressions; using Aspose.Words; using NUnit.Framework; @@ -14,8 +18,7 @@ public static void SearchAndReplaceTextFeature() { Document doc = new Document(MyDir + "Search and replace text.docx"); - Regex regex = new Regex("Hello World!", RegexOptions.IgnoreCase); - doc.Range.Replace(regex, "Hi Everyone!"); + doc.Range.Replace("Hello World!", "Hi Everyone!"); doc.Save(ArtifactsDir + "Search and replace text - Aspose.Words.docx"); } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWordsVSOpenXML.csproj b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWordsVSOpenXML.csproj index 3357e5d57..5246734e0 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWordsVSOpenXML.csproj +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/AsposeWordsVSOpenXML.csproj @@ -1,128 +1,32 @@ - - - + - Debug - AnyCPU - {5181D152-E178-4066-B8FC-A5E42B67C35A} + net8.0 Library - Properties - AsposeWordsVSOpenXML - AsposeWordsVSOpenXML - v4.6.2 - 512 - true - - + false + Aspose Words + Aspose Words + Copyright © 2021 + 1.0.0.0 + 1.0.0.0 - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - 21.1.1 + 25.1.0 - 21.2.0 + 25.2.0 - 2.12.3 + 3.2.0 - 3.13.1 + 3.14.0 - \ No newline at end of file diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Add table.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Add table.cs index 5c2f1eaf7..4d1bec83e 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Add table.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Add table.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; @@ -11,81 +16,80 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class AddTable : TestUtil { [Test] - public void AddTableFeature() + public void CreateTable() { - string[,] data = {{"Mike", "Amy"}, {"Mary", "Albert"}}; + string[,] data = { { "Mike", "Amy" }, { "Mary", "Albert" } }; - using (WordprocessingDocument wordDocument = - WordprocessingDocument.Create(ArtifactsDir + "Add Table - OpenXML.docx", - WordprocessingDocumentType.Document)) - { - MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); - mainPart.Document = new Document(); - - Body body = mainPart.Document.AppendChild(new Body()); - Paragraph para = body.AppendChild(new Paragraph()); + using WordprocessingDocument wordDocument = WordprocessingDocument.Create( + ArtifactsDir + "CreateTable - OpenXML.docx", + WordprocessingDocumentType.Document); - Run run = para.AppendChild(new Run()); - run.AppendChild(new Text("Create text in body - Create wordprocessing document")); + MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); - Table table = new Table(); + Body body = mainPart.Document.AppendChild(new Body()); + Paragraph para = body.AppendChild(new Paragraph()); - TableProperties props = new TableProperties( - new TableBorders( - new TopBorder - { - Val = new EnumValue(BorderValues.Single), - Size = 12 - }, - new BottomBorder - { - Val = new EnumValue(BorderValues.Single), - Size = 12 - }, - new LeftBorder - { - Val = new EnumValue(BorderValues.Single), - Size = 12 - }, - new RightBorder - { - Val = new EnumValue(BorderValues.Single), - Size = 12 - }, - new InsideHorizontalBorder - { - Val = new EnumValue(BorderValues.Single), - Size = 12 - }, - new InsideVerticalBorder - { - Val = new EnumValue(BorderValues.Single), - Size = 12 - })); + Run run = para.AppendChild(new Run()); + run.AppendChild(new Text("Create text in body - Create wordprocessing document")); - table.AppendChild(props); + Table table = new Table(); - for (var i = 0; i <= data.GetUpperBound(0); i++) - { - var tr = new TableRow(); - for (var j = 0; j <= data.GetUpperBound(1); j++) + TableProperties props = new TableProperties( + new TableBorders( + new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder { - var tc = new TableCell(); - tc.Append(new Paragraph(new Run(new Text(data[i, j])))); + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + })); + + table.AppendChild(props); - // Assume you want automatically sized columns. - tc.Append(new TableCellProperties( - new TableCellWidth {Type = TableWidthUnitValues.Auto})); + for (var i = 0; i <= data.GetUpperBound(0); i++) + { + var tr = new TableRow(); + for (var j = 0; j <= data.GetUpperBound(1); j++) + { + var tc = new TableCell(); + tc.Append(new Paragraph(new Run(new Text(data[i, j])))); - tr.Append(tc); - } + // Assume you want automatically sized columns. + tc.Append(new TableCellProperties( + new TableCellWidth { Type = TableWidthUnitValues.Auto })); - table.Append(tr); + tr.Append(tc); } - mainPart.Document.Body.Append(table); - mainPart.Document.Save(); + table.Append(tr); } + + mainPart.Document.Body.Append(table); + mainPart.Document.Save(); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Change or replace header and footer.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Change or replace header and footer.cs index d3a0a07f0..953c918dd 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Change or replace header and footer.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Change or replace header and footer.cs @@ -1,6 +1,12 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.Collections.Generic; +using System.Linq; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; @@ -12,120 +18,98 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class ChangeOrReplaceHeaderAndFooter : TestUtil { [Test] - public void ChangeOrReplaceHeaderAndFooterFeature() + public void CreateHeaderFooter() { - // Replace a header in the target document with a header from the source document. - using (WordprocessingDocument document = WordprocessingDocument.Create( - ArtifactsDir + "Change or replace header and footer - OpenXML.docx", - WordprocessingDocumentType.Document)) - { - MainDocumentPart mainDocumentPart = document.MainDocumentPart; + // Create a new Word document. + using WordprocessingDocument document = WordprocessingDocument.Create( + ArtifactsDir + "Create header footer - OpenXML.docx", + WordprocessingDocumentType.Document); - mainDocumentPart.DeleteParts(mainDocumentPart.HeaderParts); - mainDocumentPart.DeleteParts(mainDocumentPart.FooterParts); + // Add a main document part. + MainDocumentPart mainDocumentPart = document.AddMainDocumentPart(); + mainDocumentPart.Document = new Document(new Body()); - HeaderPart headerPart = mainDocumentPart.AddNewPart(); - FooterPart footerPart = mainDocumentPart.AddNewPart(); + // Delete existing header and footer parts (if any). + mainDocumentPart.DeleteParts(mainDocumentPart.HeaderParts); + mainDocumentPart.DeleteParts(mainDocumentPart.FooterParts); - string headerPartId = mainDocumentPart.GetIdOfPart(headerPart); - string footerPartId = mainDocumentPart.GetIdOfPart(footerPart); + // Add new header and footer parts. + HeaderPart headerPart = mainDocumentPart.AddNewPart(); + FooterPart footerPart = mainDocumentPart.AddNewPart(); - GenerateHeaderPartContent(headerPart); + string headerPartId = mainDocumentPart.GetIdOfPart(headerPart); + string footerPartId = mainDocumentPart.GetIdOfPart(footerPart); - GenerateFooterPartContent(footerPart); + // Generate content for the header and footer. + GenerateHeaderPartContent(headerPart); + GenerateFooterPartContent(footerPart); - // Give the HeaderReference and FooterReference of each section property the new Id. - IEnumerable sections = mainDocumentPart.Document.Body.Elements(); + // Ensure the document has at least one section. + if (mainDocumentPart.Document.Body.Elements().Count() == 0) + { + mainDocumentPart.Document.Body.AppendChild(new SectionProperties()); + } - foreach (var section in sections) - { - section.RemoveAllChildren(); - section.RemoveAllChildren(); + // Assign the header and footer to all sections. + IEnumerable sections = mainDocumentPart.Document.Body.Elements(); + + foreach (var section in sections) + { + section.RemoveAllChildren(); + section.RemoveAllChildren(); - section.PrependChild(new HeaderReference {Id = headerPartId}); - section.PrependChild(new FooterReference {Id = footerPartId}); - } + section.PrependChild(new HeaderReference { Id = headerPartId }); + section.PrependChild(new FooterReference { Id = footerPartId }); } + + // Save the document. + mainDocumentPart.Document.Save(); } private void GenerateHeaderPartContent(HeaderPart part) { - Header header1 = new Header() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 wp14" } }; - header1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"); - header1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); - header1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office"); - header1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); - header1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math"); - header1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml"); - header1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"); - header1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"); - header1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word"); - header1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"); - header1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml"); - header1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"); - header1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk"); - header1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml"); - header1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape"); - - Paragraph paragraph1 = new Paragraph { RsidParagraphAddition = "00164C17", RsidRunAdditionDefault = "00164C17" }; - - ParagraphProperties paragraphProperties1 = new ParagraphProperties(); - ParagraphStyleId paragraphStyleId1 = new ParagraphStyleId() { Val = "Header" }; - - paragraphProperties1.Append(paragraphStyleId1); - - Run run1 = new Run(); - Text text1 = new Text(); - text1.Text = "Header"; - - run1.Append(text1); - - paragraph1.Append(paragraphProperties1); - paragraph1.Append(run1); - - header1.Append(paragraph1); - - part.Header = header1; + Header header = new Header(); + + Paragraph paragraph = new Paragraph { RsidParagraphAddition = "00164C17", RsidRunAdditionDefault = "00164C17" }; + + ParagraphProperties paragraphProperties = new ParagraphProperties(); + ParagraphStyleId paragraphStyleId = new ParagraphStyleId { Val = "Header" }; + + paragraphProperties.Append(paragraphStyleId); + + Run run = new Run(); + Text text = new Text { Text = "Header" }; + + run.Append(text); + paragraph.Append(paragraphProperties); + paragraph.Append(run); + + header.Append(paragraph); + + part.Header = header; } private void GenerateFooterPartContent(FooterPart part) { - Footer footer1 = new Footer { MCAttributes = new MarkupCompatibilityAttributes { Ignorable = "w14 wp14" } }; - footer1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"); - footer1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); - footer1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office"); - footer1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); - footer1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math"); - footer1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml"); - footer1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"); - footer1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"); - footer1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word"); - footer1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"); - footer1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml"); - footer1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"); - footer1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk"); - footer1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml"); - footer1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape"); - - Paragraph paragraph1 = new Paragraph { RsidParagraphAddition = "00164C17", RsidRunAdditionDefault = "00164C17" }; - - ParagraphProperties paragraphProperties1 = new ParagraphProperties(); - ParagraphStyleId paragraphStyleId1 = new ParagraphStyleId { Val = "Footer" }; - - paragraphProperties1.Append(paragraphStyleId1); - - Run run1 = new Run(); - Text text1 = new Text(); - text1.Text = "Footer"; - - run1.Append(text1); - - paragraph1.Append(paragraphProperties1); - paragraph1.Append(run1); - - footer1.Append(paragraph1); - - part.Footer = footer1; + Footer footer = new Footer(); + + Paragraph paragraph = new Paragraph { RsidParagraphAddition = "00164C17", RsidRunAdditionDefault = "00164C17" }; + + ParagraphProperties paragraphProperties = new ParagraphProperties(); + ParagraphStyleId paragraphStyleId = new ParagraphStyleId { Val = "Footer" }; + + paragraphProperties.Append(paragraphStyleId); + + Run run = new Run(); + Text text = new Text { Text = "Footer" }; + + run.Append(text); + paragraph.Append(paragraphProperties); + paragraph.Append(run); + + footer.Append(paragraph); + + part.Footer = footer; } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Change text in a table.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Change text in a table.cs index 01b93f551..73c3a5057 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Change text in a table.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Change text in a table.cs @@ -1,6 +1,13 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// +using System; using System.Linq; +using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using NUnit.Framework; @@ -11,33 +18,49 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class ChangeTextInATable : TestUtil { [Test] - public void ChangeTextInATableFeature() + public void ReplaceText() { - // Use the file name and path passed in as an argument to - // open an existing document. - using (WordprocessingDocument doc = - WordprocessingDocument.Open(MyDir + "Change text in a table.docx", true)) - { - // Find the first table in the document. - Table table = - doc.MainDocumentPart.Document.Body.Elements().First(); + // Use the file name and path passed in as an argument to open an existing document. + using WordprocessingDocument doc = WordprocessingDocument.Open(MyDir + "Replace text.docx", true); + + // Get the main document part. + MainDocumentPart mainPart = doc.MainDocumentPart; + if (mainPart?.Document?.Body == null) + throw new InvalidOperationException("The document does not contain a valid body."); + + // Find the first table in the document. + Table table = mainPart.Document.Body.Elements
().FirstOrDefault(); + // Find the second row in the table. + TableRow row = table.Elements().ElementAtOrDefault(1); + // Find the third cell in the row. + TableCell cell = row.Elements().ElementAtOrDefault(2); + // Find the first paragraph in the table cell. + Paragraph paragraph = cell.Elements().FirstOrDefault(); + // Find the first run in the paragraph. + Run run = paragraph.Elements().FirstOrDefault(); - // Find the second row in the table. - TableRow row = table.Elements().ElementAt(1); + // Find the first text element in the run. + Text text = run.Elements().FirstOrDefault(); + if (text == null) + { + // If no text element exists, create one. + text = new Text(); + run.Append(text); + } - // Find the third cell in the row. - TableCell cell = row.Elements().ElementAt(2); + // Set the text for the run. + text.Text = "The text from the OpenXML API example"; - // Find the first paragraph in the table cell. - Paragraph p = cell.Elements().First(); + using WordprocessingDocument destinationDoc = WordprocessingDocument.Create( + ArtifactsDir + "Replace text - OpenXML.docx", + WordprocessingDocumentType.Document); - // Find the first run in the paragraph. - Run r = p.Elements().First(); + // Copy the content from the source document to the destination document. + destinationDoc.AddMainDocumentPart(); + destinationDoc.MainDocumentPart.Document = (Document)doc.MainDocumentPart.Document.CloneNode(true); - // Set the text for the run. - Text t = r.Elements().First(); - t.Text = "The text from the OpenXML API example"; - } + // Save the destination document. + destinationDoc.MainDocumentPart.Document.Save(); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Convert from docm to docx.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Convert from docm to docx.cs index c6b21f445..e8db9d951 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Convert from docm to docx.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Convert from docm to docx.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.IO; using DocumentFormat.OpenXml; @@ -11,41 +16,28 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class ConvertFromDocmToDocx : TestUtil { [Test] - public void ConvertFromDocmToDocxFeature() + public void DocmToDocxConversion() { - bool fileChanged = false; + string docmFilePath = MyDir + "Docm to Docx conversion.docm"; + string docxFilePath = ArtifactsDir + "Docm to Docx conversion - OpenXML.docx"; - using (WordprocessingDocument document = - WordprocessingDocument.Open(MyDir + "Convert from docm to docx.docm", true)) + using (WordprocessingDocument docm = WordprocessingDocument.Open(docmFilePath, false)) { - var docPart = document.MainDocumentPart; + // Create a copy of the .docm file as .docx. + File.Copy(docmFilePath, docxFilePath, true); - // Look for the vbaProject part. If it is there, delete it. - var vbaPart = docPart.VbaProjectPart; - if (vbaPart != null) + // Open the new .docx file and remove the macros. + using (WordprocessingDocument docx = WordprocessingDocument.Open(docxFilePath, true)) { - // Delete the vbaProject part and then save the document. - docPart.DeletePart(vbaPart); - docPart.Document.Save(); + // Remove the VBA project part (macros). + var vbaPart = docx.MainDocumentPart.VbaProjectPart; + if (vbaPart != null) + docx.MainDocumentPart.DeletePart(vbaPart); - // Change the document type to not macro-enabled. - document.ChangeDocumentType( - WordprocessingDocumentType.Document); - - fileChanged = true; + // Change the document type to .docx (no macros). + docx.ChangeDocumentType(WordprocessingDocumentType.Document); } } - - // If anything goes wrong in this file handling, - // the code will raise an exception back to the caller. - if (fileChanged) - { - if (File.Exists(ArtifactsDir + "Convert from docm to docx - OpenXML.docm")) - File.Delete(ArtifactsDir + "Convert from docm to docx - OpenXML.docm"); - - File.Move(MyDir + "Convert from docm to docx.docm", - ArtifactsDir + "Convert from docm to docx - OpenXML.docm"); - } } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Create a document.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Create a document.cs index 3bc687dcd..b95bb944b 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Create a document.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Create a document.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; @@ -11,21 +16,26 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class CreateADocument : TestUtil { [Test] - public void CreateADocumentFeature() + public void CreateNewDocument() { - using (WordprocessingDocument wordDocument = - WordprocessingDocument.Create(ArtifactsDir + "Create a document - OpenXML.docx", - WordprocessingDocumentType.Document)) + // Create a Wordprocessing document. + using (WordprocessingDocument wordDocument = WordprocessingDocument.Create( + ArtifactsDir + "Create new document - OpenXML.docx", + WordprocessingDocumentType.Document)) { + // Add a main document part. MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); + // Create the document structure and add some text. mainPart.Document = new Document(); - - Body body = mainPart.Document.AppendChild(new Body()); - Paragraph para = body.AppendChild(new Paragraph()); - - Run run = para.AppendChild(new Run()); - run.AppendChild(new Text("Create text in body - Create wordprocessing document")); + Body body = new Body(); + Paragraph paragraph = new Paragraph(); + Run run = new Run(); + run.Append(new Text("Hello, Open XML!")); + paragraph.Append(run); + body.Append(paragraph); + mainPart.Document.Append(body); + mainPart.Document.Save(); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Create and add a paragraph style.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Create and add a paragraph style.cs index b315215be..2f8089070 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Create and add a paragraph style.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Create and add a paragraph style.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.Linq; using DocumentFormat.OpenXml; @@ -12,134 +17,61 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class CreateAndAddAParagraphStyle : TestUtil { [Test] - public void CreateAndAddAParagraphStyleFeature() + public void ParagraphCustomStyle() { - using (WordprocessingDocument doc = - WordprocessingDocument.Create(ArtifactsDir + "Create and add a paragraph style - OpenXML.docx", - WordprocessingDocumentType.Document)) + // Create a Wordprocessing document. + using (WordprocessingDocument wordDocument = WordprocessingDocument.Create( + ArtifactsDir + "Paragraph custom style - OpenXML.docx", + WordprocessingDocumentType.Document)) { - // Get the Styles part for this document. - // If the Styles part does not exist: add the styles part, and then add the style. - StyleDefinitionsPart part = - doc.MainDocumentPart.StyleDefinitionsPart ?? AddStylesPartToPackage(doc); + // Add a main document part. + MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); - // Set up a variable to hold the style ID. - string parastyleId = "OverdueAmountPara"; + // Create the document structure and add some text. + mainPart.Document = new Document(); + Body body = new Body(); - // Create and add a paragraph style to the specified styles part - // with the specified style ID, style name, and aliases. - AddParagraphStyle(part, - parastyleId, - "Overdue Amount Para", - "Late Due, Late Amount"); + // Create a custom paragraph style. + StyleDefinitionsPart stylePart = mainPart.AddNewPart(); + Styles styles = new Styles(); - // Add a paragraph with a run and some text. - Paragraph p = - new Paragraph( - new Run( - new Text("This is some text in a run in a paragraph."))); - - // Add the paragraph as a child element of the w:body element. - doc.MainDocumentPart.Document.Body.AppendChild(p); - - // If the paragraph has no ParagraphProperties object, then create one. - if (!p.Elements().Any()) + // Define a new paragraph style. + Style paragraphStyle = new Style() { - p.PrependChild(new ParagraphProperties()); - } - - // Get a reference to the ParagraphProperties object. - ParagraphProperties pPr = p.ParagraphProperties; - - // If a ParagraphStyleId object doesn't exist, then create one. - if (pPr.ParagraphStyleId == null) - pPr.ParagraphStyleId = new ParagraphStyleId(); - - pPr.ParagraphStyleId.Val = parastyleId; - } - } - - // Create a new paragraph style with the specified style ID, primary style name, and aliases. - // Add it to the specified style definitions part. - public static void AddParagraphStyle(StyleDefinitionsPart styleDefinitionsPart, - string styleid, string stylename, string aliases = "") - { - // Access the root element of the styles part. - Styles styles = styleDefinitionsPart.Styles; - if (styles == null) - { - styleDefinitionsPart.Styles = new Styles(); - styleDefinitionsPart.Styles.Save(); + Type = StyleValues.Paragraph, + StyleId = "CustomStyle", + CustomStyle = true, + StyleName = new StyleName() { Val = "Custom Style" }, + BasedOn = new BasedOn() { Val = "Normal" }, + }; + + styles.Append(paragraphStyle); + stylePart.Styles = styles; + stylePart.Styles.Save(); + + // Create a new paragraph with the custom style. + Paragraph paragraph = new Paragraph() + { + ParagraphProperties = new ParagraphProperties() + { + ParagraphStyleId = new ParagraphStyleId() { Val = "CustomStyle" }, + Justification = new Justification() { Val = JustificationValues.Center }, + SpacingBetweenLines = new SpacingBetweenLines() { After = "200" } + } + }; + Run run = new Run(); + + // Set bold text. + RunProperties runProperties = new RunProperties(); + runProperties.Append(new Bold()); + run.Append(runProperties); + run.Append(new Text("This is a bold paragraph with a custom style!")); + paragraph.Append(run); + body.Append(paragraph); + + mainPart.Document.Append(body); + mainPart.Document.Save(); } - - // Create a new paragraph style element and specify some of the attributes. - Style style = new Style - { - Type = StyleValues.Paragraph, - StyleId = styleid, - CustomStyle = true, - Default = false - }; - - // Create and add the child elements (properties of the style). - Aliases aliases1 = new Aliases { Val = aliases }; - AutoRedefine autoredefine1 = new AutoRedefine { Val = OnOffOnlyValues.Off }; - BasedOn basedon1 = new BasedOn { Val = "Normal" }; - LinkedStyle linkedStyle1 = new LinkedStyle { Val = "OverdueAmountChar" }; - Locked locked1 = new Locked { Val = OnOffOnlyValues.Off }; - PrimaryStyle primarystyle1 = new PrimaryStyle { Val = OnOffOnlyValues.On }; - StyleHidden stylehidden1 = new StyleHidden { Val = OnOffOnlyValues.Off }; - SemiHidden semihidden1 = new SemiHidden { Val = OnOffOnlyValues.Off }; - StyleName styleName1 = new StyleName { Val = stylename }; - NextParagraphStyle nextParagraphStyle1 = new NextParagraphStyle { Val = "Normal" }; - UIPriority uipriority1 = new UIPriority { Val = 1 }; - UnhideWhenUsed unhidewhenused1 = new UnhideWhenUsed { Val = OnOffOnlyValues.On }; - - if (aliases != "") - style.Append(aliases1); - style.Append(autoredefine1); - style.Append(basedon1); - style.Append(linkedStyle1); - style.Append(locked1); - style.Append(primarystyle1); - style.Append(stylehidden1); - style.Append(semihidden1); - style.Append(styleName1); - style.Append(nextParagraphStyle1); - style.Append(uipriority1); - style.Append(unhidewhenused1); - - // Create the StyleRunProperties object and specify some of the run properties. - StyleRunProperties styleRunProperties1 = new StyleRunProperties(); - Bold bold1 = new Bold(); - Color color1 = new Color { ThemeColor = ThemeColorValues.Accent2 }; - RunFonts font1 = new RunFonts { Ascii = "Lucida Console" }; - Italic italic1 = new Italic(); - - // Specify a 12 point size. - FontSize fontSize1 = new FontSize { Val = "24" }; - styleRunProperties1.Append(bold1); - styleRunProperties1.Append(color1); - styleRunProperties1.Append(font1); - styleRunProperties1.Append(fontSize1); - styleRunProperties1.Append(italic1); - - // Add the run properties to the style. - style.Append(styleRunProperties1); - - // Add the style to the styles part. - styles.Append(style); - } - - // Add a StylesDefinitionsPart to the document. - public static StyleDefinitionsPart AddStylesPartToPackage(WordprocessingDocument doc) - { - Styles root = new Styles(); - - var part = doc.MainDocumentPart.AddNewPart(); - root.Save(part); - - return part; } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Extract image from word document.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Extract image from word document.cs index 1b074d129..9fd486778 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Extract image from word document.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Extract image from word document.cs @@ -1,36 +1,65 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +//// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +//// +//// This file is part of Aspose.Words. The source code in this file +//// is only intended as a supplement to the documentation, and is provided +//// "as is", without warranty of any kind, either expressed or implied. +//////////////////////////////////////////////////////////////////////////// -using System.Collections.Generic; -using System.Drawing; -using System.Linq; +using System; +using System.IO; using DocumentFormat.OpenXml.Packaging; using NUnit.Framework; namespace AsposeWordsVSOpenXML.OpenXML_features { [TestFixture] - public class ExtractImageFromWordDocument : TestUtil + public class ExtractImage : TestUtil { [Test] public void ExtractImageFromWordDocumentFeature() { - using (WordprocessingDocument doc = WordprocessingDocument.Open(MyDir + "Extract image.docx", false)) + // Open the Wordprocessing document. + using (WordprocessingDocument wordDocument = WordprocessingDocument.Open(MyDir + "Extract image.docx", false)) { - int imgCount = doc.MainDocumentPart.GetPartsOfType().Count(); + MainDocumentPart mainPart = wordDocument.MainDocumentPart; - if (imgCount > 0) + // Loop through each ImagePart in the document. + int imageIndex = 0; + foreach (var imagePart in mainPart.ImageParts) { - List imgParts = new List(doc.MainDocumentPart.ImageParts); - - foreach (ImagePart imgPart in imgParts) + // Get the image extension. + string imageExtension = GetImageExtension(imagePart.ContentType); + if (imageExtension != null) { - Image img = Image.FromStream(imgPart.GetStream()); - string imgfileName = imgPart.Uri.OriginalString.Substring(imgPart.Uri.OriginalString.LastIndexOf("/") + 1); + // Create a file name for the image. + string imageFileName = Path.Combine(ArtifactsDir, $"ExtractImage.{imageIndex}.OpenXML{imageExtension}"); + + // Save the image to the output directory. + using (var stream = imagePart.GetStream()) + using (var fileStream = new FileStream(imageFileName, FileMode.Create, FileAccess.Write)) + stream.CopyTo(fileStream); - img.Save(ArtifactsDir + imgfileName); + imageIndex++; } } } } + + static string GetImageExtension(string contentType) + { + switch (contentType) + { + case "image/jpeg": + return ".jpg"; + case "image/png": + return ".png"; + case "image/gif": + return ".gif"; + case "image/bmp": + return ".bmp"; + default: + return null; // Unsupported image type. + } + } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Get and set bookmark text.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Get and set bookmark text.cs index 1824b9f3d..c75ef2796 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Get and set bookmark text.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Get and set bookmark text.cs @@ -1,6 +1,13 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// -using System.Collections.Generic; +using System; +using System.Linq; +using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using NUnit.Framework; @@ -11,23 +18,38 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class GetAndSetBookmarkText : TestUtil { [Test] - public void GetAndSetBookmarkTextFeature() + public void BookmarkText() { - IDictionary bookmarkMap = new Dictionary(); - - using (WordprocessingDocument wordDocument = WordprocessingDocument.Open(MyDir + "Get and set bookmark text.docx", true)) + // Open the original Wordprocessing document. + using (WordprocessingDocument originalDocument = WordprocessingDocument.Open(MyDir + "Bookmark.docx", false)) { - foreach (BookmarkStart bookmarkStart in wordDocument.MainDocumentPart.Document.Body.Descendants()) + // Create a new Wordprocessing document. + using (WordprocessingDocument newDocument = WordprocessingDocument.Create(ArtifactsDir + "Bookmark text - OpenXML.docx", WordprocessingDocumentType.Document)) { - bookmarkMap[bookmarkStart.Name] = bookmarkStart; + // Add a main document part to the new document. + MainDocumentPart newMainPart = newDocument.AddMainDocumentPart(); + newMainPart.Document = new Document(new Body()); + + // Copy content from the original document to the new document. + MainDocumentPart originalMainPart = originalDocument.MainDocumentPart; + newMainPart.Document.Body = (Body)originalMainPart.Document.Body.Clone(); + + // Find the bookmark in the new document + var bookmark = newMainPart.Document.Descendants() + .FirstOrDefault(b => b.Name == "MyBookmark"); + + // Get the parent element of the bookmark + var parentElement = bookmark.Parent; + + // Create a new run with the new text + Run newRun = new Run(new Text("This is a new bookmarked text.")); - foreach (BookmarkStart bookmark in bookmarkMap.Values) - { - Run bookmarkText = bookmark.NextSibling(); + // Replace the bookmark with the new text + parentElement.RemoveAllChildren(); // Remove existing content + parentElement.Append(newRun); // Add new text - if (bookmarkText != null) - bookmarkText.GetFirstChild().Text = "Test"; - } + // Save changes to the new document + newMainPart.Document.Save(); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Insert a comment.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Insert a comment.cs index 303e548df..c950db082 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Insert a comment.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Insert a comment.cs @@ -1,7 +1,11 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System; -using System.Linq; using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; @@ -13,60 +17,55 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class InsertAComment : TestUtil { [Test] - public void InsertACommentFeature() + public void InsertComment() { - using (WordprocessingDocument document = - WordprocessingDocument.Create(ArtifactsDir + "Insert a comment - OpenXML.docx", - WordprocessingDocumentType.Document)) + using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(ArtifactsDir + "Insert a comment - OpenXML.docx", WordprocessingDocumentType.Document)) { - // Locate the first paragraph in the document. - Paragraph firstParagraph = - document.MainDocumentPart.Document.Descendants().First(); - Comments comments; - string id = "0"; + // Add the main document part. + MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + Body body = new Body(); - // Verify that the document contains a - // WordProcessingCommentsPart part; if not, add a new one. - if (document.MainDocumentPart.GetPartsOfType().Any()) - { - comments = - document.MainDocumentPart.WordprocessingCommentsPart.Comments; - if (comments.HasChildren) - // Obtain an unused ID. - id = comments.Descendants().Select(e => e.Id.Value).Max(); - } - else - { - // No "WordprocessingCommentsPart" part exists, so add one to the package. - WordprocessingCommentsPart commentPart = - document.MainDocumentPart.AddNewPart(); - commentPart.Comments = new Comments(); - comments = commentPart.Comments; - } + // Add a paragraph with some text. + Paragraph paragraph = new Paragraph(); + Run run = new Run(); + run.AppendChild(new Text("Commented text.")); + paragraph.AppendChild(run); + body.AppendChild(paragraph); + + // Add a comments part to the document. + WordprocessingCommentsPart commentsPart = mainPart.AddNewPart(); + commentsPart.Comments = new Comments(); - // Compose a new Comment and add it to the Comments part. - Paragraph p = new Paragraph(new Run(new Text("This is my comment."))); - Comment cmt = new Comment + // Create a comment. + Comment comment = new Comment() { - Id = id, - Author = "author", - Initials = "initials", + Id = "1", + Author = "Aspose.Words", Date = DateTime.Now }; - cmt.AppendChild(p); - comments.AppendChild(cmt); - comments.Save(); - // Specify the text range for the Comment. - // Insert the new CommentRangeStart before the first run of paragraph. - firstParagraph.InsertBefore(new CommentRangeStart {Id = id}, firstParagraph.GetFirstChild()); + // Add text to the comment. + Paragraph commentParagraph = new Paragraph(); + Run commentRun = new Run(); + commentRun.AppendChild(new Text("Comment regarding text.")); + commentParagraph.AppendChild(commentRun); + comment.AppendChild(commentParagraph); + + // Add the comment to the comments part. + commentsPart.Comments.AppendChild(comment); + commentsPart.Comments.Save(); + + // Add a reference to the comment in the document. + run.AppendChild(new CommentRangeStart { Id = "1" }); + run.AppendChild(new CommentRangeEnd { Id = "1" }); + run.AppendChild(new CommentReference { Id = "1" }); - // Insert the new CommentRangeEnd after last run of paragraph. - var cmtEnd = firstParagraph.InsertAfter(new CommentRangeEnd {Id = id}, - firstParagraph.Elements().Last()); + // Add the body to the document. + mainPart.Document.AppendChild(body); - // Compose a run with CommentReference and insert it. - firstParagraph.InsertAfter(new Run(new CommentReference {Id = id}), cmtEnd); + // Save the document. + mainPart.Document.Save(); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Insert picture in word document.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Insert picture in word document.cs index a8443c5d7..ac6833617 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Insert picture in word document.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Insert picture in word document.cs @@ -1,11 +1,16 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.IO; using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Drawing; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using NUnit.Framework; -using A = DocumentFormat.OpenXml.Drawing; using DW = DocumentFormat.OpenXml.Drawing.Wordprocessing; using Paragraph = DocumentFormat.OpenXml.Wordprocessing.Paragraph; using PIC = DocumentFormat.OpenXml.Drawing.Pictures; @@ -17,91 +22,117 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class InsertPictureInWordDocument : TestUtil { [Test] - public static void InsertPictureInWordDocumentFeature() + public static void InsertPicture() { - using (WordprocessingDocument wordprocessingDocument = - WordprocessingDocument.Create(ArtifactsDir + "Insert picture - OpenXML.docx", - WordprocessingDocumentType.Document)) + using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(ArtifactsDir + "Insert picture - OpenXML.docx", WordprocessingDocumentType.Document)) { - MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart; + // Add the main document part + MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + Body body = new Body(); - ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); + // Add a paragraph to the document + Paragraph paragraph = new Paragraph(); + Run run = new Run(); + // Add the image to the document + ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); using (FileStream stream = new FileStream(MyDir + "Aspose.Words.png", FileMode.Open)) { imagePart.FeedData(stream); } - AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart)); - } - } + // Generate a unique relationship ID for the image + string imageId = mainPart.GetIdOfPart(imagePart); - private static void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId) - { - // Define the reference of the image. - var element = - new Drawing( - new DW.Inline( - new DW.Extent { Cx = 990000L, Cy = 792000L }, - new DW.EffectExtent - { - LeftEdge = 0L, - TopEdge = 0L, - RightEdge = 0L, - BottomEdge = 0L - }, - new DW.DocProperties - { - Id = 1U, - Name = "Picture 1" - }, - new DW.NonVisualGraphicFrameDrawingProperties( - new A.GraphicFrameLocks { NoChangeAspect = true }), - new A.Graphic( - new A.GraphicData( - new PIC.Picture( - new PIC.NonVisualPictureProperties( - new PIC.NonVisualDrawingProperties - { - Id = 0U, - Name = "New Bitmap Image.jpg" - }, - new PIC.NonVisualPictureDrawingProperties()), - new PIC.BlipFill( - new A.Blip( - new A.BlipExtensionList( - new A.BlipExtension - { - Uri = - "{28A0092B-C50C-407E-A947-70E740481C1C}" - }) - ) - { - Embed = relationshipId, - CompressionState = - A.BlipCompressionValues.Print - }, - new A.Stretch( - new A.FillRectangle())), - new PIC.ShapeProperties( - new A.Transform2D( - new A.Offset { X = 0L, Y = 0L }, - new A.Extents { Cx = 990000L, Cy = 792000L }), - new A.PresetGeometry( - new A.AdjustValueList() - ) { Preset = A.ShapeTypeValues.Rectangle })) - ) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }) - ) - { - DistanceFromTop = 0U, - DistanceFromBottom = 0U, - DistanceFromLeft = 0U, - DistanceFromRight = 0U, - EditId = "50D07946" - }); + // Define the image's dimensions (width and height in pixels) + const int emuPerPixel = 9525; + int widthInPixels = 300; + int heightInPixels = 200; - // Append the reference to body, the element should be in a Run. - wordDoc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(new Run(element))); + // Add the image to the run + run.AppendChild(new Drawing( + new DW.Inline( + new DW.Extent() + { + Cx = widthInPixels * emuPerPixel, + Cy = heightInPixels * emuPerPixel + }, + new DW.DocProperties() + { + Id = 1, + Name = "Picture 1" + }, + new DW.NonVisualGraphicFrameDrawingProperties(), + new Graphic( + new GraphicData( + new PIC.Picture( + new PIC.NonVisualPictureProperties( + new PIC.NonVisualDrawingProperties() + { + Id = 0, + Name = "Image" + }, + new PIC.NonVisualPictureDrawingProperties() + ), + new PIC.BlipFill( + new Blip() + { + Embed = imageId, + CompressionState = BlipCompressionValues.Print + }, + new Stretch( + new FillRectangle() + ) + ), + new PIC.ShapeProperties( + new Transform2D( + new Offset() + { + X = 0, + Y = 0 + }, + new Extents() + { + Cx = widthInPixels * emuPerPixel, + Cy = heightInPixels * emuPerPixel + } + ), + new PresetGeometry( + new AdjustValueList() + ) + { + Preset = ShapeTypeValues.Rectangle + } + ) + ) + ) + { + Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" + } + ) + ) + { + DistanceFromTop = 0, + DistanceFromBottom = 0, + DistanceFromLeft = 0, + DistanceFromRight = 0, + EditId = "50D07946" + } + )); + + // Add the run to the paragraph + paragraph.AppendChild(run); + + // Add the paragraph to the body + body.AppendChild(paragraph); + + // Add the body to the document + mainPart.Document.AppendChild(body); + + // Save the document + mainPart.Document.Save(); + } } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Open and add text to word document.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Open and add text to word document.cs index d7080ba4d..7df1aab91 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Open and add text to word document.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Open and add text to word document.cs @@ -1,5 +1,11 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// +using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using NUnit.Framework; @@ -10,19 +16,36 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class OpenAndAddTextToWordDocument : TestUtil { [Test] - public void OpenAndAddTextToWordDocumentFeature() + public void AddText() { - // Open a WordprocessingDocument for editing using the filepath. - using (WordprocessingDocument wordprocessingDocument = - WordprocessingDocument.Open(MyDir + "Document.docx", true)) + using (WordprocessingDocument originalDocument = WordprocessingDocument.Open(MyDir + "Document.docx", false)) { - // Assign a reference to the existing document body. - Body body = wordprocessingDocument.MainDocumentPart.Document.Body; + // Create a new Wordprocessing document. + using (WordprocessingDocument newDocument = WordprocessingDocument.Create(ArtifactsDir + "Add text - OpenXML.docx", WordprocessingDocumentType.Document)) + { + // Add a main document part to the new document. + MainDocumentPart newMainPart = newDocument.AddMainDocumentPart(); + newMainPart.Document = new Document(new Body()); - // Add new text. - Paragraph para = body.AppendChild(new Paragraph()); - Run run = para.AppendChild(new Run()); - run.AppendChild(new Text("Append text in body - Open and add text to word document")); + // Copy content from the original document to the new document. + MainDocumentPart originalMainPart = originalDocument.MainDocumentPart; + newMainPart.Document.Body = (Body)originalMainPart.Document.Body.Clone(); + + Body body = newMainPart.Document.Body; + + // Create a new paragraph with the text you want to add + Paragraph newParagraph = new Paragraph(); + Run newRun = new Run(); + Text newText = new Text("This is the text added to the end of the document."); + newRun.Append(newText); + newParagraph.Append(newRun); + + // Append the new paragraph to the body + body.Append(newParagraph); + + // Save the changes + newMainPart.Document.Save(); + } } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Open document from stream.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Open document from stream.cs index 663bc480c..ec553c9f4 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Open document from stream.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Open document from stream.cs @@ -1,6 +1,12 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.IO; +using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using NUnit.Framework; @@ -11,17 +17,41 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class OpenDocumentFromStream : TestUtil { [Test] - public void OpenDocumentFromStreamFeature() + public void AddTextStream() { - using (Stream stream = File.Open(MyDir + "Document.docx", FileMode.Open)) + using (Stream inStream = File.Open(MyDir + "Document.docx", FileMode.Open)) { - using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(stream, true)) + using (WordprocessingDocument originalDocument = WordprocessingDocument.Open(inStream, false)) { - Body body = wordprocessingDocument.MainDocumentPart.Document.Body; - Paragraph para = body.AppendChild(new Paragraph()); + using (Stream outStream = File.Create(ArtifactsDir + "Add text stream - OpenXML.docx")) + { + // Create a new Wordprocessing document. + using (WordprocessingDocument newDocument = WordprocessingDocument.Create(outStream, WordprocessingDocumentType.Document)) + { + // Add a main document part to the new document. + MainDocumentPart newMainPart = newDocument.AddMainDocumentPart(); + newMainPart.Document = new Document(new Body()); - Run run = para.AppendChild(new Run()); - run.AppendChild(new Text("Append text in body - Open and add to wordprocessing stream")); + // Copy content from the original document to the new document. + MainDocumentPart originalMainPart = originalDocument.MainDocumentPart; + newMainPart.Document.Body = (Body)originalMainPart.Document.Body.Clone(); + + Body body = newMainPart.Document.Body; + + // Create a new paragraph with the text you want to add + Paragraph newParagraph = new Paragraph(); + Run newRun = new Run(); + Text newText = new Text("This is the text added to the end of the document."); + newRun.Append(newText); + newParagraph.Append(newRun); + + // Append the new paragraph to the body + body.Append(newParagraph); + + // Save the changes + newMainPart.Document.Save(); + } + } } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Open read only access.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Open read only access.cs index a0657d1d3..abde340ab 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Open read only access.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Open read only access.cs @@ -11,7 +11,7 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class OpenReadOnlyAccess : TestUtil { [Test] - public void OpenReadOnlyAccessFeature() + public void OpenReadOnly() { // Open a WordprocessingDocument based on a filepath. using (WordprocessingDocument wordDocument = @@ -23,7 +23,7 @@ public void OpenReadOnlyAccessFeature() // Attempt to add some text. Paragraph para = body.AppendChild(new Paragraph()); Run run = para.AppendChild(new Run()); - run.AppendChild(new Text("Append text in body, but text is not saved - Open wordprocessing document readonly")); + run.AppendChild(new Text("This is the text added to the end of the document.")); // Call the "Save" method to generate an exception and show that access is read-only. using (Stream stream = File.Create(ArtifactsDir + "Open readonly access - OpenXML.docx")) diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove comments.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove comments.cs index b623b1e88..22c5416e1 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove comments.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove comments.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System; using System.Collections.Generic; @@ -14,72 +19,60 @@ namespace AsposeWordsVSOpenXML.OpenXML_features public class DeleteCommentsByAllOrASpecificAuthor : TestUtil { [Test] - public void DeleteCommentsByAllOrASpecificAuthorFeature() + public void RemoveComments() { - RemoveComments(""); - } + string authorName = string.Empty; - private void RemoveComments(string author) - { - // Get an existing Wordprocessing document. - using (WordprocessingDocument document = - WordprocessingDocument.Open(MyDir + "Comments.docx", true)) + File.Copy(MyDir + "Comments.docx", ArtifactsDir + "Remove comments - OpenXML.docx", true); + using (WordprocessingDocument doc = WordprocessingDocument.Open(ArtifactsDir + "Remove comments - OpenXML.docx", true)) { - WordprocessingCommentsPart commentPart = - document.MainDocumentPart.WordprocessingCommentsPart; - - // If no "WordprocessingCommentsPart" exists, there can be no comments. - // Stop execution and return from the method. - if (commentPart == null) - return; - - // Create a list of comments by the specified author. - // If the author name is empty, then list all authors. - List commentsToDelete = - commentPart.Comments.Elements().ToList(); - - if (!String.IsNullOrEmpty(author)) + // Add a main document part to the new document. + MainDocumentPart mainPart = doc.MainDocumentPart; + + // Get the comments part + var commentsPart = mainPart.WordprocessingCommentsPart; + if (commentsPart != null) { - commentsToDelete = commentsToDelete.Where(c => c.Author == author).ToList(); - } - - IEnumerable commentIds = - commentsToDelete.Select(r => r.Id.Value); + // Get the comments + var comments = commentsPart.Comments; + // Create a list to hold comments to remove + var commentsToRemove = new List(); - foreach (Comment c in commentsToDelete) - c.Remove(); + foreach (var comment in comments.Elements()) + if (string.IsNullOrEmpty(authorName) || comment.Author == authorName) + commentsToRemove.Add(comment); - // Save changes to the comments part. - commentPart.Comments.Save(); + IEnumerable commentIds = + commentsToRemove.Select(r => r.Id.Value); - Document doc = document.MainDocumentPart.Document; + // Remove the comments + foreach (var comment in commentsToRemove) + comment.Remove(); - // Delete the "CommentRangeStart" for each deleted comment in the main document. - List commentRangeStartToDelete = - doc.Descendants().Where(c => commentIds.Contains(c.Id.Value)).ToList(); + // Save changes to the comments part + commentsPart.Comments.Save(); - foreach (CommentRangeStart c in commentRangeStartToDelete) - c.Remove(); + // Delete the "CommentRangeStart" for each deleted comment in the main document. + List commentRangeStartToDelete = + mainPart.Document.Descendants().Where(c => commentIds.Contains(c.Id.Value)).ToList(); - // Delete the "CommentRangeEnd" for each deleted comment in the main document. - List commentRangeEndToDelete = - doc.Descendants().Where(c => commentIds.Contains(c.Id.Value)).ToList(); + foreach (CommentRangeStart rangeStart in commentRangeStartToDelete) + rangeStart.Remove(); - foreach (CommentRangeEnd c in commentRangeEndToDelete) - c.Remove(); + // Delete the "CommentRangeEnd" for each deleted comment in the main document. + List commentRangeEndToDelete = + mainPart.Document.Descendants().Where(c => commentIds.Contains(c.Id.Value)).ToList(); - // Delete the "CommentReference" for each deleted comment in the main document. - List commentRangeReferenceToDelete = - doc.Descendants().Where(c => commentIds.Contains(c.Id.Value)).ToList(); + foreach (CommentRangeEnd rangeEnd in commentRangeEndToDelete) + rangeEnd.Remove(); - foreach (CommentReference c in commentRangeReferenceToDelete) - c.Remove(); + // Delete the "CommentReference" for each deleted comment in the main document. + List commentRangeReferenceToDelete = + mainPart.Document.Descendants().Where(c => commentIds.Contains(c.Id.Value)).ToList(); - using (Stream stream = File.Open(ArtifactsDir + "Remove comments - OpenXML.docx", FileMode.CreateNew)) - { - doc.Save(stream); + foreach (CommentReference reference in commentRangeReferenceToDelete) + reference.Remove(); } - } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove header footer.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove header footer.cs index 6dc90f5a5..dd63c63b1 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove header footer.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove header footer.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.IO; using System.Linq; @@ -14,7 +19,8 @@ public class RemoveHeaderFooter : TestUtil [Test] public void RemoveHeaderFooterFeature() { - using (WordprocessingDocument doc = WordprocessingDocument.Open(MyDir + "Document.docx", true)) + File.Copy(MyDir + "Document.docx", ArtifactsDir + "Remove header and footer - OpenXML.docx", true); + using (WordprocessingDocument doc = WordprocessingDocument.Open(ArtifactsDir + "Remove header and footer - OpenXML.docx", true)) { var mainDocumentPart = doc.MainDocumentPart; @@ -28,26 +34,17 @@ public void RemoveHeaderFooterFeature() // Get a reference to the root element of the main document part. Document document = mainDocumentPart.Document; - // Remove all references to the headers and footers. - // First, create a list of all descendants of type HeaderReference. // Then, navigate the list and call remove on each item to delete the reference. var headers = document.Descendants().ToList(); - foreach (var header in headers) header.Remove(); // First, create a list of all descendants of type FooterReference. // Then, navigate the list and call remove on each item to delete the reference. var footers = document.Descendants().ToList(); - foreach (var footer in footers) footer.Remove(); - - using (Stream stream = File.Create(ArtifactsDir + "Remove header and footer - OpenXML.docx")) - { - document.Save(stream); - } } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove hidden text.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove hidden text.cs index 3292f3069..4f708d6da 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove hidden text.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove hidden text.cs @@ -1,8 +1,14 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.IO; -using System.Xml; +using System.Linq; using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; using NUnit.Framework; namespace AsposeWordsVSOpenXML.OpenXML_features @@ -13,35 +19,24 @@ public class RemoveHiddenText : TestUtil [Test] public void RemoveHiddenTextFeature() { - const string wordmlNamespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"; + File.Copy(MyDir + "Remove hidden text.docx", ArtifactsDir + "Remove hidden text - OpenXML.docx", true); - using (WordprocessingDocument wdDoc = WordprocessingDocument.Open(MyDir + "Remove hidden text.docx", true)) + using WordprocessingDocument doc = WordprocessingDocument.Open(ArtifactsDir + "Remove hidden text - OpenXML.docx", true); + foreach (var paragraph in doc.MainDocumentPart.Document.Body.Elements()) { - // Manage namespaces to perform XPath queries. - NameTable nt = new NameTable(); - XmlNamespaceManager nsManager = new XmlNamespaceManager(nt); - nsManager.AddNamespace("w", wordmlNamespace); - - // Get the document part from the package. - // Load the XML in the document part into an XmlDocument instance. - XmlDocument xdoc = new XmlDocument(nt); - xdoc.Load(wdDoc.MainDocumentPart.GetStream()); - - XmlNodeList hiddenNodes = xdoc.SelectNodes("//w:vanish", nsManager); - - foreach (XmlNode hiddenNode in hiddenNodes) - { - XmlNode topNode = hiddenNode.ParentNode.ParentNode; - XmlNode topParentNode = topNode.ParentNode; - - topParentNode.RemoveChild(topNode); - if (!(topParentNode.HasChildNodes)) - topParentNode.ParentNode.RemoveChild(topParentNode); - } - - using (Stream stream = File.Create(ArtifactsDir + "Remove hidden text - OpenXML.docx")) + // Iterate through all runs in the paragraph. + foreach (var run in paragraph.Elements()) { - xdoc.Save(stream); + // Check if the run has properties + var runProperties = run.RunProperties; + if (runProperties != null) + { + // Check if the text is hidden. + var hidden = runProperties.Elements().FirstOrDefault(); + if (hidden != null) + // Remove the hidden property to unhide the text. + hidden.Remove(); + } } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove page breaks.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove page breaks.cs index f4dcf0b17..c65378c37 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove page breaks.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove page breaks.cs @@ -1,6 +1,10 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// -using System.Collections.Generic; using System.IO; using System.Linq; using DocumentFormat.OpenXml.Packaging; @@ -15,18 +19,17 @@ public class RemovePageBreaks : TestUtil [Test] public void RemovePageBreaksFeature() { - using (WordprocessingDocument myDoc = WordprocessingDocument.Open(MyDir + "Remove page breaks.docx", true)) - { - MainDocumentPart mainPart = myDoc.MainDocumentPart; - List breaks = mainPart.Document.Descendants().ToList(); - - foreach (Break b in breaks) - b.Remove(); + File.Copy(MyDir + "Remove page breaks.docx", ArtifactsDir + "Remove page breaks - OpenXML.docx", true); - using (Stream stream = File.Create(ArtifactsDir + "Remove page breaks - OpenXML.docx")) - { - mainPart.Document.Save(stream); - } + using (WordprocessingDocument doc = WordprocessingDocument.Open(ArtifactsDir + "Remove page breaks - OpenXML.docx", true)) + { + // Get the main document part. + var body = doc.MainDocumentPart.Document.Body; + + // Find all page breaks in the document. + var breaks = body.Descendants().ToList(); + foreach (var pageBreak in breaks) + pageBreak.Remove(); } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove section breaks.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove section breaks.cs index 97b0df195..b51c5da3c 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove section breaks.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Remove section breaks.cs @@ -1,6 +1,10 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// -using System.Collections.Generic; using System.IO; using System.Linq; using DocumentFormat.OpenXml.Packaging; @@ -15,30 +19,19 @@ public class RemoveSectionBreaks : TestUtil [Test] public void RemoveSectionBreaksFeature() { - using (WordprocessingDocument myDoc = WordprocessingDocument.Open(MyDir + "Remove section breaks.docx", true)) - { - MainDocumentPart mainPart = myDoc.MainDocumentPart; - List paraProps = mainPart.Document.Descendants() - .Where(IsSectionProps).ToList(); + File.Copy(MyDir + "Remove section breaks.docx", ArtifactsDir + "Remove section breaks - OpenXML.docx", true); - foreach (ParagraphProperties pPr in paraProps) - pPr.RemoveChild(pPr.GetFirstChild()); + using (WordprocessingDocument doc = WordprocessingDocument.Open(ArtifactsDir + "Remove section breaks - OpenXML.docx", true)) + { + // Get the main document part. + var body = doc.MainDocumentPart.Document.Body; - using (Stream stream = File.Create(ArtifactsDir + "Remove section breaks - OpenXML.docx")) - { - mainPart.Document.Save(stream); - } + // Find all section breaks in the document. + var sectionProperties = body.Descendants().ToList(); + // Remove each section properties element. + foreach (var section in sectionProperties) + section.Remove(); } } - - private static bool IsSectionProps(ParagraphProperties pPr) - { - SectionProperties sectPr = pPr.GetFirstChild(); - - if (sectPr == null) - return false; - - return true; - } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Retrieve comments.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Retrieve comments.cs index b03932e8d..1f9f75329 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Retrieve comments.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Retrieve comments.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System; using DocumentFormat.OpenXml.Packaging; @@ -13,9 +18,9 @@ public class RetrieveComments : TestUtil [Test] public static void RetrieveCommentsFeature() { - using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(MyDir + "Comments.docx", false)) + using (WordprocessingDocument doc = WordprocessingDocument.Open(MyDir + "Comments.docx", false)) { - WordprocessingCommentsPart commentsPart = wordDoc.MainDocumentPart.WordprocessingCommentsPart; + WordprocessingCommentsPart commentsPart = doc.MainDocumentPart.WordprocessingCommentsPart; if (commentsPart?.Comments != null) foreach (Comment comment in commentsPart.Comments.Elements()) diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Search and replace text.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Search and replace text.cs index 81745114b..f59c92a3e 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Search and replace text.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/OpenXML features/Search and replace text.cs @@ -1,4 +1,9 @@ -// Copyright (c) Aspose 2002-2021. All Rights Reserved. +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// using System.IO; using System.Text.RegularExpressions; @@ -13,24 +18,19 @@ public class SearchAndReplaceText : TestUtil [Test] public static void SearchAndReplaceTextFeature() { - using (WordprocessingDocument wordDoc = - WordprocessingDocument.Open(MyDir + "Search and replace text.docx", true)) - { - string docText; + File.Copy(MyDir + "Search and replace text.docx", ArtifactsDir + "Search and replace text - OpenXML.docx", true); - using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream())) - { + using (WordprocessingDocument doc = WordprocessingDocument.Open(ArtifactsDir + "Search and replace text - OpenXML.docx", true)) + { + string? docText = null; + using (StreamReader sr = new StreamReader(doc.MainDocumentPart.GetStream())) docText = sr.ReadToEnd(); - } - Regex regexText = new Regex("Hello world!"); + Regex regexText = new Regex("Hello World!"); docText = regexText.Replace(docText, "Hi Everyone!"); - using (StreamWriter sw = - new StreamWriter(File.Create(ArtifactsDir + "Search and replace text - OpenXML.docx"))) - { + using (StreamWriter sw = new StreamWriter(doc.MainDocumentPart.GetStream(FileMode.Create))) sw.Write(docText); - } } } } diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/Properties/AssemblyInfo.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/Properties/AssemblyInfo.cs index 9a764581a..644febc4d 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/Properties/AssemblyInfo.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/Properties/AssemblyInfo.cs @@ -1,16 +1,6 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Aspose Words")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Aspose Words")] -[assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -21,16 +11,3 @@ // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("5181d152-e178-4066-b8fc-a5e42b67c35a")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/TestUtil.cs b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/TestUtil.cs index 56786e629..bc140076f 100644 --- a/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/TestUtil.cs +++ b/Plugins/Aspose.Words Vs OpenXML Words/Aspose.Words VS OpenXML/AsposeWords/TestUtil.cs @@ -1,7 +1,17 @@ -using System; +// Copyright (c) 2001-2025 Aspose Pty Ltd. All Rights Reserved. +// +// This file is part of Aspose.Words. The source code in this file +// is only intended as a supplement to the documentation, and is provided +// "as is", without warranty of any kind, either expressed or implied. +////////////////////////////////////////////////////////////////////////// + +using System; using System.Globalization; using System.IO; +using System.Linq; +using System.Net; using System.Reflection; +using System.Runtime.InteropServices; using System.Threading; using NUnit.Framework; @@ -9,25 +19,28 @@ namespace AsposeWordsVSOpenXML { public class TestUtil { - static TestUtil() - { - MainDataDir = GetCodeBaseDir(Assembly.GetExecutingAssembly()); - MyDir = new Uri(new Uri(MainDataDir), @"Data/").LocalPath; - ArtifactsDir = new Uri(new Uri(MainDataDir), @"Data/Artifacts/").LocalPath; - } - [OneTimeSetUp] - public static void OneTimeSetUp() + public void OneTimeSetUp() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; + ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; + if (!Directory.Exists(ArtifactsDir)) Directory.CreateDirectory(ArtifactsDir); } + [SetUp] + public void SetUp() + { + Console.WriteLine($"Clr: {RuntimeInformation.FrameworkDescription}\n"); + } + [OneTimeTearDown] - public static void OneTimeTearDown() + public void OneTimeTearDown() { + ServicePointManager.ServerCertificateValidationCallback = delegate { return false; }; + if (Directory.Exists(ArtifactsDir)) Directory.Delete(ArtifactsDir, true); } @@ -37,26 +50,49 @@ public static void OneTimeTearDown() /// internal static string GetCodeBaseDir(Assembly assembly) { - Uri uri = new Uri(assembly.CodeBase); + // CodeBase is a full URI, such as file:///x:\blahblah. + Uri uri = new Uri(assembly.Location); string mainFolder = Path.GetDirectoryName(uri.LocalPath) ?.Substring(0, uri.LocalPath.IndexOf("Aspose.Words VS OpenXML", StringComparison.Ordinal)); - return mainFolder; } /// - /// Gets the path to the codebase directory. + /// Returns the assembly directory correctly even if the assembly is shadow-copied. /// - internal static string MainDataDir { get; } + internal static string GetAssemblyDir(Assembly assembly) + { + // CodeBase is a full URI, such as file:///x:\blahblah. + Uri uri = new Uri(assembly.Location); + return Path.GetDirectoryName(uri.LocalPath) + Path.DirectorySeparatorChar; + } /// - /// Gets the path to the documents used by the code examples. + /// Gets the path to the currently running executable. /// - internal static string MyDir { get; } + internal static string AssemblyDir { get; } /// - /// Gets the path to the artifacts used by the code examples. + /// Gets the path to the codebase directory. + /// + internal static string CodeBaseDir { get; } + + /// + /// Gets the path to the documents used by the code examples. Ends with a back slash. /// internal static string ArtifactsDir { get; } + + /// + /// Gets the path to the documents used by the code examples. Ends with a back slash. + /// + internal static string MyDir { get; } + + static TestUtil() + { + AssemblyDir = GetAssemblyDir(Assembly.GetExecutingAssembly()); + CodeBaseDir = GetCodeBaseDir(Assembly.GetExecutingAssembly()); + ArtifactsDir = new Uri(new Uri(CodeBaseDir), @"Data/Artifacts/").LocalPath; + MyDir = new Uri(new Uri(CodeBaseDir), @"Data/").LocalPath; + } } } \ No newline at end of file diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Data/Bookmark.docx b/Plugins/Aspose.Words Vs OpenXML Words/Data/Bookmark.docx new file mode 100644 index 000000000..c5ad04015 Binary files /dev/null and b/Plugins/Aspose.Words Vs OpenXML Words/Data/Bookmark.docx differ diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Data/Comments.docx b/Plugins/Aspose.Words Vs OpenXML Words/Data/Comments.docx index a43cb5699..5ba7d4b51 100644 Binary files a/Plugins/Aspose.Words Vs OpenXML Words/Data/Comments.docx and b/Plugins/Aspose.Words Vs OpenXML Words/Data/Comments.docx differ diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Data/Convert from docm to docx.docm b/Plugins/Aspose.Words Vs OpenXML Words/Data/Docm to Docx conversion.docm similarity index 100% rename from Plugins/Aspose.Words Vs OpenXML Words/Data/Convert from docm to docx.docm rename to Plugins/Aspose.Words Vs OpenXML Words/Data/Docm to Docx conversion.docm diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Data/Document.docx b/Plugins/Aspose.Words Vs OpenXML Words/Data/Document.docx index fe1ec51b9..d17a230d1 100644 Binary files a/Plugins/Aspose.Words Vs OpenXML Words/Data/Document.docx and b/Plugins/Aspose.Words Vs OpenXML Words/Data/Document.docx differ diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Data/Get and set bookmark text.docx b/Plugins/Aspose.Words Vs OpenXML Words/Data/Get and set bookmark text.docx deleted file mode 100644 index 7bd3b710c..000000000 Binary files a/Plugins/Aspose.Words Vs OpenXML Words/Data/Get and set bookmark text.docx and /dev/null differ diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Data/Remove page breaks.docx b/Plugins/Aspose.Words Vs OpenXML Words/Data/Remove page breaks.docx index c79e98cb0..d0670c258 100644 Binary files a/Plugins/Aspose.Words Vs OpenXML Words/Data/Remove page breaks.docx and b/Plugins/Aspose.Words Vs OpenXML Words/Data/Remove page breaks.docx differ diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Data/Remove section breaks.docx b/Plugins/Aspose.Words Vs OpenXML Words/Data/Remove section breaks.docx index d0670c258..76b439691 100644 Binary files a/Plugins/Aspose.Words Vs OpenXML Words/Data/Remove section breaks.docx and b/Plugins/Aspose.Words Vs OpenXML Words/Data/Remove section breaks.docx differ diff --git a/Plugins/Aspose.Words Vs OpenXML Words/Data/Change text in a table.docx b/Plugins/Aspose.Words Vs OpenXML Words/Data/Replace text.docx similarity index 74% rename from Plugins/Aspose.Words Vs OpenXML Words/Data/Change text in a table.docx rename to Plugins/Aspose.Words Vs OpenXML Words/Data/Replace text.docx index 6ad5344fb..d4aa9d956 100644 Binary files a/Plugins/Aspose.Words Vs OpenXML Words/Data/Change text in a table.docx and b/Plugins/Aspose.Words Vs OpenXML Words/Data/Replace text.docx differ