-
Notifications
You must be signed in to change notification settings - Fork 56
997930 - Add DocIO Sample for Find bookmarks location in Word document #494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MathanKumarVaradhaRajaPerumal
merged 3 commits into
main
from
997930-Add-Sample-for-find-bookmark-location
Dec 18, 2025
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...rk-Owner-TextBody-or-Header-Footer/.NET/Find-Bookmark-Owner-TextBody-or-Header-Footer.sln
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 17 | ||
| VisualStudioVersion = 17.14.36518.9 d17.14 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-Bookmark-Owner-TextBody-or-Header-Footer", "Find-Bookmark-Owner-TextBody-or-Header-Footer\Find-Bookmark-Owner-TextBody-or-Header-Footer.csproj", "{73FE0BC7-3E61-4093-864D-77BC36251331}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {73FE0BC7-3E61-4093-864D-77BC36251331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {73FE0BC7-3E61-4093-864D-77BC36251331}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {73FE0BC7-3E61-4093-864D-77BC36251331}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {73FE0BC7-3E61-4093-864D-77BC36251331}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {1FF6D9EE-60E6-40F2-94B4-AC0FD9D92EA3} | ||
| EndGlobalSection | ||
| EndGlobal |
Binary file added
BIN
+61.1 KB
...dy-or-Header-Footer/.NET/Find-Bookmark-Owner-TextBody-or-Header-Footer/Data/Template.docx
Binary file not shown.
21 changes: 21 additions & 0 deletions
21
...mark-Owner-TextBody-or-Header-Footer/Find-Bookmark-Owner-TextBody-or-Header-Footer.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <RootNamespace>Find_Bookmark_Owner_TextBody_or_Header_Footer</RootNamespace> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Update="Data\Template.docx"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </None> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
63 changes: 63 additions & 0 deletions
63
...r-TextBody-or-Header-Footer/.NET/Find-Bookmark-Owner-TextBody-or-Header-Footer/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| using Syncfusion.DocIO.DLS; | ||
|
|
||
| namespace Find_Bookmark_Owner_TextBody_or_Header_Footer | ||
| { | ||
| class Program | ||
| { | ||
| public static void Main(string[] args) | ||
| { | ||
| // Load the existing Word document | ||
| WordDocument document = new WordDocument(Path.GetFullPath("Data/Template.docx")); | ||
| // Iterate through all bookmarks in the document. | ||
| foreach (Bookmark bookmark in document.Bookmarks) | ||
| { | ||
| // Get bookmark start from the current bookmark | ||
| BookmarkStart bkmkStart = bookmark.BookmarkStart; | ||
| if (bkmkStart != null) | ||
| { | ||
| // Get the paragraphs that contain the bookmark's start. | ||
| WParagraph startPara = bkmkStart.OwnerParagraph; | ||
| Entity ownerEntity = startPara; | ||
| // Traverse the owner hierarchy until reaching the section, stopping if a HeaderFooter is found | ||
| while (!(ownerEntity is WSection)) | ||
| { | ||
| if (ownerEntity.EntityType == EntityType.HeaderFooter) | ||
| break; | ||
| ownerEntity = ownerEntity.Owner; | ||
| } | ||
| // Check if the bookmark is in the text body, header, or footer | ||
| string ownerLabel = (ownerEntity.EntityType == EntityType.Section) | ||
| ? "TextBody" | ||
| : CheckHeaderFooterType(ownerEntity.Owner as WSection, ownerEntity as HeaderFooter); | ||
| // Print the bookmark name and its owner type | ||
| Console.WriteLine("Bookmark Name:" + bkmkStart.Name + "\n Bookmark Owner:" + ownerLabel); | ||
| } | ||
| } | ||
| Console.ReadLine(); | ||
| } | ||
| /// <summary> | ||
| /// Returns a whether the provided HeaderFooter instance belongs to the header or footer of the given section. | ||
| /// </summary> | ||
| /// <param name="section">The section that contains the HeaderFooter</param> | ||
| /// <param name="headerFooter">The HeaderFooter instance to check.</param> | ||
| /// <returns>Returns "Header" if the instance is a header, "Footer" if it is a footer, | ||
| /// otherwise "Header and Footer".</returns> | ||
| private static string CheckHeaderFooterType(WSection section, HeaderFooter headerFooter) | ||
| { | ||
| string type = "Header and Footer"; | ||
| // Check if the given HeaderFooter instance is one of the section's header references. | ||
| if (section.HeadersFooters.OddHeader == headerFooter | ||
| || section.HeadersFooters.FirstPageHeader == headerFooter || section.HeadersFooters.EvenHeader == headerFooter) | ||
| { | ||
| type = "Header"; | ||
| } | ||
| // Otherwise, check if it is one of the section's footer references. | ||
| else if (section.HeadersFooters.OddFooter == headerFooter || section.HeadersFooters.EvenFooter == headerFooter | ||
| || section.HeadersFooters.FirstPageFooter == headerFooter) | ||
| { | ||
| type = "Footer"; | ||
| } | ||
| return type; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entity ownerEntity = bkmkStart.OwnerParagraph;