Skip to content

Commit 24cace9

Browse files
ES-879113-How-to-find-a-table-by-title-in-a-Word-document-and-add-a-row - Added sample
1 parent 01995e5 commit 24cace9

File tree

7 files changed

+33
-40
lines changed

7 files changed

+33
-40
lines changed

Tables/Replace-cell-content/.NET/Replace-cell-content.sln renamed to Tables/Find-table-and-add-row/Find-table-and-add-row.sln

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.12.35309.182
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-cell-content", "Replace-cell-content\Replace-cell-content.csproj", "{EE3F9583-BEBA-4C9C-B8F2-D395B3A083AF}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-table-and-add-row", "Find-table-and-add-row\Find-table-and-add-row.csproj", "{E8C23293-ABC9-4C54-81BA-9C5FBA6D85C1}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
1111
Release|Any CPU = Release|Any CPU
1212
EndGlobalSection
1313
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14-
{EE3F9583-BEBA-4C9C-B8F2-D395B3A083AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15-
{EE3F9583-BEBA-4C9C-B8F2-D395B3A083AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16-
{EE3F9583-BEBA-4C9C-B8F2-D395B3A083AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17-
{EE3F9583-BEBA-4C9C-B8F2-D395B3A083AF}.Release|Any CPU.Build.0 = Release|Any CPU
14+
{E8C23293-ABC9-4C54-81BA-9C5FBA6D85C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E8C23293-ABC9-4C54-81BA-9C5FBA6D85C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E8C23293-ABC9-4C54-81BA-9C5FBA6D85C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E8C23293-ABC9-4C54-81BA-9C5FBA6D85C1}.Release|Any CPU.Build.0 = Release|Any CPU
1818
EndGlobalSection
1919
GlobalSection(SolutionProperties) = preSolution
2020
HideSolutionNode = FALSE
2121
EndGlobalSection
2222
GlobalSection(ExtensibilityGlobals) = postSolution
23-
SolutionGuid = {97EA4ED6-8BFF-4FE4-9D48-298CDAFC3065}
23+
SolutionGuid = {EC6BCFD8-E759-47DE-BC97-AC492B3D6DF8}
2424
EndGlobalSection
2525
EndGlobal
Binary file not shown.

Tables/Replace-cell-content/.NET/Replace-cell-content/Replace-cell-content.csproj renamed to Tables/Find-table-and-add-row/Find-table-and-add-row/Find-table-and-add-row.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net8.0</TargetFramework>
6-
<RootNamespace>Replace_Cell_Content</RootNamespace>
6+
<RootNamespace>Find_table_and_add_row</RootNamespace>
77
<ImplicitUsings>enable</ImplicitUsings>
88
<Nullable>enable</Nullable>
99
</PropertyGroup>
@@ -13,12 +13,12 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<None Update="Data\Template.docx">
16+
<None Update="Data\Input.docx">
1717
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
1818
</None>
1919
<None Update="Output\.gitkeep">
2020
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2121
</None>
2222
</ItemGroup>
23-
23+
2424
</Project>

Tables/Replace-cell-content/.NET/Replace-cell-content/Output/.gitkeep renamed to Tables/Find-table-and-add-row/Find-table-and-add-row/Output/.gitkeep

File renamed without changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
using (FileStream inputFileStream = new FileStream(Path.GetFullPath("Data/Input.docx"), FileMode.Open, FileAccess.ReadWrite))
5+
{
6+
// Open the input Word document.
7+
using (WordDocument document = new WordDocument(inputFileStream, FormatType.Docx))
8+
{
9+
//Find a table by Title.
10+
WTable table = document.FindItemByProperty(EntityType.Table, "Title", "DataTable") as WTable;
11+
// Check if the table exists.
12+
if (table != null)
13+
{
14+
// Add a new row to the table.
15+
table.AddRow();
16+
}
17+
18+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath("Output/Result.docx"), FileMode.Create, FileAccess.Write))
19+
{
20+
// Save the modified document to the output file stream.
21+
document.Save(outputFileStream, FormatType.Docx);
22+
}
23+
}
24+
}
Binary file not shown.

Tables/Replace-cell-content/.NET/Replace-cell-content/Program.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)