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.37314.3 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Split_a_TableRow_into_MultipleRows", "Split_a_TableRow_into_MultipleRows\Split_a_TableRow_into_MultipleRows.csproj", "{D01A3F0E-108B-E548-A652-9AEE28B61554}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D01A3F0E-108B-E548-A652-9AEE28B61554}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D01A3F0E-108B-E548-A652-9AEE28B61554}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D01A3F0E-108B-E548-A652-9AEE28B61554}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D01A3F0E-108B-E548-A652-9AEE28B61554}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CA9E1F07-F169-4D63-89BE-F5457051D1E7}
EndGlobalSection
EndGlobal
Binary file not shown.
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,38 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;

//Open an existing Word document.
using (FileStream fileStreamPath = new FileStream(@"../../../Data/Input.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
// Load the file stream
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
//Get the table from a Word document.
WTable table = document.Sections[0].Tables[0] as WTable;
//Split the row into required number of rows
ConvertOneRowIntoMultipleRows(table, 5, 3);
//Save a Word document.
using (FileStream outputStream = new FileStream(@"../../../Output/Result.docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
document.Save(outputStream, FormatType.Docx);
}
}
}


static void ConvertOneRowIntoMultipleRows(WTable table, int rowIndex, int numberOfLines)
{
for (int i = numberOfLines; i > 0; i--)
{
//Clone the row.
WTableRow row = table.Rows[rowIndex - 1].Clone();
    //Iterate all cells in a row and clear the contents.
    for (int j = 0; j < row.Cells.Count; j++)
{
WTableCell tableCell = row.Cells[j];
tableCell.ChildEntities.Clear();
}
//Insert the cloned row in the required index
table.Rows.Insert(rowIndex, row);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

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