Skip to content

Commit 14bfd50

Browse files
ES-924937-remove-multiple-rows-from-table
1 parent 9b91872 commit 14bfd50

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-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}") = "Remove-multiple-rows-from-table", "Remove-multiple-rows-from-table\Remove-multiple-rows-from-table.csproj", "{38FB99D1-DB4A-4A3F-B90B-7135724337EF}"
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+
{38FB99D1-DB4A-4A3F-B90B-7135724337EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{38FB99D1-DB4A-4A3F-B90B-7135724337EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{38FB99D1-DB4A-4A3F-B90B-7135724337EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{38FB99D1-DB4A-4A3F-B90B-7135724337EF}.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 = {B75368E1-9546-4CD5-BE4C-5C905E8D16C2}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using System.IO;
4+
5+
namespace Remove_multiple_rows_from_table
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
// Open the template document from the specified file path.
12+
using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
13+
{
14+
// Load the Word document.
15+
using (WordDocument document = new WordDocument(inputFileStream, FormatType.Automatic))
16+
{
17+
// Access the first section of the document.
18+
WSection section = document.Sections[0];
19+
// Access the first table in the section.
20+
WTable table = section.Tables[0] as WTable;
21+
// Iterate through the table rows in reverse order to prevent index shifting issues.
22+
for (int i = table.Rows.Count - 1; i >= 0; i--)
23+
{
24+
// Remove specific rows based on index (e.g., rows at index 2, 5, and 7).
25+
if (i == 2 || i == 5 || i == 7)
26+
{
27+
WTableRow row = table.Rows[i];
28+
table.Rows.Remove(row);
29+
}
30+
}
31+
// Save the updated document to the output file.
32+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
33+
{
34+
document.Save(outputFileStream, FormatType.Docx);
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}
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>Remove_multiple_rows_from_table</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>

0 commit comments

Comments
 (0)