diff --git a/Comments/Find-text-and-add-comments/.NET/Find-text-and-add-comments.sln b/Comments/Find-text-and-add-comments/.NET/Find-text-and-add-comments.sln new file mode 100644 index 00000000..fe5f1052 --- /dev/null +++ b/Comments/Find-text-and-add-comments/.NET/Find-text-and-add-comments.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34928.147 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-text-and-add-comments", "Find-text-and-add-comments\Find-text-and-add-comments.csproj", "{8B2E34B8-B23D-4717-A86A-34EB32012EC3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8B2E34B8-B23D-4717-A86A-34EB32012EC3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6140D05B-D8BA-4632-A04A-84100359C4AF} + EndGlobalSection +EndGlobal diff --git a/Comments/Find-text-and-add-comments/.NET/Find-text-and-add-comments/Data/InsertComment.docx b/Comments/Find-text-and-add-comments/.NET/Find-text-and-add-comments/Data/InsertComment.docx new file mode 100644 index 00000000..dfcc4dd0 Binary files /dev/null and b/Comments/Find-text-and-add-comments/.NET/Find-text-and-add-comments/Data/InsertComment.docx differ diff --git a/Comments/Find-text-and-add-comments/.NET/Find-text-and-add-comments/Find-text-and-add-comments.csproj b/Comments/Find-text-and-add-comments/.NET/Find-text-and-add-comments/Find-text-and-add-comments.csproj new file mode 100644 index 00000000..6d140628 --- /dev/null +++ b/Comments/Find-text-and-add-comments/.NET/Find-text-and-add-comments/Find-text-and-add-comments.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + Find_text_and_add_comments + enable + enable + + + + + + + diff --git a/Comments/Find-text-and-add-comments/.NET/Find-text-and-add-comments/Program.cs b/Comments/Find-text-and-add-comments/.NET/Find-text-and-add-comments/Program.cs new file mode 100644 index 00000000..0c6214fc --- /dev/null +++ b/Comments/Find-text-and-add-comments/.NET/Find-text-and-add-comments/Program.cs @@ -0,0 +1,39 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + +using (FileStream inputStream = new FileStream(@"../../../Data/InsertComment.docx", FileMode.Open, FileAccess.Read)) +{ + //Open the existing Word document. + using (WordDocument document = new WordDocument(inputStream, FormatType.Docx)) + { + //Find all occurrence of a particular text ending with comma in the document using regex. + TextSelection[] textSelection = document.FindAll("panda", true, true); + if (textSelection != null) + { + //Iterates through each occurrence and comment it. + for (int i = 0; i < textSelection.Count(); i++) + { + WTextRange textRange = textSelection[i].GetAsOneRange(); + + //Get the index of the found text. + int textIndex = textRange.OwnerParagraph.ChildEntities.IndexOf(textRange); + //Add comment to a paragraph. + WComment comment = textRange.OwnerParagraph.AppendComment("comment test_" + i); + //Specify the author of the comment. + comment.Format.User = "Peter"; + //Set the date and time for the comment. + comment.Format.DateTime = DateTime.Now; + //Insert the comment next to the textrange. + textRange.OwnerParagraph.ChildEntities.Insert(textIndex + 1, comment); + //Add the paragraph items to the commented items. + comment.AddCommentedItem(textRange); + } + } + + //Save the Word document + using (FileStream outputStream = new FileStream(@"../../../Output.docx", FileMode.Create, FileAccess.Write)) + { + document.Save(outputStream, FormatType.Docx); + } + } +} \ No newline at end of file diff --git a/Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks.sln b/Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks.sln new file mode 100644 index 00000000..e008a03e --- /dev/null +++ b/Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34928.147 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Remove_all_page_breaks", "Remove_all_page_breaks\Remove_all_page_breaks.csproj", "{BBAF7F96-C858-4CE2-AEA5-5192110B8CB8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BBAF7F96-C858-4CE2-AEA5-5192110B8CB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BBAF7F96-C858-4CE2-AEA5-5192110B8CB8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BBAF7F96-C858-4CE2-AEA5-5192110B8CB8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BBAF7F96-C858-4CE2-AEA5-5192110B8CB8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5AA2BDB5-3AE9-4E8D-8115-E0B1DF21850D} + EndGlobalSection +EndGlobal diff --git a/Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks/Data/Template.docx b/Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks/Data/Template.docx new file mode 100644 index 00000000..ce4a5295 Binary files /dev/null and b/Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks/Data/Template.docx differ diff --git a/Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks/Program.cs b/Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks/Program.cs new file mode 100644 index 00000000..b3f9dd1c --- /dev/null +++ b/Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks/Program.cs @@ -0,0 +1,22 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + +using (FileStream inputStream = new FileStream(@"../../../Data/Template.docx", FileMode.Open, FileAccess.Read)) +{ + //Open the existing Word document. + using (WordDocument document = new WordDocument(inputStream, FormatType.Docx)) + { + //Get the list of page breaks + List entities = document.FindAllItemsByProperty(EntityType.Break, "BreakType", "PageBreak"); + + //Iterate through all page breaks and remove it from the owner paragraph + foreach (Entity entity in entities) + (entity as Break).OwnerParagraph.ChildEntities.Remove(entity); + + //Save the Word document + using (FileStream outputStream = new FileStream(@"../../../Output.docx", FileMode.Create, FileAccess.Write)) + { + document.Save(outputStream, FormatType.Docx); + } + } +} \ No newline at end of file diff --git a/Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks/Remove_all_page_breaks.csproj b/Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks/Remove_all_page_breaks.csproj new file mode 100644 index 00000000..8850c522 --- /dev/null +++ b/Paragraphs/Remove_all_page_breaks/.NET/Remove_all_page_breaks/Remove_all_page_breaks.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents.sln b/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents.sln new file mode 100644 index 00000000..3db73225 --- /dev/null +++ b/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34928.147 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add_toc_in_merged_documents", "Add_toc_in_merged_documents\Add_toc_in_merged_documents.csproj", "{78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}.Debug|Any CPU.Build.0 = Debug|Any CPU + {78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}.Release|Any CPU.ActiveCfg = Release|Any CPU + {78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CF8B010D-A0FC-4D30-8767-8B601222372E} + EndGlobalSection +EndGlobal diff --git a/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Add_toc_in_merged_documents.csproj b/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Add_toc_in_merged_documents.csproj new file mode 100644 index 00000000..aa508695 --- /dev/null +++ b/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Add_toc_in_merged_documents.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + diff --git a/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Data/Document1.docx b/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Data/Document1.docx new file mode 100644 index 00000000..52e17df6 Binary files /dev/null and b/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Data/Document1.docx differ diff --git a/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Data/Document2.docx b/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Data/Document2.docx new file mode 100644 index 00000000..57f74055 Binary files /dev/null and b/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Data/Document2.docx differ diff --git a/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Data/Document3.docx b/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Data/Document3.docx new file mode 100644 index 00000000..c39c1438 Binary files /dev/null and b/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Data/Document3.docx differ diff --git a/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Program.cs b/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Program.cs new file mode 100644 index 00000000..fed062af --- /dev/null +++ b/Table-Of-Contents/Add_toc_in_merged_documents/.NET/Add_toc_in_merged_documents/Program.cs @@ -0,0 +1,41 @@ +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIO; +using Syncfusion.DocIORenderer; + +//Get the Source document names from the folder. +string[] sourceDocumentNames = Directory.GetFiles(@"../../../Data/"); + +//Create an WordDocumentinstance for destination document. +using (WordDocument destinationDocument = new WordDocument()) +{ + //Add an section and paragraph to the destination document. + IWSection section = destinationDocument.AddSection(); + IWParagraph paragraph = section.AddParagraph(); + //Appends the TOC field with LowerHeadingLevel and UpperHeadingLevel to determines the TOC entries. + paragraph.AppendTOC(1, 3); + + //Merge each source document to the destination document. + foreach (string subDocumentName in sourceDocumentNames) + { + //Open the source document files as a stream. + using (FileStream sourceDocumentPathStream = new FileStream(Path.GetFullPath(subDocumentName), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + //Open the source documents. + using (WordDocument sourceDocument = new WordDocument(sourceDocumentPathStream, FormatType.Docx)) + { + //Sets the break-code of First section of source document as NoBreak to avoid imported from a new page + sourceDocument.Sections[0].BreakCode = SectionBreakCode.NoBreak; + //Imports the contents of source document at the end of destination document + destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles); + } + } + } + + //Updates the table of contents + destinationDocument.UpdateTableOfContents(); + //Save the destination document. + using (FileStream outputStream = new FileStream(@"../../../Output.docx", FileMode.Create, FileAccess.Write)) + { + destinationDocument.Save(outputStream, FormatType.Docx); + } +} \ No newline at end of file