Skip to content

Commit 7779e83

Browse files
author
Konduru Keerthi Konduru Ravichandra Raju
committed
Table of Contents
1 parent 7ebbdaa commit 7779e83

File tree

6 files changed

+81
-0
lines changed

6 files changed

+81
-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.10.34928.147
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add_toc_in_merged_documents", "Add_toc_in_merged_documents\Add_toc_in_merged_documents.csproj", "{78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}"
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+
{78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{78D9D0A1-4467-4A3C-8C45-3F90EE69EC36}.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 = {CF8B010D-A0FC-4D30-8767-8B601222372E}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
12+
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
using Syncfusion.DocIORenderer;
4+
5+
//Get the Source document names from the folder.
6+
string[] sourceDocumentNames = Directory.GetFiles(@"../../../Data/");
7+
8+
//Create an WordDocumentinstance for destination document.
9+
using (WordDocument destinationDocument = new WordDocument())
10+
{
11+
//Add an section and paragraph to the destination document.
12+
IWSection section = destinationDocument.AddSection();
13+
IWParagraph paragraph = section.AddParagraph();
14+
//Appends the TOC field with LowerHeadingLevel and UpperHeadingLevel to determines the TOC entries.
15+
paragraph.AppendTOC(1, 3);
16+
17+
//Merge each source document to the destination document.
18+
foreach (string subDocumentName in sourceDocumentNames)
19+
{
20+
//Open the source document files as a stream.
21+
using (FileStream sourceDocumentPathStream = new FileStream(Path.GetFullPath(subDocumentName), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
22+
{
23+
//Open the source documents.
24+
using (WordDocument sourceDocument = new WordDocument(sourceDocumentPathStream, FormatType.Docx))
25+
{
26+
//Sets the break-code of First section of source document as NoBreak to avoid imported from a new page
27+
sourceDocument.Sections[0].BreakCode = SectionBreakCode.NoBreak;
28+
//Imports the contents of source document at the end of destination document
29+
destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles);
30+
}
31+
}
32+
}
33+
34+
//Updates the table of contents
35+
destinationDocument.UpdateTableOfContents();
36+
//Save the destination document.
37+
using (FileStream outputStream = new FileStream(@"../../../Output.docx", FileMode.Create, FileAccess.Write))
38+
{
39+
destinationDocument.Save(outputStream, FormatType.Docx);
40+
}
41+
}

0 commit comments

Comments
 (0)