diff --git a/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables.sln b/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables.sln new file mode 100644 index 00000000..304a3b7e --- /dev/null +++ b/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables.sln @@ -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 diff --git a/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables/Insert-Page-Break-Inside-Tables.csproj b/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables/Insert-Page-Break-Inside-Tables.csproj new file mode 100644 index 00000000..5ebe53ca --- /dev/null +++ b/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables/Insert-Page-Break-Inside-Tables.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + Insert_Page_Break_Inside_Tables + + + + + Always + + + + + + + + + + diff --git a/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables/Output/.gitkeep b/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables/Output/.gitkeep new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables/Output/Output.docx b/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables/Output/Output.docx new file mode 100644 index 00000000..0506f882 Binary files /dev/null and b/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables/Output/Output.docx differ diff --git a/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables/Program.cs b/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables/Program.cs new file mode 100644 index 00000000..6c34d9e6 --- /dev/null +++ b/Tables/Insert-Page-Break-Inside-Tables/.NET/Insert-Page-Break-Inside-Tables/Program.cs @@ -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")); + } + } + + /// + /// Inserts page break into the tablecell + /// + /// + 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); + } + } + } +}