diff --git a/Find-and-Replace/Find-and-replace-text-with-TOC/.NET standard/Find-and-replace-text-with-TOC.sln b/Find-and-Replace/Find-and-replace-text-with-TOC/.NET standard/Find-and-replace-text-with-TOC.sln new file mode 100644 index 00000000..9c344f46 --- /dev/null +++ b/Find-and-Replace/Find-and-replace-text-with-TOC/.NET standard/Find-and-replace-text-with-TOC.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33213.308 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-and-replace-text-with-TOC", "Find-and-replace-text-with-TOC\Find-and-replace-text-with-TOC.csproj", "{23ABDEA3-F208-4355-B4A4-D17CBC963A16}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {23ABDEA3-F208-4355-B4A4-D17CBC963A16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23ABDEA3-F208-4355-B4A4-D17CBC963A16}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23ABDEA3-F208-4355-B4A4-D17CBC963A16}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23ABDEA3-F208-4355-B4A4-D17CBC963A16}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {632BD348-C0F4-4909-B134-1554F75A6F1B} + EndGlobalSection +EndGlobal diff --git a/Find-and-Replace/Find-and-replace-text-with-TOC/.NET standard/Find-and-replace-text-with-TOC/Data/Input.docx b/Find-and-Replace/Find-and-replace-text-with-TOC/.NET standard/Find-and-replace-text-with-TOC/Data/Input.docx new file mode 100644 index 00000000..1102cfb7 Binary files /dev/null and b/Find-and-Replace/Find-and-replace-text-with-TOC/.NET standard/Find-and-replace-text-with-TOC/Data/Input.docx differ diff --git a/Find-and-Replace/Find-and-replace-text-with-TOC/.NET standard/Find-and-replace-text-with-TOC/Find-and-replace-text-with-TOC.csproj b/Find-and-Replace/Find-and-replace-text-with-TOC/.NET standard/Find-and-replace-text-with-TOC/Find-and-replace-text-with-TOC.csproj new file mode 100644 index 00000000..a79dbe14 --- /dev/null +++ b/Find-and-Replace/Find-and-replace-text-with-TOC/.NET standard/Find-and-replace-text-with-TOC/Find-and-replace-text-with-TOC.csproj @@ -0,0 +1,13 @@ + + + + Exe + netcoreapp3.1 + Find_and_replace_text_with_TOC + + + + + + + diff --git a/Find-and-Replace/Find-and-replace-text-with-TOC/.NET standard/Find-and-replace-text-with-TOC/Program.cs b/Find-and-Replace/Find-and-replace-text-with-TOC/.NET standard/Find-and-replace-text-with-TOC/Program.cs new file mode 100644 index 00000000..b19e67e5 --- /dev/null +++ b/Find-and-Replace/Find-and-replace-text-with-TOC/.NET standard/Find-and-replace-text-with-TOC/Program.cs @@ -0,0 +1,57 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIORenderer; +using System; +using System.IO; + +namespace Find_and_replace_text_with_TOC +{ + internal class Program + { + static void Main(string[] args) + { + using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"../../../Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + //Opens an existing Word document. + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) + { + TextSelection[] selections = document.FindAll("[Insert TOC]", true, true); + WTextRange textrange = selections[0].GetAsOneRange(); + WParagraph paragraph = textrange.OwnerParagraph; + int index = paragraph.ChildEntities.IndexOf(textrange); + //Remove the existing text + paragraph.ChildEntities.Remove(textrange); + //Insert the TOC + InsertTOC(document, paragraph, index); + //Update the TOC + document.UpdateTableOfContents(); + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Data/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputFileStream, FormatType.Docx); + } + } + } + } + /// + /// Insert the TOC in the index of given paragraph + /// + /// + /// + /// + private static void InsertTOC(WordDocument document, WParagraph ownerPara, int index) + { + //Create a new paragraph + WParagraph newPara = new WParagraph(document); + //Append TOC to the new paragraph + newPara.AppendTOC(1, 3); + //Insert the child entities of new paragraph to the owner paragraph at the given index. + for (int i = 0; i < newPara.ChildEntities.Count;) + { + ownerPara.ChildEntities.Insert(index, newPara.ChildEntities[i]); + index++; + } + } + } +} diff --git a/Find-and-Replace/Find-and-replace-text-with-chart/.NET Standard/Find-and-replace-text-with-chart.sln b/Find-and-Replace/Find-and-replace-text-with-chart/.NET Standard/Find-and-replace-text-with-chart.sln new file mode 100644 index 00000000..8728e676 --- /dev/null +++ b/Find-and-Replace/Find-and-replace-text-with-chart/.NET Standard/Find-and-replace-text-with-chart.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33213.308 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-and-replace-text-with-chart", "Find-and-replace-text-with-chart\Find-and-replace-text-with-chart.csproj", "{6DC22CF0-0561-4C68-9D83-5C0971490748}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6DC22CF0-0561-4C68-9D83-5C0971490748}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6DC22CF0-0561-4C68-9D83-5C0971490748}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6DC22CF0-0561-4C68-9D83-5C0971490748}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6DC22CF0-0561-4C68-9D83-5C0971490748}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D05EB822-AE02-4DFA-B932-C32E99F9BFA9} + EndGlobalSection +EndGlobal diff --git a/Find-and-Replace/Find-and-replace-text-with-chart/.NET Standard/Find-and-replace-text-with-chart/Data/Input.docx b/Find-and-Replace/Find-and-replace-text-with-chart/.NET Standard/Find-and-replace-text-with-chart/Data/Input.docx new file mode 100644 index 00000000..1a6356e2 Binary files /dev/null and b/Find-and-Replace/Find-and-replace-text-with-chart/.NET Standard/Find-and-replace-text-with-chart/Data/Input.docx differ diff --git a/Find-and-Replace/Find-and-replace-text-with-chart/.NET Standard/Find-and-replace-text-with-chart/Find-and-replace-text-with-chart.csproj b/Find-and-Replace/Find-and-replace-text-with-chart/.NET Standard/Find-and-replace-text-with-chart/Find-and-replace-text-with-chart.csproj new file mode 100644 index 00000000..ef22849e --- /dev/null +++ b/Find-and-Replace/Find-and-replace-text-with-chart/.NET Standard/Find-and-replace-text-with-chart/Find-and-replace-text-with-chart.csproj @@ -0,0 +1,13 @@ + + + + Exe + netcoreapp3.1 + Find_and_replace_text_with_chart + + + + + + + diff --git a/Find-and-Replace/Find-and-replace-text-with-chart/.NET Standard/Find-and-replace-text-with-chart/Program.cs b/Find-and-Replace/Find-and-replace-text-with-chart/.NET Standard/Find-and-replace-text-with-chart/Program.cs new file mode 100644 index 00000000..b32b7114 --- /dev/null +++ b/Find-and-Replace/Find-and-replace-text-with-chart/.NET Standard/Find-and-replace-text-with-chart/Program.cs @@ -0,0 +1,102 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using Syncfusion.OfficeChart; +using System; +using System.ComponentModel; +using System.IO; + +namespace Find_and_replace_text_with_chart +{ + internal class Program + { + static void Main(string[] args) + { + using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"../../../Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + //Opens an existing Word document. + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) + { + TextBodyPart bodyPart = new TextBodyPart(document); + //Create new paragraph + WParagraph paragraph= CreateBarChart(document); + bodyPart.BodyItems.Add(paragraph); + //Replaces the placeholder text with a new chart. + document.Replace("[Purchase details]", bodyPart, true, true, true); + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Data/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputFileStream, FormatType.Docx); + } + } + } + } + /// + /// Create a bar chart inside a new paragraph. + /// + /// + /// + private static WParagraph CreateBarChart(WordDocument document) + { + //Create new paragraph + WParagraph paragraph = new WParagraph(document); + //Append new chart + WChart barchart = paragraph.AppendChart(400, 300); + //Set type as bar chart + barchart.ChartType = OfficeChartType.Bar_Clustered; + //Add data for the bar chart + AddBarChartData(barchart); + + //Set the other parts of the chart. + barchart.ChartTitle = "Purchase Details"; + barchart.ChartTitleArea.FontName = "Calibri"; + barchart.ChartTitleArea.Size = 14; + IOfficeChartSerie serie1 = barchart.Series.Add("Sum of Future Expenses"); + serie1.Values = barchart.ChartData[2, 2, 6, 2]; + IOfficeChartSerie serie2 = barchart.Series.Add("Sum of Purchases"); + serie2.Values = barchart.ChartData[2, 3, 6, 3]; + + barchart.HasDataTable = true; + barchart.DataTable.HasBorders = true; + barchart.DataTable.HasHorzBorder = true; + barchart.DataTable.HasVertBorder = true; + barchart.DataTable.ShowSeriesKeys = true; + barchart.HasLegend = false; + + barchart.PlotArea.Border.LinePattern = OfficeChartLinePattern.Solid; + barchart.ChartArea.Border.LinePattern = OfficeChartLinePattern.Solid; + barchart.PrimaryCategoryAxis.CategoryLabels = barchart.ChartData[2, 1, 6, 1]; + barchart.PrimaryCategoryAxis.Font.Size = 12; + barchart.PrimaryCategoryAxis.MajorTickMark = OfficeTickMark.TickMark_None; + barchart.PrimaryValueAxis.MajorTickMark = OfficeTickMark.TickMark_None; + + //Return the new paragraph that has bar chart in it. + return paragraph; + } + /// + /// Add the data for bar chart + /// + /// + private static void AddBarChartData(WChart chart) + { + chart.ChartData.SetValue(1, 2, "Sum of Future Expenses"); + chart.ChartData.SetValue(1, 3, "Sum of Purchases"); + chart.ChartData.SetValue(2, 1, "Nancy Davalio"); + chart.ChartData.SetValue(2, 2, 1300); + chart.ChartData.SetValue(2, 3, 600); + chart.ChartData.SetValue(3, 1, "Andrew Fuller"); + chart.ChartData.SetValue(3, 2, 680); + chart.ChartData.SetValue(3, 3, 1000); + chart.ChartData.SetValue(4, 1, "Janet Leverling"); + chart.ChartData.SetValue(4, 2, 1280); + chart.ChartData.SetValue(4, 3, 800); + chart.ChartData.SetValue(5, 1, "Margaret Peacock"); + chart.ChartData.SetValue(5, 2, 2000); + chart.ChartData.SetValue(5, 3, 400); + chart.ChartData.SetValue(6, 1, "Steven Buchanan"); + chart.ChartData.SetValue(6, 2, 2660); + chart.ChartData.SetValue(6, 3, 731); + } + + } +} diff --git a/Find-and-Replace/Find-and-replace-text-with-image/.NET-Standard/Find-and-replace-text-with-image/Program.cs b/Find-and-Replace/Find-and-replace-text-with-image/.NET-Standard/Find-and-replace-text-with-image/Program.cs index 45d385e0..9f0fb8fc 100644 --- a/Find-and-Replace/Find-and-replace-text-with-image/.NET-Standard/Find-and-replace-text-with-image/Program.cs +++ b/Find-and-Replace/Find-and-replace-text-with-image/.NET-Standard/Find-and-replace-text-with-image/Program.cs @@ -22,7 +22,6 @@ static void Main(string[] args) WParagraph paragraph = new WParagraph(document); FileStream imageStream = new FileStream(Path.GetFullPath(@"../../../Data" + textSelections[i].SelectedText + ".png"), FileMode.Open, FileAccess.ReadWrite); WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; - TextSelection newSelection = new TextSelection(paragraph, 0, 1); TextBodyPart bodyPart = new TextBodyPart(document); bodyPart.BodyItems.Add(paragraph); document.Replace(textSelections[i].SelectedText, bodyPart, true, true); diff --git a/Find-and-Replace/Replace-text-with-hyperlink/.NET Standard/Replace-text-with-hyperlink.sln b/Find-and-Replace/Replace-text-with-hyperlink/.NET Standard/Replace-text-with-hyperlink.sln new file mode 100644 index 00000000..7cbf13a2 --- /dev/null +++ b/Find-and-Replace/Replace-text-with-hyperlink/.NET Standard/Replace-text-with-hyperlink.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33213.308 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-text-with-hyperlink", "Replace-text-with-hyperlink\Replace-text-with-hyperlink.csproj", "{0E4D096D-C506-497E-8DE1-A71DECFBBB8C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0E4D096D-C506-497E-8DE1-A71DECFBBB8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E4D096D-C506-497E-8DE1-A71DECFBBB8C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E4D096D-C506-497E-8DE1-A71DECFBBB8C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E4D096D-C506-497E-8DE1-A71DECFBBB8C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FC6DAA82-E7CA-4AB9-A2A0-A54A52989B25} + EndGlobalSection +EndGlobal diff --git a/Find-and-Replace/Replace-text-with-hyperlink/.NET Standard/Replace-text-with-hyperlink/Data/Input.docx b/Find-and-Replace/Replace-text-with-hyperlink/.NET Standard/Replace-text-with-hyperlink/Data/Input.docx new file mode 100644 index 00000000..0912c43f Binary files /dev/null and b/Find-and-Replace/Replace-text-with-hyperlink/.NET Standard/Replace-text-with-hyperlink/Data/Input.docx differ diff --git a/Find-and-Replace/Replace-text-with-hyperlink/.NET Standard/Replace-text-with-hyperlink/Program.cs b/Find-and-Replace/Replace-text-with-hyperlink/.NET Standard/Replace-text-with-hyperlink/Program.cs new file mode 100644 index 00000000..d5d51dcd --- /dev/null +++ b/Find-and-Replace/Replace-text-with-hyperlink/.NET Standard/Replace-text-with-hyperlink/Program.cs @@ -0,0 +1,40 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System; +using System.IO; + +namespace Replace_text_with_hyperlink +{ + internal class Program + { + static void Main(string[] args) + { + using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"../../../Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + //Opens an existing Word document. + using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) + { + string textToReplace = "Syncfusion"; + //Initialize new text body part + TextBodyPart textBodyPart = new TextBodyPart(document); + //Initialize new paragraph + WParagraph paragraph = new WParagraph(document); + //Adds the paragraph into the text body part + textBodyPart.BodyItems.Add(paragraph); + //Appends web hyperlink to the paragraph + paragraph.AppendHyperlink("http://www.syncfusion.com", textToReplace, HyperlinkType.WebLink); + //Replaces all entries of given string in the document with text body part + document.Replace(textToReplace, textBodyPart, false, true); + //Clears the text body part + textBodyPart.Clear(); + //Creates file stream. + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Data/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Saves the Word document to file stream. + document.Save(outputFileStream, FormatType.Docx); + } + } + } + } + } +} diff --git a/Find-and-Replace/Replace-text-with-hyperlink/.NET Standard/Replace-text-with-hyperlink/Replace-text-with-hyperlink.csproj b/Find-and-Replace/Replace-text-with-hyperlink/.NET Standard/Replace-text-with-hyperlink/Replace-text-with-hyperlink.csproj new file mode 100644 index 00000000..95a2339b --- /dev/null +++ b/Find-and-Replace/Replace-text-with-hyperlink/.NET Standard/Replace-text-with-hyperlink/Replace-text-with-hyperlink.csproj @@ -0,0 +1,13 @@ + + + + Exe + netcoreapp3.1 + Replace_text_with_hyperlink + + + + + + +