-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
898185-change-format-after-append-html
- Loading branch information
1 parent
73db5a3
commit 6b4e254
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
HTML-conversions/Change-format-after-append-html/.NET/Change-format-after-append-html.sln
This file contains 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,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.12.35527.113 d17.12 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Change-format-after-append-html", "Change-format-after-append-html\Change-format-after-append-html.csproj", "{5C44DC52-5C9E-4FE2-9F56-31ECB24E3B33}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5C44DC52-5C9E-4FE2-9F56-31ECB24E3B33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5C44DC52-5C9E-4FE2-9F56-31ECB24E3B33}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5C44DC52-5C9E-4FE2-9F56-31ECB24E3B33}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5C44DC52-5C9E-4FE2-9F56-31ECB24E3B33}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
24 changes: 24 additions & 0 deletions
24
...r-append-html/.NET/Change-format-after-append-html/Change-format-after-append-html.csproj
This file contains 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,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>Change_format_after_append_html</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> | ||
<None Update="Output\.gitkeep"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file added
BIN
+154 KB
...s/Change-format-after-append-html/.NET/Change-format-after-append-html/Data/Template.docx
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...ions/Change-format-after-append-html/.NET/Change-format-after-append-html/Output/.gitkeep
This file contains 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 @@ | ||
|
52 changes: 52 additions & 0 deletions
52
...nversions/Change-format-after-append-html/.NET/Change-format-after-append-html/Program.cs
This file contains 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,52 @@ | ||
using Syncfusion.DocIO.DLS; | ||
using Syncfusion.DocIO; | ||
|
||
namespace Change_format_after_append_html | ||
{ | ||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
// Open the Word document. | ||
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read)) | ||
{ | ||
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx)) | ||
{ | ||
// Access the first section of the document. | ||
WSection section = document.Sections[0]; | ||
|
||
// Get the index of the last paragraph. | ||
int paraIndex = section.Body.Paragraphs.Count - 1; | ||
|
||
// Append HTML content to the document with formatting in <p> tag. | ||
document.LastParagraph.AppendHTML("<p style='color:blue; font-weight:bold;'>The Giant</p><p style='color:green; font-style:italic;'>Panda</p>"); | ||
|
||
// Iterate through the paragraphs in the section's body. | ||
for (int i = paraIndex; i < section.Body.ChildEntities.Count; i++) | ||
{ | ||
// Get the paragraph and check if it's not null. | ||
WParagraph paragraph = section.Body.ChildEntities[i] as WParagraph; | ||
if (paragraph != null) | ||
{ | ||
// Set the paragraph formatting spacing to 0. | ||
paragraph.ParagraphFormat.BeforeSpacing = 0; | ||
paragraph.ParagraphFormat.AfterSpacing = 0; | ||
|
||
// Iterate through the items in the paragraph to chnage formatting. | ||
foreach (var item in paragraph.ChildEntities) | ||
{ | ||
if (item is WTextRange textRange) | ||
textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.DarkGreen; // Change text color | ||
} | ||
} | ||
} | ||
// Save the modified document. | ||
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.Write)) | ||
{ | ||
document.Save(outputStream, FormatType.Docx); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |