-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sample for insert content of the Word document into Block content control #292
Open
VijayadharshiniMathiyalagan
wants to merge
1
commit into
SyncfusionExamples:main
Choose a base branch
from
VijayadharshiniMathiyalagan:ES-891648-How-to-insert-the-content-of-a-docx-document-into-a-BlockContentControl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...s/Insert-content-into-block-content-control/Insert-content-into-block-content-control.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,25 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.136 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Insert-content-into-block-content-control", "Insert-content-into-block-content-control\Insert-content-into-block-content-control.csproj", "{AE9996D9-17F0-4A69-AB1D-CA10E8605CF7}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{AE9996D9-17F0-4A69-AB1D-CA10E8605CF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{AE9996D9-17F0-4A69-AB1D-CA10E8605CF7}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{AE9996D9-17F0-4A69-AB1D-CA10E8605CF7}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{AE9996D9-17F0-4A69-AB1D-CA10E8605CF7}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {2D02C5F8-31E9-4F9E-96E9-D370D58B7826} | ||
EndGlobalSection | ||
EndGlobal |
Binary file added
BIN
+44 KB
...t-into-block-content-control/Insert-content-into-block-content-control/Data/Template.docx
Binary file not shown.
22 changes: 22 additions & 0 deletions
22
...nsert-content-into-block-content-control/Insert-content-into-block-content-control.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,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>Insert_Word_document_in_block_content_control</RootNamespace> | ||
</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> |
1 change: 1 addition & 0 deletions
1
...tent-into-block-content-control/Insert-content-into-block-content-control/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 @@ | ||
|
40 changes: 40 additions & 0 deletions
40
...t-content-into-block-content-control/Insert-content-into-block-content-control/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,40 @@ | ||
using System.IO; | ||
using Syncfusion.DocIO; | ||
using Syncfusion.DocIO.DLS; | ||
|
||
// Creates a new Word document. | ||
using (WordDocument document = new WordDocument()) | ||
{ | ||
// Adds new section to the document. | ||
IWSection section = document.AddSection(); | ||
WTextBody textBody = section.Body; | ||
// Adds block content control into Word document. | ||
BlockContentControl blockContentControl = textBody.AddBlockContentControl(ContentControlType.RichText) as BlockContentControl; | ||
using (FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read)) | ||
{ | ||
// Open the template Word document. | ||
using (WordDocument docxDocument = new WordDocument(docStream, FormatType.Docx)) | ||
{ | ||
// Insert the Word document into block content control. | ||
InsertContentIntoBlockContentControl(blockContentControl, docxDocument); | ||
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) | ||
{ | ||
// Saves the Word document. | ||
document.Save(outputFileStream, FormatType.Docx); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Inserts the content of a specified Word document into a block content control. | ||
/// </summary> | ||
void InsertContentIntoBlockContentControl(BlockContentControl blockContentControl, WordDocument document) | ||
{ | ||
// Get the textbody of the another Word document and add it to the block content control. | ||
WTextBody textBody = document.LastSection.Body; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Iterate all sections of document and perform the same for all textbody items |
||
foreach (IEntity entity in textBody.ChildEntities) | ||
{ | ||
blockContentControl.TextBody.ChildEntities.Add(entity.Clone()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Insert Word document in content control -- Change the sample name like this