Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-page-break-between-rows", "Add-page-break-between-rows\Add-page-break-between-rows.csproj", "{C03BB1D7-2D69-4CD7-8761-CC906E649E2C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C03BB1D7-2D69-4CD7-8761-CC906E649E2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C03BB1D7-2D69-4CD7-8761-CC906E649E2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C03BB1D7-2D69-4CD7-8761-CC906E649E2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C03BB1D7-2D69-4CD7-8761-CC906E649E2C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Add_page_break_between_rows</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\Template.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;

namespace Add_page_break_between_rows
{
internal class Program
{
static void Main(string[] args)
{
// Load the Word document from the specified file path.
using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read))
{
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
{
// Access the table from the specified index in the document's body.
WTable table = document.Sections[0].Body.ChildEntities[4] as WTable;

// Check if the table contains 2 or more rows.
if (table != null && table.Rows.Count >= 2)
{
// Clone and remove the first row of the table.
WTableRow clonedRow = table.Rows[0].Clone();
table.Rows.RemoveAt(0);

// Get the text body of the table.
WTextBody documentBody = table.OwnerTextBody;

// Determine the index of the current table in the document body.
int currentTableIndex = documentBody.ChildEntities.IndexOf(table);

// Create a new paragraph and add a page break.
WParagraph pageBreakParagraph = new WParagraph(document);
pageBreakParagraph.AppendBreak(BreakType.PageBreak);

// Insert the new paragraph (with page break) before the current table.
documentBody.ChildEntities.Insert(currentTableIndex, pageBreakParagraph);

// Create a new table and insert it before the page break paragraph.
WTable newTable = new WTable(document);
documentBody.ChildEntities.Insert(currentTableIndex, newTable);

// Add the cloned row to the newly created table.
newTable.Rows.Add(clonedRow);
}
// Save the modified document to the specified file path.
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.Write))
{
document.Save(outputStream, FormatType.Docx);
}
}
}
}
}
}

Loading