Skip to content

Commit 8233c28

Browse files
Merge pull request #508 from SyncfusionExamples/965408-Add-Sample-for-Cloned-and-add-table-row-with-restart-numbered-list
965408 - Add sample for cloned table row with restart list numbering
2 parents 131e103 + c9f3deb commit 8233c28

5 files changed

Lines changed: 97 additions & 0 deletions

File tree

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.36518.9 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cloned-and-add-table-row-with-restart-numbered-list", "Cloned-and-add-table-row-with-restart-numbered-list\Cloned-and-add-table-row-with-restart-numbered-list.csproj", "{78E727C6-B0F8-43EF-91CA-FCBD28CE9A70}"
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+
{78E727C6-B0F8-43EF-91CA-FCBD28CE9A70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{78E727C6-B0F8-43EF-91CA-FCBD28CE9A70}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{78E727C6-B0F8-43EF-91CA-FCBD28CE9A70}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{78E727C6-B0F8-43EF-91CA-FCBD28CE9A70}.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 = {1444F73B-CB15-4B82-A264-556FD70226DE}
24+
EndGlobalSection
25+
EndGlobal
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>Cloned_and_add_table_row_with_restart_numbered_list</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\Input.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Syncfusion.DocIO.DLS;
2+
3+
namespace Cloned_and_add_table_row_with_restart_numbered_list
4+
{
5+
class Program
6+
{
7+
public static void Main(string[] args)
8+
{
9+
// Load the existing Word document
10+
WordDocument document = new WordDocument(Path.GetFullPath(@"Data\Input.docx"));
11+
// Retrieve the first table from the last section of the document
12+
WTable table = (WTable)document.LastSection.Tables[0];
13+
// Clone the second row (index 1) of the table
14+
WTableRow clonedRow = table.Rows[1].Clone();
15+
// Insert the cloned row back into the table at position 2 (after the original row)
16+
table.Rows.Insert(2, clonedRow);
17+
// Iterate through all cells in the newly inserted row (row index 2)
18+
foreach (WTableCell cell in table.Rows[2].Cells)
19+
{
20+
// Flag to track whether the first list paragraph has been encountered
21+
bool isListStart = false;
22+
// Iterate through all paragraphs inside the current cell
23+
foreach (WParagraph paragraph in cell.Paragraphs)
24+
{
25+
// Check if paragraph is a list
26+
if (paragraph.ListFormat.ListType != ListType.NoList)
27+
{
28+
// If a list has already started, continue numbering to align with the existing list
29+
if (isListStart)
30+
paragraph.ListFormat.ContinueListNumbering();
31+
else
32+
{
33+
// Mark that the first list paragraph has been found
34+
isListStart = true;
35+
// Restart numbering for the first list paragraph in the cloned row
36+
paragraph.ListFormat.RestartNumbering = true;
37+
}
38+
}
39+
}
40+
}
41+
// Save the Word document
42+
document.Save(Path.GetFullPath("../../../Output/Output.docx"));
43+
// Close the Word document
44+
document.Close();
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)