Skip to content

Commit a1c6505

Browse files
Merge pull request #249 from VijayadharshiniMathiyalagan/ES-876652-How-to-change-the-font-of-table-content-in-a-Word-document
ES-876652 Added change font table content sample
2 parents 1ffe70f + b2028e8 commit a1c6505

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35309.182
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Change-font-of-table-content", "Change-font-of-table-content\Change-font-of-table-content.csproj", "{5510835E-0856-4A22-ABEC-80957F810A16}"
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+
{5510835E-0856-4A22-ABEC-80957F810A16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5510835E-0856-4A22-ABEC-80957F810A16}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5510835E-0856-4A22-ABEC-80957F810A16}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{5510835E-0856-4A22-ABEC-80957F810A16}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {4D0250FF-F767-4F12-813F-5ACFC09975A8}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 24 additions & 0 deletions
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_font_of_table_content</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\Input.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
4+
using (FileStream inputStream = new FileStream("Data/Input.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
5+
{
6+
// Open the input Word document.
7+
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
8+
{
9+
// Find a table by Title.
10+
WTable table = document.FindItemByProperty(EntityType.Table, "Title", "Adventure") as WTable;
11+
// Iterate through each row in the table.
12+
foreach (WTableRow row in table.Rows)
13+
{
14+
// Iterate through each cell in the row.
15+
foreach (WTableCell cell in row.Cells)
16+
{
17+
// Iterate through each paragraph in the cell.
18+
foreach (WParagraph paragraph in cell.Paragraphs)
19+
{
20+
// Iterate through the child entities of the paragraph.
21+
foreach (Entity entity in paragraph.ChildEntities)
22+
{
23+
// Check if the child entity is a text range.
24+
if (entity is WTextRange)
25+
{
26+
// Change the font to Algerian for the text range.
27+
(entity as WTextRange).CharacterFormat.FontName = "Algerian";
28+
}
29+
}
30+
}
31+
}
32+
}
33+
// Save the modified Word document.
34+
using (FileStream outputStream = new FileStream("Output/Output.docx", FileMode.Create, FileAccess.Write))
35+
{
36+
document.Save(outputStream, FormatType.Docx);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)