Skip to content

Commit 99a31d7

Browse files
Merge pull request #246 from VijayadharshiniMathiyalagan/main
Added Sample for replace cell content
2 parents ecc8403 + 01995e5 commit 99a31d7

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35309.182
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-cell-content", "Replace-cell-content\Replace-cell-content.csproj", "{EE3F9583-BEBA-4C9C-B8F2-D395B3A083AF}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{EE3F9583-BEBA-4C9C-B8F2-D395B3A083AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EE3F9583-BEBA-4C9C-B8F2-D395B3A083AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EE3F9583-BEBA-4C9C-B8F2-D395B3A083AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EE3F9583-BEBA-4C9C-B8F2-D395B3A083AF}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {97EA4ED6-8BFF-4FE4-9D48-298CDAFC3065}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
using (FileStream inputFileStream = new FileStream(Path.GetFullPath("Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite))
5+
{
6+
//Open the template Word document.
7+
using (WordDocument document = new WordDocument(inputFileStream, FormatType.Docx))
8+
{
9+
//Retrieve the first section of the document.
10+
IWSection section = document.LastSection;
11+
//Get the first table in the section.
12+
WTable table = section.Body.Tables[0] as WTable;
13+
//Access the instance of the cell (second row, second cell).
14+
WTableCell cell1 = table[1, 1];
15+
//Access the instance of the cell (third row, third cell).
16+
WTableCell cell2 = table[2, 2];
17+
//Clear the contents of the cell (second row, second cell).
18+
cell1.ChildEntities.Clear();
19+
//Add a new paragraph with content to the cell (second row, second cell).
20+
cell1.AddParagraph().AppendText("Adventure");
21+
//Clear the contents of the cell (third row, third cell).
22+
cell2.ChildEntities.Clear();
23+
//Add a new paragraph with content to the cell (third row, third cell).
24+
cell2.AddParagraph().AppendText("Cycle");
25+
//Save the modified document.
26+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath("Output/Result.docx"), FileMode.Create, FileAccess.Write))
27+
{
28+
document.Save(outputFileStream, FormatType.Docx);
29+
}
30+
}
31+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Replace_Cell_Content</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Template.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>

0 commit comments

Comments
 (0)