Skip to content

Commit 1f7b661

Browse files
Merge pull request #318 from SyncfusionExamples/898185-change-format-after-append-html
898185-Add the sample change-format-after-append-html in HTML conversion
2 parents c399b5d + 8586300 commit 1f7b661

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35527.113 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
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}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{5C44DC52-5C9E-4FE2-9F56-31ECB24E3B33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5C44DC52-5C9E-4FE2-9F56-31ECB24E3B33}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5C44DC52-5C9E-4FE2-9F56-31ECB24E3B33}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{5C44DC52-5C9E-4FE2-9F56-31ECB24E3B33}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Change_format_after_append_html</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Template.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
4+
namespace Change_format_after_append_html
5+
{
6+
internal class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
// Open the Word document.
11+
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read))
12+
{
13+
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
14+
{
15+
// Access the first section of the document.
16+
WSection section = document.Sections[0];
17+
18+
// Get the index of the last paragraph.
19+
int paraIndex = section.Body.Paragraphs.Count - 1;
20+
21+
// Append HTML content to the document with formatting in <p> tag.
22+
document.LastParagraph.AppendHTML("<p>The Giant</p><p>Panda</p>");
23+
24+
// Iterate through the paragraphs in the section's body.
25+
for (int i = paraIndex; i < section.Body.ChildEntities.Count; i++)
26+
{
27+
// Get the paragraph and check if it's not null.
28+
WParagraph paragraph = section.Body.ChildEntities[i] as WParagraph;
29+
if (paragraph != null)
30+
{
31+
// Set the paragraph formatting spacing to 0.
32+
paragraph.ParagraphFormat.BeforeSpacing = 0;
33+
paragraph.ParagraphFormat.AfterSpacing = 0;
34+
}
35+
}
36+
// Save the modified document.
37+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.Write))
38+
{
39+
document.Save(outputStream, FormatType.Docx);
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)