-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #319 from SyncfusionExamples/881815-Add-page-break…
…-between-rows 881815-Add the sample Add-page-break-between-rows in Tables
- Loading branch information
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
Tables/Add-page-break-between-rows/.NET/Add-page-break-between-rows.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
24 changes: 24 additions & 0 deletions
24
...ge-break-between-rows/.NET/Add-page-break-between-rows/Add-page-break-between-rows.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+155 KB
Tables/Add-page-break-between-rows/.NET/Add-page-break-between-rows/Data/Template.docx
Binary file not shown.
1 change: 1 addition & 0 deletions
1
Tables/Add-page-break-between-rows/.NET/Add-page-break-between-rows/Output/.gitkeep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
55 changes: 55 additions & 0 deletions
55
Tables/Add-page-break-between-rows/.NET/Add-page-break-between-rows/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|