-
Notifications
You must be signed in to change notification settings - Fork 56
Replace-text-in-list-paragraph #310
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
MohanaselvamJothi
merged 3 commits into
main
from
ES-876618-Replace-text-in-list-paragraph
Dec 31, 2024
Merged
Changes from 1 commit
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
HTML-conversions/Replace-text-in-list-paragraph/.NET/Replace-text-in-list-paragraph.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 16 | ||
| VisualStudioVersion = 16.0.30804.86 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-text-in-list-paragraph", "Replace-text-in-list-paragraph/Replace-text-in-list-paragraph.csproj", "{DDC158F3-4052-48B7-AF5F-4AB3D6CD4B22}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {DDC158F3-4052-48B7-AF5F-4AB3D6CD4B22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {DDC158F3-4052-48B7-AF5F-4AB3D6CD4B22}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {DDC158F3-4052-48B7-AF5F-4AB3D6CD4B22}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {DDC158F3-4052-48B7-AF5F-4AB3D6CD4B22}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {2F907F5C-D20B-4C16-8863-3281F8B7A58B} | ||
| EndGlobalSection | ||
| EndGlobal |
9 changes: 9 additions & 0 deletions
9
...ersions/Replace-text-in-list-paragraph/.NET/Replace-text-in-list-paragraph/Data/File.html
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,9 @@ | ||
| <html> | ||
| <body> | ||
| <div style="font-family:calibri;color:#3C4D6F;"> | ||
| <p>Cycling Helmet</p> | ||
| <p>Enhance durability and performance in rough terrain</p> | ||
| <p>Beefier look with thicker tires</p> | ||
| </div> | ||
| </body> | ||
| </html> |
Binary file added
BIN
+34.4 KB
...ons/Replace-text-in-list-paragraph/.NET/Replace-text-in-list-paragraph/Data/Template.docx
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...rsions/Replace-text-in-list-paragraph/.NET/Replace-text-in-list-paragraph/Output/.gitkeep
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 @@ | ||
| |
72 changes: 72 additions & 0 deletions
72
...conversions/Replace-text-in-list-paragraph/.NET/Replace-text-in-list-paragraph/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,72 @@ | ||
| using Syncfusion.DocIO; | ||
| using Syncfusion.DocIO.DLS; | ||
| using System.IO; | ||
|
|
||
| namespace Replace_text_in_list_paragraph | ||
| { | ||
| class Program | ||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite)) | ||
| { | ||
| //Open the template Word document. | ||
| using (WordDocument document = new WordDocument(inputFileStream, FormatType.Automatic)) | ||
| { | ||
| string htmlFilePath = @"Data/File.html"; | ||
| //Check if the HTML content is valid. | ||
| if (document.LastSection.Body.IsValidXHTML(htmlFilePath, XHTMLValidationType.None)) | ||
| { | ||
| //Define the variable containing the text to search within the paragraph. | ||
| string variable = "Youth mountain bike"; | ||
| //Find the first occurrence of a particular text in the document | ||
| TextSelection textSelection = document.Find(variable, true, true); | ||
| //Get the found text as single text range | ||
| WTextRange textRange = textSelection.GetAsOneRange(); | ||
| // Get the paragraph containing the found text range | ||
| WParagraph paragraph = textRange.OwnerParagraph; | ||
| //Get the next sibling element of the current paragraph. | ||
| TextBodyItem nextSibling = paragraph.NextSibling as TextBodyItem; | ||
| //Get the index of the current paragraph within its parent text body. | ||
| int sourceIndex = paragraph.OwnerTextBody.ChildEntities.IndexOf(paragraph); | ||
| //Clear all child entities within the paragraph. | ||
| paragraph.ChildEntities.Clear(); | ||
| //Get the list style name from the paragraph. | ||
| string listStyleName = paragraph.ListFormat.CurrentListStyle.Name; | ||
| //Get the current list level number. | ||
| int listLevelNum = paragraph.ListFormat.ListLevelNumber; | ||
| //Append HTML content from the specified file to the paragraph. | ||
| paragraph.AppendHTML(File.ReadAllText(Path.GetFullPath(htmlFilePath))); | ||
| //Determine the index of the next sibling if it exists. | ||
| int nextSiblingIndex = nextSibling != null ? nextSibling.OwnerTextBody.ChildEntities.IndexOf(nextSibling) : -1; | ||
| //Apply the same list style to newly added paragraphs from the HTML content. | ||
| for (int k = sourceIndex; k < paragraph.OwnerTextBody.Count; k++) | ||
| { | ||
| //Stop applying the style if the next sibling is reached. | ||
| if (nextSiblingIndex != -1 && k == nextSiblingIndex) | ||
| { | ||
| break; | ||
| } | ||
| Entity entity = paragraph.OwnerTextBody.ChildEntities[k]; | ||
| //Apply the list style only if the entity is a paragraph. | ||
| if (entity is WParagraph) | ||
| { | ||
| (entity as WParagraph).ListFormat.ApplyStyle(listStyleName); | ||
| (entity as WParagraph).ListFormat.ListLevelNumber = listLevelNum; | ||
| } | ||
| else | ||
| { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) | ||
| { | ||
| //Save the modified Word document to the output file stream. | ||
| document.Save(outputFileStream, FormatType.Docx); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
...-list-paragraph/.NET/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph.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,28 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <RootNamespace>Replace_text_in_list_paragraph</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Update="Data\File.html"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </None> | ||
| <None Update="Data\Input.docx"> | ||
|
||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </None> | ||
| <None Update="Data\Template.docx"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </None> | ||
| <None Update="Output\.gitkeep"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </None> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
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.
Change sample name as Replace text in list paragraph with HTML
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.
modified