forked from SyncfusionExamples/DocIO-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SyncfusionExamples:main' into main
- Loading branch information
Showing
413 changed files
with
307,431 additions
and
70 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...ce-picture-content-control-with-chart/.NET/Replace-picture-content-control-with-chart.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 Version 17 | ||
VisualStudioVersion = 17.9.34622.214 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-picture-content-control-with-chart", "Replace-picture-content-control-with-chart\Replace-picture-content-control-with-chart.csproj", "{3F42250C-E397-40D5-9F0B-AF60BE03A221}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{3F42250C-E397-40D5-9F0B-AF60BE03A221}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{3F42250C-E397-40D5-9F0B-AF60BE03A221}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{3F42250C-E397-40D5-9F0B-AF60BE03A221}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{3F42250C-E397-40D5-9F0B-AF60BE03A221}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {A3DDA0C7-80BA-4659-93A8-3C3DD692D5AB} | ||
EndGlobalSection | ||
EndGlobal |
Binary file added
BIN
+27 KB
...ontent-control-with-chart/.NET/Replace-picture-content-control-with-chart/Data/Input.docx
Binary file not shown.
145 changes: 145 additions & 0 deletions
145
...ure-content-control-with-chart/.NET/Replace-picture-content-control-with-chart/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,145 @@ | ||
using Syncfusion.DocIO.DLS; | ||
using Syncfusion.DocIO; | ||
using Syncfusion.DocIORenderer; | ||
using Syncfusion.OfficeChart; | ||
|
||
|
||
// Open the file as stream. | ||
using (FileStream docStream = new FileStream(Path.GetFullPath(@"../../../Data/Input.docx"), FileMode.Open)) | ||
{ | ||
// Load file stream into Word document. | ||
using (WordDocument document = new WordDocument(docStream, Syncfusion.DocIO.FormatType.Automatic)) | ||
{ | ||
string[] propertyNames = { "ContentControlProperties.Title", "ContentControlProperties.Type" }; | ||
string[] propertyValues = { "Chart", "Picture" }; | ||
// Find BlockContentControl by given properties | ||
BlockContentControl contentControl = document.FindItemByProperties(EntityType.BlockContentControl, propertyNames, propertyValues) as BlockContentControl; | ||
|
||
if (contentControl != null) | ||
{ | ||
int index = contentControl.OwnerTextBody.ChildEntities.IndexOf(contentControl); | ||
|
||
// Create a new paragraph to hold the chart image. | ||
WParagraph paragraph = new WParagraph(document); | ||
|
||
// Generate the chart and get it as an image stream. | ||
Stream chartImage = GenerateChartAndGetChartAsImage(); | ||
|
||
// Create a new image instance and load the chart image. | ||
WPicture picture = (WPicture)paragraph.AppendPicture(chartImage); | ||
|
||
// Set picture dimensions. | ||
picture.Height = 300; | ||
picture.Width = 300; | ||
|
||
// To replace Picture content Control insert Picture paragraph and remove the content control. | ||
contentControl.OwnerTextBody.ChildEntities.Insert(index, paragraph); | ||
contentControl.OwnerTextBody.ChildEntities.RemoveAt(index + 1); | ||
} | ||
|
||
|
||
// Create file stream for output document. | ||
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Data/Sample.docx"), FileMode.Create, FileAccess.ReadWrite)) | ||
{ | ||
// Save the Word document to the file stream. | ||
document.Save(outputFileStream, FormatType.Docx); | ||
} | ||
} | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Generates a chart and saves it as an image. | ||
/// </summary> | ||
/// <returns>A stream containing the chart image.</returns> | ||
static Stream GenerateChartAndGetChartAsImage() | ||
{ | ||
// Create a new Word document. | ||
using (WordDocument document = new WordDocument()) | ||
{ | ||
// Add a section to the document. | ||
IWSection section = document.AddSection(); | ||
// Add a paragraph to the section. | ||
IWParagraph paragraph = section.AddParagraph(); | ||
// Create and append the chart to the paragraph. | ||
WChart chart = paragraph.AppendChart(446, 270); | ||
|
||
// Set chart data. | ||
chart.ChartData.SetValue(1, 1, "Month"); | ||
chart.ChartData.SetValue(2, 1, "Jan"); | ||
chart.ChartData.SetValue(3, 1, "Feb"); | ||
chart.ChartData.SetValue(4, 1, "Mar"); | ||
chart.ChartData.SetValue(5, 1, "Apr"); | ||
chart.ChartData.SetValue(6, 1, "May"); | ||
chart.ChartData.SetValue(7, 1, "Jun"); | ||
chart.ChartData.SetValue(8, 1, "Jul"); | ||
chart.ChartData.SetValue(9, 1, "Aug"); | ||
chart.ChartData.SetValue(10, 1, "Sep"); | ||
chart.ChartData.SetValue(11, 1, "Oct"); | ||
chart.ChartData.SetValue(12, 1, "Nov"); | ||
chart.ChartData.SetValue(13, 1, "Dec"); | ||
chart.ChartData.SetValue(1, 2, "Rainy Days"); | ||
chart.ChartData.SetValue(2, 2, 12); | ||
chart.ChartData.SetValue(3, 2, 11); | ||
chart.ChartData.SetValue(4, 2, 10); | ||
chart.ChartData.SetValue(5, 2, 9); | ||
chart.ChartData.SetValue(6, 2, 8); | ||
chart.ChartData.SetValue(7, 2, 6); | ||
chart.ChartData.SetValue(8, 2, 4); | ||
chart.ChartData.SetValue(9, 2, 6); | ||
chart.ChartData.SetValue(10, 2, 7); | ||
chart.ChartData.SetValue(11, 2, 8); | ||
chart.ChartData.SetValue(12, 2, 10); | ||
chart.ChartData.SetValue(13, 2, 11); | ||
chart.ChartData.SetValue(1, 3, "Profit"); | ||
chart.ChartData.SetValue(2, 3, 3574); | ||
chart.ChartData.SetValue(3, 3, 4708); | ||
chart.ChartData.SetValue(4, 3, 5332); | ||
chart.ChartData.SetValue(5, 3, 6693); | ||
chart.ChartData.SetValue(6, 3, 8843); | ||
chart.ChartData.SetValue(7, 3, 12347); | ||
chart.ChartData.SetValue(8, 3, 15180); | ||
chart.ChartData.SetValue(9, 3, 11198); | ||
chart.ChartData.SetValue(10, 3, 9739); | ||
chart.ChartData.SetValue(11, 3, 9846); | ||
chart.ChartData.SetValue(12, 3, 6620); | ||
chart.ChartData.SetValue(13, 3, 5085); | ||
|
||
// Set region of chart data. | ||
chart.DataRange = chart.ChartData[1, 1, 13, 3]; | ||
// Set chart series in the column for assigned data region. | ||
chart.IsSeriesInRows = false; | ||
// Set chart title. | ||
chart.ChartTitle = "Combination Chart"; | ||
|
||
// Set data labels. | ||
IOfficeChartSerie series1 = chart.Series[0]; | ||
IOfficeChartSerie series2 = chart.Series[1]; | ||
// Set series type. | ||
series1.SerieType = OfficeChartType.Column_Clustered; | ||
series2.SerieType = OfficeChartType.Line; | ||
series2.UsePrimaryAxis = false; | ||
|
||
// Set data labels. | ||
series1.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; | ||
|
||
// Set legend. | ||
chart.HasLegend = true; | ||
chart.Legend.Position = OfficeLegendPosition.Bottom; | ||
|
||
// Set chart type. | ||
chart.ChartType = OfficeChartType.Combination_Chart; | ||
|
||
// Set secondary axis on right side. | ||
chart.SecondaryValueAxis.TickLabelPosition = OfficeTickLabelPosition.TickLabelPosition_High; | ||
|
||
// Create an instance of DocIORenderer. | ||
using (DocIORenderer renderer = new DocIORenderer()) | ||
{ | ||
// Convert chart to an image. | ||
Stream stream = chart.SaveAsImage(); | ||
return stream; | ||
} | ||
} | ||
} | ||
|
15 changes: 15 additions & 0 deletions
15
...lace-picture-content-control-with-chart/Replace-picture-content-control-with-chart.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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>Replace_picture_content_control_with_chart</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" /> | ||
</ItemGroup> | ||
|
||
</Project> |
25 changes: 25 additions & 0 deletions
25
...ace-with-multiple-list-paragraphs/.NET/Find-and-replace-with-multiple-list-paragraphs.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 Version 17 | ||
VisualStudioVersion = 17.8.34322.80 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-and-replace-with-multiple-list-paragraphs", "Find-and-replace-with-multiple-list-paragraphs\Find-and-replace-with-multiple-list-paragraphs.csproj", "{01BA5F87-72F1-4FA7-B85D-6768675A7DF2}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{01BA5F87-72F1-4FA7-B85D-6768675A7DF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{01BA5F87-72F1-4FA7-B85D-6768675A7DF2}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{01BA5F87-72F1-4FA7-B85D-6768675A7DF2}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{01BA5F87-72F1-4FA7-B85D-6768675A7DF2}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {BD00CDA9-FEA5-4C54-B803-39A387358F68} | ||
EndGlobalSection | ||
EndGlobal |
Binary file added
BIN
+81.1 KB
...st-paragraphs/.NET/Find-and-replace-with-multiple-list-paragraphs/Data/Heading1Items.docx
Binary file not shown.
Binary file added
BIN
+74.5 KB
...st-paragraphs/.NET/Find-and-replace-with-multiple-list-paragraphs/Data/Heading2Items.docx
Binary file not shown.
Binary file added
BIN
+15.9 KB
...tiple-list-paragraphs/.NET/Find-and-replace-with-multiple-list-paragraphs/Data/Input.docx
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
...place-with-multiple-list-paragraphs/Find-and-replace-with-multiple-list-paragraphs.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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>Find_and_replace_with_multiple_list_paragraphs</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" /> | ||
</ItemGroup> | ||
|
||
</Project> |
109 changes: 109 additions & 0 deletions
109
...h-multiple-list-paragraphs/.NET/Find-and-replace-with-multiple-list-paragraphs/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,109 @@ | ||
using Syncfusion.DocIO; | ||
using Syncfusion.DocIO.DLS; | ||
using System.Reflection.Metadata; | ||
|
||
|
||
string[] filePaths = {"../../../Data/Heading1Items.docx","../../../Data/Heading2Items.docx"}; | ||
//Open the file as Stream. | ||
using (FileStream documentStream = new FileStream("../../../Data/Input.docx", FileMode.Open, FileAccess.Read)) | ||
{ | ||
//Open an existing Word document. | ||
using (WordDocument document = new WordDocument(documentStream, FormatType.Docx)) | ||
{ | ||
for(int documentIndex = 1; documentIndex <= filePaths.Length; documentIndex++) | ||
{ | ||
//String to be found. | ||
string findText = "<<Heading"+ documentIndex + "Items>>"; | ||
//Find the selection in the document. | ||
TextSelection selection = document.Find(findText, false, false); | ||
//Get the owner paragraph. | ||
WParagraph ownerPara = selection.GetAsOneRange().OwnerParagraph; | ||
//Open the file as Stream. | ||
using (FileStream subDocumentStream = new FileStream(filePaths[documentIndex-1], FileMode.Open, FileAccess.Read)) | ||
{ | ||
//Open an sub Word document. | ||
using (WordDocument subDocument = new WordDocument(subDocumentStream, FormatType.Docx)) | ||
{ | ||
//Create a text body part to be replaced. | ||
TextBodyPart textBodyPart = CreateBodyPart(subDocument, ownerPara); | ||
//Replace the text with the created text body part. | ||
document.Replace(findText, textBodyPart, true, true); | ||
} | ||
} | ||
} | ||
|
||
//Save the Word document. | ||
using (FileStream output = new FileStream("../../../Result.docx", FileMode.Create, FileAccess.Write)) | ||
{ | ||
document.Save(output, FormatType.Docx); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Create body parts that need to be replaced in the Word document. | ||
/// </summary> | ||
/// <param name="subDocument">Document contains the paragraph which need to be replace</param> | ||
/// <param name="ownerPara">The paragraph that needs to be copied.</param> | ||
TextBodyPart CreateBodyPart(WordDocument subDocument, WParagraph ownerPara) | ||
{ | ||
//Creates new text body part. | ||
TextBodyPart bodyPart = new TextBodyPart(ownerPara.Document); | ||
//Iterate each section of the Word document. | ||
foreach (WSection section in subDocument.Sections) | ||
{ | ||
//Accesses the Body of section where all the contents in document are apart | ||
WTextBody sectionBody = section.Body; | ||
IterateTextBody(sectionBody, ownerPara, bodyPart); | ||
} | ||
return bodyPart; | ||
} | ||
/// <summary> | ||
/// Iterates textbody child elements. | ||
/// </summary> | ||
void IterateTextBody(WTextBody sectionTextBody, WParagraph ownerPara, TextBodyPart bodyPart) | ||
{ | ||
//Iterates through each of the child items of WTextBody | ||
for (int i = 0; i < sectionTextBody.ChildEntities.Count; i++) | ||
{ | ||
//IEntity is the basic unit in DocIO DOM. | ||
//Accesses the body items (should be either paragraph, table or block content control) as IEntity | ||
IEntity bodyItemEntity = sectionTextBody.ChildEntities[i]; | ||
//A Text body has 3 types of elements - Paragraph, Table and Block Content Control | ||
//Decides the element type by using EntityType | ||
switch (bodyItemEntity.EntityType) | ||
{ | ||
case EntityType.Paragraph: | ||
WParagraph paragraph = bodyItemEntity as WParagraph; | ||
AddParagraphItemsToTextBody (paragraph, ownerPara, bodyPart); | ||
break; | ||
case EntityType.Table: | ||
//Add to text body part. | ||
bodyPart.BodyItems.Add(bodyItemEntity.Clone()); | ||
break; | ||
case EntityType.BlockContentControl: | ||
BlockContentControl blockContentControl = bodyItemEntity as BlockContentControl; | ||
//Iterates to the body items of Block Content Control. | ||
IterateTextBody(blockContentControl.TextBody, ownerPara, bodyPart); | ||
break; | ||
} | ||
} | ||
} | ||
/// <summary> | ||
/// Add the paragraph items to the text body part. | ||
/// </summary> | ||
void AddParagraphItemsToTextBody(WParagraph paragraph, WParagraph ownerPara, TextBodyPart bodyPart) | ||
{ | ||
//Clone the paragraph. | ||
WParagraph paratoInsert = ownerPara.Clone() as WParagraph; | ||
//Clear the paragraph's items. | ||
paratoInsert.ChildEntities.Clear(); | ||
//Iterate the items of the paragraph. | ||
for (int paraItemIndex = 0; paraItemIndex < paragraph.ChildEntities.Count; paraItemIndex++) | ||
{ | ||
//Add the paragraph items. | ||
paratoInsert.ChildEntities.Add(paragraph.ChildEntities[paraItemIndex].Clone()); | ||
} | ||
//Add to text body part. | ||
bodyPart.BodyItems.Add(paratoInsert.Clone()); | ||
} |
25 changes: 25 additions & 0 deletions
25
Mail-Merge/Mail-merge-with-JSON/.NET/Mail-merge-with-JSON.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 Version 16 | ||
VisualStudioVersion = 16.0.31911.196 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mail-merge-with-JSON", "Mail-merge-with-JSON\Mail-merge-with-JSON.csproj", "{D3AF529E-DB54-4294-A876-DD42E1E472D0}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {58137FF9-5AE1-4514-9929-3A8A7DA1DFEB} | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
1 change: 1 addition & 0 deletions
1
Mail-Merge/Mail-merge-with-JSON/.NET/Mail-merge-with-JSON/Json Data.json
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 @@ | ||
{ "Employee": [{"EmployeeId":1001,"Name":"Peter","Phone":"+122-2222222","City":"London"}]} |
14 changes: 14 additions & 0 deletions
14
Mail-Merge/Mail-merge-with-JSON/.NET/Mail-merge-with-JSON/Mail-merge-with-JSON.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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>Mail_merge_with_JSON</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="*" /> | ||
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.