Skip to content

Commit 796c44a

Browse files
committed
ES-963148 : Add Samples
1 parent 8723130 commit 796c44a

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-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.13.35919.96 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-or-remove-column-in-a-table", "Add-or-remove-column-in-a-table\Add-or-remove-column-in-a-table.csproj", "{CB9481DB-1AD2-4432-B868-5AABFF5E0092}"
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+
{CB9481DB-1AD2-4432-B868-5AABFF5E0092}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{CB9481DB-1AD2-4432-B868-5AABFF5E0092}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{CB9481DB-1AD2-4432-B868-5AABFF5E0092}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{CB9481DB-1AD2-4432-B868-5AABFF5E0092}.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 = {F8A4CC44-1AC3-4919-AFA8-63AA0BBBAABA}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Add_or_remove_column_in_a_table</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Template.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
4+
namespace Add_or_remove_column_in_a_table
5+
{
6+
class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
// Load the Word document
11+
using (WordDocument document = new WordDocument(Path.GetFullPath(@"Data/Template.docx")))
12+
{
13+
// Access the first table in the document
14+
WTable table = (WTable)document.Sections[0].Tables[0];
15+
// Add a new column at index
16+
AddColumn(table, 2);
17+
// Remove a column at the index
18+
RemoveColumn(table, 1);
19+
// Save the modified document to a new file
20+
document.Save(Path.GetFullPath(@"Output/Result.docx"), FormatType.Docx);
21+
}
22+
}
23+
/// <summary>
24+
/// Adds a new column at the specified index in the table.
25+
/// </summary>
26+
/// <param name="table">The table to modify.</param>
27+
/// <param name="indexToAdd">The index at which to insert the new column.</param>
28+
private static void AddColumn(WTable table, int indexToAdd)
29+
{
30+
// Loop through each row in the table
31+
for (int i = 0; i < table.Rows.Count; i++)
32+
{
33+
// Check if the index is within the valid range for the current row
34+
if (indexToAdd >= 0 && indexToAdd <= table.Rows[i].Cells.Count)
35+
{
36+
// Create a new cell.
37+
WTableCell newCell = new WTableCell(table.Document);
38+
// Insert the new cell at the specified index in the current row
39+
table.Rows[i].Cells.Insert(indexToAdd, newCell);
40+
}
41+
}
42+
}
43+
/// <summary>
44+
/// Removes a column at the specified index from the table.
45+
/// </summary>
46+
/// <param name="table">The table to modify.</param>
47+
/// <param name="indexToRemove">The index of the column to remove.</param>
48+
private static void RemoveColumn(WTable table, int indexToRemove)
49+
{
50+
// Loop through each row in the table
51+
for (int i = 0; i < table.Rows.Count; i++)
52+
{
53+
// Check if the index is within the valid range for the current row
54+
if (indexToRemove >= 0 && indexToRemove < table.Rows[i].Cells.Count)
55+
{
56+
// Remove the cell at the specified index in the current row
57+
table.Rows[i].Cells.RemoveAt(indexToRemove);
58+
}
59+
}
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)