Skip to content

Commit

Permalink
Merge pull request #249 from VijayadharshiniMathiyalagan/ES-876652-Ho…
Browse files Browse the repository at this point in the history
…w-to-change-the-font-of-table-content-in-a-Word-document

ES-876652 Added change font table content sample
  • Loading branch information
MohanaselvamJothi authored Oct 28, 2024
2 parents 1ffe70f + b2028e8 commit a1c6505
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
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.12.35309.182
MinimumVisualStudioVersion = 10.0.40219.1
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5510835E-0856-4A22-ABEC-80957F810A16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5510835E-0856-4A22-ABEC-80957F810A16}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5510835E-0856-4A22-ABEC-80957F810A16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5510835E-0856-4A22-ABEC-80957F810A16}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D0250FF-F767-4F12-813F-5ACFC09975A8}
EndGlobalSection
EndGlobal
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_font_of_table_content</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\Input.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;

using (FileStream inputStream = new FileStream("Data/Input.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
// Open the input Word document.
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
{
// Find a table by Title.
WTable table = document.FindItemByProperty(EntityType.Table, "Title", "Adventure") as WTable;
// Iterate through each row in the table.
foreach (WTableRow row in table.Rows)
{
// Iterate through each cell in the row.
foreach (WTableCell cell in row.Cells)
{
// Iterate through each paragraph in the cell.
foreach (WParagraph paragraph in cell.Paragraphs)
{
// Iterate through the child entities of the paragraph.
foreach (Entity entity in paragraph.ChildEntities)
{
// Check if the child entity is a text range.
if (entity is WTextRange)
{
// Change the font to Algerian for the text range.
(entity as WTextRange).CharacterFormat.FontName = "Algerian";
}
}
}
}
}
// Save the modified Word document.
using (FileStream outputStream = new FileStream("Output/Output.docx", FileMode.Create, FileAccess.Write))
{
document.Save(outputStream, FormatType.Docx);
}
}
}

0 comments on commit a1c6505

Please sign in to comment.