Skip to content

Commit aa35664

Browse files
Added sample
1 parent 1cfc871 commit aa35664

7 files changed

Lines changed: 119 additions & 0 deletions

File tree

Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
<ItemGroup>
15+
<None Update="Data\Template.docx">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
<None Update="Output\.gitkeep">
19+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20+
</None>
21+
</ItemGroup>
22+
23+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<_LastSelectedProfileId>D:\Nuget\NugetCheck\NugetCheck\Properties\PublishProfiles\ClickOnceProfile.pubxml</_LastSelectedProfileId>
5+
</PropertyGroup>
6+
</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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
namespace Extract_Selected_CheckBox
5+
{
6+
class Program
7+
{
8+
9+
static void Main(string[] args)
10+
{
11+
List<string> questionList = new List<string>();
12+
//Load an existing Word document.
13+
using (WordDocument wordDocument = new WordDocument(Path.GetFullPath(@"../../../Data/Template.docx"), FormatType.Docx))
14+
{
15+
//Find all checkBoxes in the Word document.
16+
List<Entity> checkBoxes = wordDocument.FindAllItemsByProperty(EntityType.CheckBox, "Checked", "True");
17+
18+
19+
if (checkBoxes != null)
20+
{
21+
22+
foreach (WCheckBox checkBox in checkBoxes)
23+
{
24+
string paragraphText = "";
25+
WParagraph ownerParagraph = (checkBox.Owner as WParagraph);
26+
int index = ownerParagraph.ChildEntities.IndexOf(checkBox);
27+
//Extract the question information when checkBox is the first item of the paragraph.
28+
if (index == 0)
29+
{
30+
//Get the paragraph's item collection.
31+
ParagraphItemCollection paraItems = ownerParagraph.Items;
32+
// This boolean is used to avoid the checkBox in the extracted question information.
33+
bool isIgnoreCheckBoxItems = true;
34+
for (int i = 0; i < paraItems.Count; i++)
35+
{
36+
//Collect the question information from the paragraph.
37+
if (!isIgnoreCheckBoxItems)
38+
{
39+
switch (paraItems[i].EntityType)
40+
{
41+
case EntityType.TextRange:
42+
paragraphText += (paraItems[i] as WTextRange).Text;
43+
break;
44+
case EntityType.Break:
45+
paragraphText += (paraItems[i] as Break).BreakType is BreakType.LineBreak ? "\r\n" : "";
46+
break;
47+
48+
}
49+
}
50+
51+
if (paraItems[i] is WFieldMark && (paraItems[i] as WFieldMark).Type is FieldMarkType.FieldEnd)
52+
isIgnoreCheckBoxItems = false;
53+
}
54+
//Add the question information to the list collection.
55+
questionList.Add(paragraphText);
56+
}
57+
}
58+
}
59+
//Save the Word file.
60+
wordDocument.Save(Path.GetFullPath(@"../../../Output/Result.docx"));
61+
}
62+
}
63+
}
64+
}
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.14.37111.16 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Extract_Selected_CheckBox", "Extract-Selected-CheckBox\Extract_Selected_CheckBox.csproj", "{438F805B-D4F7-68E4-DC33-D141CB27C89B}"
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+
{438F805B-D4F7-68E4-DC33-D141CB27C89B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{438F805B-D4F7-68E4-DC33-D141CB27C89B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{438F805B-D4F7-68E4-DC33-D141CB27C89B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{438F805B-D4F7-68E4-DC33-D141CB27C89B}.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 = {29A935F8-ED49-416B-88E0-CB390B6A540D}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)