Skip to content

Commit cde0f17

Browse files
Added sample to retrieve list values for a specific heading in a Word document
1 parent 9f2d2d7 commit cde0f17

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 16
4+
VisualStudioVersion = 16.0.31911.196
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Get-heading-list-value", "Get-heading-list-value\Get-heading-list-value.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}"
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+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.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 = {EF357FC6-E9E5-4E3C-B932-43F727BE1DE4}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Get_heading_list_value</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Data\Template.docx">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Output\.gitkeep">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using System.Collections.Generic;
4+
using System;
5+
using System.IO;
6+
7+
namespace Get_heading_list_value
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
14+
{
15+
//Open an existing Word document from the file stream.
16+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
17+
{
18+
//Get the document text.
19+
document.GetText();
20+
//Find all paragraphs with the style 'Heading 3' in the Word document.
21+
List<Entity> headingParagraphs = document.FindAllItemsByProperty(EntityType.Paragraph, "StyleName", "Heading 3");
22+
if (headingParagraphs.Count == 0)
23+
Console.WriteLine("No paragraphs with the style 'Heading 3' found.");
24+
else
25+
{
26+
foreach (Entity paragraph in headingParagraphs)
27+
{
28+
//Get the string that represents the appearance of list value of the paragraph.
29+
if (paragraph is WParagraph)
30+
Console.WriteLine((paragraph as WParagraph).ListString);
31+
else
32+
Console.WriteLine("The entity is not a WParagraph.");
33+
}
34+
}
35+
//Pauses the console to display the output.
36+
Console.ReadLine();
37+
}
38+
}
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)