Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.14.37614.0 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apply-Custom-Font-For-TOC-Headings", "Apply-Custom-Font-For-TOC-Headings\Apply-Custom-Font-For-TOC-Headings.csproj", "{000D8166-FF6B-E115-AEE0-A0A05404C8D8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{000D8166-FF6B-E115-AEE0-A0A05404C8D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{000D8166-FF6B-E115-AEE0-A0A05404C8D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{000D8166-FF6B-E115-AEE0-A0A05404C8D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{000D8166-FF6B-E115-AEE0-A0A05404C8D8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {60A98D90-ADE4-44B7-B094-64DB371D3B67}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Apply_Custom_Font_For_TOC_Headings</RootNamespace>
</PropertyGroup>

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

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



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

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIORenderer;
using System.IO;

namespace Apply_Custom_Font_For_TOC_Headings
{
class Program
{
static void Main(string[] args)
{
//Creates a new Word document
using (WordDocument document = new WordDocument())
{
//Adds the section into the Word document.
IWSection section = document.AddSection();
string paraText = "AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company.";
//Adds the paragraph into the created section.
IWParagraph paragraph = section.AddParagraph();
//Appends the TOC field with LowerHeadingLevel and UpperHeadingLevel to determines the TOC entries.
paragraph.AppendTOC(1, 3);
//Adds the section into the Word document.
section = document.AddSection();
//Adds the paragraph into the created section.
paragraph = section.AddParagraph();
//Adds the text for the headings.
IWTextRange textRange = paragraph.AppendText("First Chapter");
//Apply character formatong to the text ranges.
textRange.CharacterFormat.FontName = "Calibri";
textRange.CharacterFormat.FontSize = 15;
//Sets a built-in heading style.
paragraph.ApplyStyle(BuiltinStyle.Heading1);
//Gets the paragrapg style.
IWParagraphStyle style = paragraph.GetStyle();
style.CharacterFormat.ClearFormatting();
//Adds the text into the paragraph.
IWParagraph firstParagraph = section.AddParagraph();
IWTextRange text = firstParagraph.AppendText(paraText);
//Sets font name and size for the paragraphs.
text.CharacterFormat.FontName = "Calibri";
text.CharacterFormat.FontSize = 12;
//Adds the section into the Word document.
section = document.AddSection();
//Adds the paragraph into the created section.
paragraph = section.AddParagraph();
//Adds the text for the headings.
textRange = paragraph.AppendText("Second Chapter");
//Apply character formatong to the text ranges.
textRange.CharacterFormat.FontName = "Verdana";
textRange.CharacterFormat.FontSize = 15;
//Sets a built-in heading style.
paragraph.ApplyStyle(BuiltinStyle.Heading2);
style = paragraph.GetStyle();
style.CharacterFormat.ClearFormatting();
//Adds the text into the paragraph.
firstParagraph = section.AddParagraph();
text = firstParagraph.AppendText(paraText);
text.CharacterFormat.FontName = "Verdana";
text.CharacterFormat.FontSize = 12;
//Adds the section into the Word document.
section = document.AddSection();
//Adds the paragraph into the created section.
paragraph = section.AddParagraph();
//Adds the text into the headings.
textRange = paragraph.AppendText("Third Chapter");
//Apply character formatong to the text ranges.
textRange.CharacterFormat.FontName = "Calibri";
textRange.CharacterFormat.FontSize = 15;
//Sets a built-in heading style.
paragraph.ApplyStyle(BuiltinStyle.Heading3);
style = paragraph.GetStyle();
style.CharacterFormat.ClearFormatting();
//Adds the text into the paragraph.
firstParagraph = section.AddParagraph();
text = firstParagraph.AppendText(paraText);
text.CharacterFormat.FontName = "Calibri";
text.CharacterFormat.FontSize = 12;
//Updates the table of contents.
document.UpdateTableOfContents();
//Save and close the Word document.
document.Save(Path.GetFullPath("../../../Output/Output.docx"));
}
}
}
}
Loading