diff --git a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs index 64c357f99..032691c69 100644 --- a/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs +++ b/Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs @@ -12,8 +12,8 @@ static void Main(string[] args) //Opens an existing Word document. using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Automatic)) { - //Replace Bookmark name - ReplaceBookmarkName(document, "Northwind", "New_Bookmark"); + //Rename Bookmark + RenameBookmark(document, "Northwind", "New_Bookmark"); //Creates file stream. using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) { @@ -29,8 +29,8 @@ static void Main(string[] args) /// /// Input Word document. /// The name of the bookmark to replace. - /// The new name for the bookmark. - private static void ReplaceBookmarkName(WordDocument document, string existingBookmarkName, string replaceBookmarkName) + /// The new name for the bookmark. + private static void RenameBookmark(WordDocument document, string existingBookmarkName, string newBookmarkName) { //Gets the bookmark instance by using FindByName method of BookmarkCollection with bookmark name Bookmark bookmark = document.Bookmarks.FindByName(existingBookmarkName); @@ -41,8 +41,8 @@ private static void ReplaceBookmarkName(WordDocument document, string existingBo int startIndex = -1; int endIndex = -1; // Create new bookmark start and end markers with the replacement name - BookmarkStart newBookmarkStart = new BookmarkStart(document, replaceBookmarkName); - BookmarkEnd newBookmarkEnd = new BookmarkEnd(document, replaceBookmarkName); + BookmarkStart newBookmarkStart = new BookmarkStart(document, newBookmarkName); + BookmarkEnd newBookmarkEnd = new BookmarkEnd(document, newBookmarkName); // Determine the owner and index for the bookmark start. // The bookmark start may be inside a WParagraph (as a child entity) diff --git a/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title.slnx b/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title.slnx new file mode 100644 index 000000000..01fcc303b --- /dev/null +++ b/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title.slnx @@ -0,0 +1,3 @@ + + + diff --git a/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title/Data/Template.docx b/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title/Data/Template.docx new file mode 100644 index 000000000..1f16530a5 Binary files /dev/null and b/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title/Data/Template.docx differ diff --git a/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title/Find-and-iterate-table-by-title.csproj b/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title/Find-and-iterate-table-by-title.csproj new file mode 100644 index 000000000..c89af551e --- /dev/null +++ b/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title/Find-and-iterate-table-by-title.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + Find_and_iterate_table_by_title + enable + enable + + + + + + + + + Always + + + Always + + + + diff --git a/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title/Output/.gitkeep b/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title/Program.cs b/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title/Program.cs new file mode 100644 index 000000000..c6df26c03 --- /dev/null +++ b/Tables/Find-and-iterate-table-by-title/.NET/Find-and-iterate-table-by-title/Program.cs @@ -0,0 +1,52 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.Drawing; + +namespace Find_and_iterate_table_by_title +{ + internal class Program + { + static void Main(string[] args) + { + using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite)) + { + //Opens an existing Word document. + using (WordDocument document = new WordDocument(fileStream, FormatType.Automatic)) + { + // Find the table with title. + WTable table = document.FindItemByProperty(EntityType.Table, "Title", "Overview") as WTable; + if (table != null) + { + // Iterate through the rows and cells of the table + foreach (WTableRow row in table.Rows) + { + //Iterates through the cells of rows. + foreach (WTableCell cell in row.Cells) + { + //Iterates through the paragraphs of the cell. + foreach (WParagraph paragraph in cell.Paragraphs) + { + //When the paragraph contains text Panda then insert new text into paragraph. + if (paragraph.Text.Contains("panda")) + { + WTextRange insertedText = paragraph.AppendText(" (Attributes)") as WTextRange; + // Apply simple formatting only to the inserted text + insertedText.CharacterFormat.Bold = true; + insertedText.CharacterFormat.HighlightColor = Color.Yellow; + } + } + } + } + } + //Creates file stream. + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputStream, FormatType.Docx); + } + } + } + } + } +} +