Skip to content
Open
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,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.37614.0 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Insert-Page-Break-Inside-Tables", "Insert-Page-Break-Inside-Tables\Insert-Page-Break-Inside-Tables.csproj", "{8FCDCDE2-4309-88B1-9269-5EFFE148B495}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8FCDCDE2-4309-88B1-9269-5EFFE148B495}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8FCDCDE2-4309-88B1-9269-5EFFE148B495}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FCDCDE2-4309-88B1-9269-5EFFE148B495}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FCDCDE2-4309-88B1-9269-5EFFE148B495}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6016CC04-B8A1-4DBF-82A4-5A433FE516DE}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Insert_Page_Break_Inside_Tables</RootNamespace>
</PropertyGroup>

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

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



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

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Syncfusion.DocIO.DLS;
using System.IO;

namespace Insert_Page_Break_Inside_Tables
{
class Program
{
static void Main(string[] args)
{
// Creates a new Word document.
using (WordDocument document = new WordDocument())
{
// Adds a default section and paragraph to the document.
document.EnsureMinimal();

//Adds a new Table to the text body.
WTable table = document.LastSection.Body.AddTable() as WTable;

//Insert rows to the table. This will apply the format to a whole table.
table.ResetCells(5, 5);

// Sample text collection used to populate table cells.
string[] randomTexts =
{
"Lorem ipsum dolor sit amet",
"Syncfusion DocIO library",
"Word document processing",
"Table cell sample text",
"Page break demonstration",
"Random content generation",
"Document automation example",
"Text inside table row",
"Sample paragraph content",
"Testing table layout"
};
// Populate each table cell with sample text.
for (int i = 0; i < table.Rows.Count; i++)
{
WTableRow row = table.Rows[i];

for (int j = 0; j < row.Cells.Count; j++)
{
// Add a paragraph to the current cell.
WParagraph paragraph = row.Cells[j].AddParagraph() as WParagraph;

// Add random text
paragraph.AppendText(randomTexts[(i * row.Cells.Count + j) % randomTexts.Length]);
}
}
// Insert page breaks between table rows.
InserPageBreak(table);
//saves the document
document.Save(Path.GetFullPath("Output/Output.docx"));
}
}

/// <summary>
/// Inserts page break into the tablecell
/// </summary>
/// <param name="table"></param>
private static void InserPageBreak(WTable table)
{
int i = 1;
while (i < table.Rows.Count)
{
//To get the owner textbody of the table
WTextBody body = table.Owner as WTextBody;
//Adds an empty paragraph and insert the pagebreak
body.AddParagraph().AppendBreak(Syncfusion.DocIO.DLS.BreakType.PageBreak);
//Add the new table to the owner textbody
WTable pageBreaktable = body.AddTable() as WTable;
//Moves the row to the new table
WTableRow row = table.Rows[i] as WTableRow;
pageBreaktable.Rows.Add(row);
}
}
}
}
Loading