diff --git a/Find-item-in-word-document/Replace-text-heading-paragraphs/.NET/Replace-text-heading-paragraphs/Program.cs b/Find-item-in-word-document/Replace-text-heading-paragraphs/.NET/Replace-text-heading-paragraphs/Program.cs index 583d0e15..4a9ec866 100644 --- a/Find-item-in-word-document/Replace-text-heading-paragraphs/.NET/Replace-text-heading-paragraphs/Program.cs +++ b/Find-item-in-word-document/Replace-text-heading-paragraphs/.NET/Replace-text-heading-paragraphs/Program.cs @@ -1,7 +1,4 @@ - - -using Microsoft.VisualBasic.FileIO; -using Syncfusion.DocIO; +using Syncfusion.DocIO; using Syncfusion.DocIO.DLS; namespace Replace_text_heading_paragraphs @@ -10,24 +7,26 @@ class Program { static void Main(string[] args) { - using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + using (FileStream inputFileStream = 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.Automatic)) + //Opens the input Word document. + using (WordDocument document = new WordDocument(inputFileStream, FormatType.Automatic)) { for (int headingLevel = 1; headingLevel < 10; headingLevel++) { //Find headings based on the levels and endnote by paragraph in Word document. List headings = document.FindAllItemsByProperty(EntityType.Paragraph, "StyleName", "Heading " + headingLevel); - //Replace the headings with text. + //Iterate through all headings in the list. for (int index = 0; index < headings.Count; index++) { + //Cast the current heading to WParagraph. WParagraph paragraph = headings[index] as WParagraph; + //Remove all child elements from the paragraph. paragraph.ChildEntities.Clear(); - paragraph.AppendText("Replaced Heading"+headingLevel+" text"); + //Add new text to replace the heading content. + paragraph.AppendText("Replaced Heading" + headingLevel + " text"); } } - //Creates file stream. using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) { //Saves the Word document to file stream. diff --git a/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph.sln b/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph.sln new file mode 100644 index 00000000..181bd5e9 --- /dev/null +++ b/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35309.182 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-text-in-list-paragraph", "Replace-text-in-list-paragraph\Replace-text-in-list-paragraph.csproj", "{CD5449C2-95ED-4D2B-8984-E2D4386503BA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CD5449C2-95ED-4D2B-8984-E2D4386503BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD5449C2-95ED-4D2B-8984-E2D4386503BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD5449C2-95ED-4D2B-8984-E2D4386503BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD5449C2-95ED-4D2B-8984-E2D4386503BA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8AAB32F5-BB2E-4918-B6CC-FF84105D3AC3} + EndGlobalSection +EndGlobal diff --git a/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Data/File.html b/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Data/File.html new file mode 100644 index 00000000..7a610754 --- /dev/null +++ b/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Data/File.html @@ -0,0 +1,7 @@ + + +
+

Road-150

+
+ + \ No newline at end of file diff --git a/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Data/Template.docx b/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Data/Template.docx new file mode 100644 index 00000000..a8d66043 Binary files /dev/null and b/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Data/Template.docx differ diff --git "a/Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Output/.gitkeep" b/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Output/.gitkeep similarity index 100% rename from "Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Output/.gitkeep" rename to HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Output/.gitkeep diff --git a/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Program.cs b/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Program.cs new file mode 100644 index 00000000..dc43e583 --- /dev/null +++ b/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Program.cs @@ -0,0 +1,93 @@ +using Syncfusion.DocIO.DLS; +using Syncfusion.DocIO; + +//Register Syncfusion license +Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Mgo+DSMBMAY9C3t2UlhhQlNHfV5DQmBWfFN0QXNYfVRwdF9GYEwgOX1dQl9nSXZTc0VlWndfcXNSQWc="); + +using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite)) +{ + //Open the template Word document. + using (WordDocument document = new WordDocument(inputFileStream, FormatType.Automatic)) + { + string htmlFilePath = @"Data/File.html"; + //Check if the HTML content is valid. + bool isvalidHTML = IsValidHTML(htmlFilePath); + if (isvalidHTML) + { + //Iterate through the sections in the document. + for (int i = 0; i < document.Sections.Count; i++) + { + //Iterate through the paragraphs within the section. + for (int j = 0; j < document.Sections[i].Paragraphs.Count; j++) + { + //Get the current paragraph from the section. + WParagraph paragraph = document.Sections[i].Paragraphs[j] as WParagraph; + //Define the variable containing the text to search within the paragraph. + string variable = "Mountain-300"; + //If the paragraph contains the specific text, replace it with HTML content. + if (paragraph.Text.Contains(variable)) + { + //Get the next sibling element of the current paragraph. + TextBodyItem nextSibling = paragraph.NextSibling as TextBodyItem; + //Get the index of the current paragraph within its parent text body. + int sourceIndex = paragraph.OwnerTextBody.ChildEntities.IndexOf(paragraph); + //Clear all child entities within the paragraph. + paragraph.ChildEntities.Clear(); + //Get the list style name from the paragraph. + string listStyleName = paragraph.ListFormat.CurrentListStyle.Name; + //Get the current list level number. + int listLevelNum = paragraph.ListFormat.ListLevelNumber; + //Append HTML content from the specified file to the paragraph. + paragraph.AppendHTML(File.ReadAllText(Path.GetFullPath(htmlFilePath))); + //Reapply the original list style to the paragraph. + paragraph.ListFormat.ApplyStyle(listStyleName); + //Reapply the original list level number. + paragraph.ListFormat.ListLevelNumber = listLevelNum; + //Determine the index of the next sibling if it exists. + int nextSiblingIndex = nextSibling != null ? nextSibling.OwnerTextBody.ChildEntities.IndexOf(nextSibling) : -1; + //Apply the same list style to newly added paragraphs from the HTML content. + for (int k = sourceIndex; k < paragraph.OwnerTextBody.Count; k++) + { + //Stop applying the style if the next sibling is reached. + if (nextSiblingIndex != -1 && k == nextSiblingIndex) + { + break; + } + Entity entity = paragraph.OwnerTextBody.ChildEntities[k]; + //Apply the list style only if the entity is a paragraph. + if (entity is WParagraph) + { + (entity as WParagraph).ListFormat.ApplyStyle(listStyleName); + } + else + { + break; + } + } + } + } + } + } + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) + { + //Save the modified Word document to the output file stream. + document.Save(outputFileStream, FormatType.Docx); + } + } +} + +/// +/// Validates whether the HTML content from the specified file is well-formed XHTML. +/// +static bool IsValidHTML(string htmlFilePath) +{ + using (WordDocument document = new WordDocument()) + { + //Add a section for the HTML content. + IWSection section = document.AddSection(); + //Read the HTML string from the specified file. + string htmlString = File.ReadAllText(Path.GetFullPath(htmlFilePath)); + //Validate the HTML string. + return section.Body.IsValidXHTML(htmlString, XHTMLValidationType.None); + } +} diff --git a/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph.csproj b/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph.csproj new file mode 100644 index 00000000..1e87d88a --- /dev/null +++ b/HTML-conversions/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph/Replace-text-in-list-paragraph.csproj @@ -0,0 +1,27 @@ + + + + Exe + net8.0 + Replace_text_in_list_paragraph + enable + enable + + + + + + + + + Always + + + Always + + + Always + + + + diff --git a/Tables/Find-table-and-add-row/Find-table-and-add-row.sln b/Tables/Find-table-and-add-row/Find-table-and-add-row.sln new file mode 100644 index 00000000..01d64ba1 --- /dev/null +++ b/Tables/Find-table-and-add-row/Find-table-and-add-row.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35309.182 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Find-table-and-add-row", "Find-table-and-add-row\Find-table-and-add-row.csproj", "{E8C23293-ABC9-4C54-81BA-9C5FBA6D85C1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E8C23293-ABC9-4C54-81BA-9C5FBA6D85C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E8C23293-ABC9-4C54-81BA-9C5FBA6D85C1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E8C23293-ABC9-4C54-81BA-9C5FBA6D85C1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E8C23293-ABC9-4C54-81BA-9C5FBA6D85C1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EC6BCFD8-E759-47DE-BC97-AC492B3D6DF8} + EndGlobalSection +EndGlobal diff --git a/Tables/Find-table-and-add-row/Find-table-and-add-row/Data/Template.docx b/Tables/Find-table-and-add-row/Find-table-and-add-row/Data/Template.docx new file mode 100644 index 00000000..5c462ec4 Binary files /dev/null and b/Tables/Find-table-and-add-row/Find-table-and-add-row/Data/Template.docx differ diff --git a/Tables/Find-table-and-add-row/Find-table-and-add-row/Find-table-and-add-row.csproj b/Tables/Find-table-and-add-row/Find-table-and-add-row/Find-table-and-add-row.csproj new file mode 100644 index 00000000..56ec9ffa --- /dev/null +++ b/Tables/Find-table-and-add-row/Find-table-and-add-row/Find-table-and-add-row.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + Find_table_and_add_row + enable + enable + + + + + + + + + Always + + + Always + + + + diff --git a/Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG/Output/.gitkeep b/Tables/Find-table-and-add-row/Find-table-and-add-row/Output/.gitkeep similarity index 100% rename from Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG/Output/.gitkeep rename to Tables/Find-table-and-add-row/Find-table-and-add-row/Output/.gitkeep diff --git a/Tables/Find-table-and-add-row/Find-table-and-add-row/Program.cs b/Tables/Find-table-and-add-row/Find-table-and-add-row/Program.cs new file mode 100644 index 00000000..b44d86b1 --- /dev/null +++ b/Tables/Find-table-and-add-row/Find-table-and-add-row/Program.cs @@ -0,0 +1,28 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + + +//Register Syncfusion license +Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Mgo+DSMBMAY9C3t2UlhhQlNHfV5DQmBWfFN0QXNYfVRwdF9GYEwgOX1dQl9nSXZTc0VlWndfcXNSQWc="); + +using (FileStream inputFileStream = new FileStream(Path.GetFullPath("Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite)) +{ + // Open the input Word document + using (WordDocument document = new WordDocument(inputFileStream, FormatType.Docx)) + { + // Find a table with its alternate text (Title property). + WTable table = document.FindItemByProperty(EntityType.Table, "Title", "DataTable") as WTable; + // Check if the table exists. + if (table != null) + { + // Add a new row to the table. + table.AddRow(); + } + + using (FileStream outputFileStream = new FileStream(Path.GetFullPath("Output/Result.docx"), FileMode.Create, FileAccess.Write)) + { + // Save the modified document to the output file stream. + document.Save(outputFileStream, FormatType.Docx); + } + } +} \ No newline at end of file diff --git a/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows.sln b/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows.sln new file mode 100644 index 00000000..508ae112 --- /dev/null +++ b/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35309.182 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-row-with-multiple-rows", "Replace-row-with-multiple-rows\Replace-row-with-multiple-rows.csproj", "{7D07A56C-8B23-4CFE-9E8C-903C5C1EF6CB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7D07A56C-8B23-4CFE-9E8C-903C5C1EF6CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7D07A56C-8B23-4CFE-9E8C-903C5C1EF6CB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7D07A56C-8B23-4CFE-9E8C-903C5C1EF6CB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7D07A56C-8B23-4CFE-9E8C-903C5C1EF6CB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F9812314-7D24-42E7-8090-5B2969EB47E9} + EndGlobalSection +EndGlobal diff --git a/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows/Data/Template.docx b/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows/Data/Template.docx new file mode 100644 index 00000000..5c462ec4 Binary files /dev/null and b/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows/Data/Template.docx differ diff --git a/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows/Output/.gitkeep b/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows/Output/.gitkeep new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows/Program.cs b/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows/Program.cs new file mode 100644 index 00000000..908c44cb --- /dev/null +++ b/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows/Program.cs @@ -0,0 +1,125 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; +using System.Dynamic; + +using (FileStream inputFileStream = new FileStream(Path.GetFullPath("Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite)) +{ + // Open the input Word document + using (WordDocument document = new WordDocument(inputFileStream, FormatType.Docx)) + { + // Find a table with its alternate text (Title property). + WTable table = document.FindItemByProperty(EntityType.Table, "Title", "DataTable") as WTable; + // Check if the table was found. + if (table != null) + { + // Get the second row of the table. + WTableRow secondRow = table.Rows[1]; + // Insert data into the cells of the second row. + InsertDataToCells(secondRow); + // Add dynamic rows starting at index 2, based on the second row. + AddDyamicRows(table, 2, secondRow); + } + + using (FileStream outputFileStream = new FileStream(Path.GetFullPath("Output/Result.docx"), FileMode.Create, FileAccess.Write)) + { + // Save the modified document to the output file stream. + document.Save(outputFileStream, FormatType.Docx); + } + } +} + +/// +/// Insert data into the cells of a specified table row. +/// +void InsertDataToCells(WTableRow row) +{ + // List of placeholder data to insert into the cells. + List data = new List { "<>", "<>", "<>", "<>" }; + int count = 0; + // Iterate through each cell in the specified row. + foreach (WTableCell cell in row.Cells) + { + // Assign data to the particular cell. + cell.Paragraphs[0].Text = data[count]; + count++; + } +} + +/// +/// Add dynamic rows to a specified table at a certain index. +/// +void AddDyamicRows(WTable table, int index, WTableRow row) +{ + // Create a list of dynamic row details. + IEnumerable rowsDetails = CreateDyamicRows(); + // Iterate through each dynamic row detail. + foreach (dynamic rowDetails in rowsDetails) + { + // Retrieve cell content for the new row. + List cellDetails = GetListOfCellValue(rowDetails); + // Clone the second row to create a new row. + WTableRow newRow = row.Clone(); + // Iterate through the cells of the cloned row. + for (int i = 0; i < newRow.Cells.Count; i++) + { + // Get the cell at specific from the cloned row. + WTableCell wTableCell = newRow.Cells[i]; + // Modify the paragraph text of the cell with the corresponding cell detail. + wTableCell.Paragraphs[0].Text = cellDetails[i]; + } + // Insert the newly created row at the specified index. + table.Rows.Insert(index, newRow); + // Increment the index for the next dynamic row. + index++; + } +} + +/// +/// Create dynamic rows with sample cell data. +/// +IEnumerable CreateDyamicRows() +{ + // Create a list of dynamic row details. + List rowDetails = new List(); + + // Add dynamic cells to the row details list. + rowDetails.Add(CreateDynamicCells("<>", "<>", "<>", "<>")); + rowDetails.Add(CreateDynamicCells("<>", "<>", "<>", "<>")); + rowDetails.Add(CreateDynamicCells("<>", "<>", "<>", "<>")); + rowDetails.Add(CreateDynamicCells("<>", "<>", "<>", "<>")); + // Return the list of dynamic row details. + return rowDetails; +} + +/// +/// Create dynamic cell data. +/// +dynamic CreateDynamicCells(string cell1, string cell2, string cell3, string cell4) +{ + // Create a new ExpandoObject for dynamic properties. + dynamic dynamicOrder = new ExpandoObject(); + + // Assign values to the dynamic object properties. + dynamicOrder.Cell1 = cell1; + dynamicOrder.Cell2 = cell2; + dynamicOrder.Cell3 = cell3; + dynamicOrder.Cell4 = cell4; + // Return the dynamic object. + return dynamicOrder; +} + +/// +/// Convert the dynamic values to a list of strings. +/// +List GetListOfCellValue(dynamic rowDetails) +{ + List cellDetails = new List(); + + // Add each dynamic cell value to the list. + cellDetails.Add(rowDetails.Cell1); + cellDetails.Add(rowDetails.Cell2); + cellDetails.Add(rowDetails.Cell3); + cellDetails.Add(rowDetails.Cell4); + // Return the list of cell details. + return cellDetails; +} diff --git a/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows.csproj b/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows.csproj new file mode 100644 index 00000000..1ab83b48 --- /dev/null +++ b/Tables/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows/Replace-row-with-multiple-rows.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + Replace_row_with_multiple_rows + enable + enable + + + + + + + + + Always + + + Always + + + + diff --git "a/Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page.sln" b/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page.sln similarity index 80% rename from "Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page.sln" rename to Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page.sln index 17cc3bca..3a111bfc 100644 --- "a/Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page.sln" +++ b/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page.sln @@ -3,7 +3,7 @@ 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}") = "Merge–multiple-Word-files-in-same-page", "Merge–multiple-Word-files-in-same-page\Merge–multiple-Word-files-in-same-page.csproj", "{C790F761-62BA-49E1-8FF6-E15165CB08C1}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge-multiple-Word-files-in-same-page", "Merge-multiple-Word-files-in-same-page\Merge-multiple-Word-files-in-same-page.csproj", "{C790F761-62BA-49E1-8FF6-E15165CB08C1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git "a/Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Data/Addressblock.docx" b/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Data/Addressblock.docx similarity index 100% rename from "Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Data/Addressblock.docx" rename to Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Data/Addressblock.docx diff --git "a/Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Data/Greetings.docx" b/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Data/Greetings.docx similarity index 100% rename from "Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Data/Greetings.docx" rename to Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Data/Greetings.docx diff --git "a/Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Data/Salutation.docx" b/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Data/Salutation.docx similarity index 100% rename from "Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Data/Salutation.docx" rename to Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Data/Salutation.docx diff --git "a/Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Data/Title.docx" b/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Data/Title.docx similarity index 100% rename from "Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Data/Title.docx" rename to Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Data/Title.docx diff --git "a/Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Merge\342\200\223multiple-Word-files-in-same-page.csproj" b/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Merge-multiple-Word-files-in-same-page.csproj similarity index 92% rename from "Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Merge\342\200\223multiple-Word-files-in-same-page.csproj" rename to Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Merge-multiple-Word-files-in-same-page.csproj index c079f85a..d0154946 100644 --- "a/Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Merge\342\200\223multiple-Word-files-in-same-page.csproj" +++ b/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Merge-multiple-Word-files-in-same-page.csproj @@ -9,7 +9,7 @@ - + diff --git a/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Output/.gitkeep b/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Output/.gitkeep new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Program.cs b/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Program.cs new file mode 100644 index 00000000..c1eca853 --- /dev/null +++ b/Word-document/Merge-multiple-Word-files-in-same-page/.NET/Merge-multiple-Word-files-in-same-page/Program.cs @@ -0,0 +1,46 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + +//Create a list and add the paths of the source Word documents to it. +List sourceFileNames = new List(); +sourceFileNames.Add("Data/Addressblock.docx"); +sourceFileNames.Add("Data/Salutation.docx"); +sourceFileNames.Add("Data/Greetings.docx"); + +//Get the absolute path of the destination Word document. +string destinationFileName = Path.GetFullPath(@"Data/Title.docx"); +using (FileStream destinationStream = new FileStream(destinationFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +{ + //Open the destination document. + using (WordDocument destinationDocument = new WordDocument(destinationStream, FormatType.Automatic)) + { + ImportOtherDocuments(sourceFileNames, destinationDocument); + //Save the destination document. + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.Write)) + { + destinationDocument.Save(outputStream, FormatType.Docx); + } + } +} + +/// +/// Import content from multiple source Word documents into a destination document. +/// +void ImportOtherDocuments(List sourceFiles, WordDocument destinationDocument) +{ + //Iterate through each source document from the list. + foreach (string sourceFileName in sourceFiles) + { + using (FileStream sourceStream = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + //Open the source document. + using (WordDocument sourceDocument = new WordDocument(sourceStream, FormatType.Automatic)) + { + //Set the break-code of First section of source document as NoBreak to avoid imported from a new page. + sourceDocument.LastSection.BreakCode = SectionBreakCode.NoBreak; + //Import the contents of source document at the end of destination document. + destinationDocument.ImportContent(sourceDocument, ImportOptions.UseDestinationStyles); + } + } + } +} \ No newline at end of file diff --git "a/Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Program.cs" "b/Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Program.cs" deleted file mode 100644 index 328b9827..00000000 --- "a/Word-document/Merge\342\200\223multiple-Word-files-in-same-page/.NET/Merge\342\200\223multiple-Word-files-in-same-page/Program.cs" +++ /dev/null @@ -1,46 +0,0 @@ -using Syncfusion.DocIO; -using Syncfusion.DocIO.DLS; -using System.Runtime.Serialization; - -//Get the list of source document to be imported -List sourceFileNames = new List(); -sourceFileNames.Add("Data/Addressblock.docx"); -sourceFileNames.Add("Data/Salutation.docx"); -sourceFileNames.Add("Data/Greetings.docx"); - -string destinationFileName = Path.GetFullPath(@"Data/Title.docx"); -using (FileStream destinationStreamPath = new FileStream(destinationFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) -{ - //Opens the destination document - using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic)) - { - ImportOtherDocuments(sourceFileNames, destinationDocument); - //Saves and closes the destination document - using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.docx"), FileMode.Create, FileAccess.Write)) - { - destinationDocument.Save(outputStream, FormatType.Docx); - destinationDocument.Close(); - } - } -} - -void ImportOtherDocuments(List sourceFiles, WordDocument destinationDocument) -{ - //Iterate through each source document from the list - foreach (string sourceFileName in sourceFiles) - { - //Open source document - using (FileStream sourceStreamPath = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) - { - using (WordDocument document = new WordDocument(sourceStreamPath, FormatType.Automatic)) - { - //Sets the break-code of First section of source document as NoBreak to avoid imported from a new page - document.LastSection.BreakCode = SectionBreakCode.NoBreak; - //Imports the contents of source document at the end of destination document - destinationDocument.ImportContent(document, ImportOptions.UseDestinationStyles); - //Close the document. - document.Close(); - } - } - } -} \ No newline at end of file diff --git a/Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG/Data/Input.docx b/Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG/Data/Input.docx deleted file mode 100644 index 68857f4c..00000000 Binary files a/Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG/Data/Input.docx and /dev/null differ diff --git a/Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG.sln b/Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image.sln similarity index 81% rename from Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG.sln rename to Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image.sln index fb956f8c..67e5d5e7 100644 --- a/Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG.sln +++ b/Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image.sln @@ -3,7 +3,7 @@ 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}") = "Replace-Excel-embedded-image-to-PNG", "Replace-Excel-embedded-image-to-PNG\Replace-Excel-embedded-image-to-PNG.csproj", "{269AC7DF-6678-47E4-BC60-BD9811FAE8C5}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Replace-embedded-excel-as-image", "Replace-embedded-excel-as-image\Replace-embedded-excel-as-image.csproj", "{269AC7DF-6678-47E4-BC60-BD9811FAE8C5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image/Data/Input.docx b/Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image/Data/Input.docx new file mode 100644 index 00000000..6c12d252 Binary files /dev/null and b/Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image/Data/Input.docx differ diff --git a/Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image/Output/.gitkeep b/Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image/Output/.gitkeep new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG/Program.cs b/Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image/Program.cs similarity index 62% rename from Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG/Program.cs rename to Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image/Program.cs index 1fd98b73..3b17a7dc 100644 --- a/Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG/Program.cs +++ b/Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image/Program.cs @@ -1,36 +1,36 @@ -using System.Drawing; -using Syncfusion.Pdf; +using Syncfusion.Pdf; using Syncfusion.DocIORenderer; using Syncfusion.DocIO.DLS; using Syncfusion.DocIO; -using Syncfusion.Drawing; -using System.Drawing.Imaging; using Syncfusion.XlsIO; using Syncfusion.XlsIORenderer; -// Initialize the DocIORenderer component for converting Word documents to PDF -using DocIORenderer docIORenderer = new DocIORenderer(); -// Create new DocIORenderer settings -docIORenderer.Settings = new DocIORendererSettings(); -// Open the input Word document from a file stream -FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read); -// Load the Word document into a WordDocument instance -using var tempDocument = new WordDocument(inputStream, FormatType.Automatic); -// Call a method to replace embedded Excel objects in the document with images -ReplaceExcelToImage(tempDocument); -// Convert the Word document to a PDF using the DocIORenderer component -using PdfDocument pdf = docIORenderer.ConvertToPDF(tempDocument); -// Create a file stream to save the output PDF document -FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write); -// Save the generated PDF to the specified file stream -pdf.Save(outputStream); -//Dispose the streams. -inputStream.Dispose(); -outputStream.Dispose(); +//Initialize the DocIORenderer component for converting Word documents to PDF. +using (DocIORenderer docIORenderer = new DocIORenderer()) +{ + using (FileStream inputStream = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read)) + { + //Open the input Word document. + using (WordDocument document = new WordDocument(inputStream, FormatType.Automatic)) + { + //Replace embedded Excel objects in the document with images. + ReplaceExcelToImage(document); + //Convert the Word document to a PDF using the DocIORenderer component. + using (PdfDocument pdf = docIORenderer.ConvertToPDF(document)) + { + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.Write)) + { + //Save the generated PDF to the specified file stream. + pdf.Save(outputStream); + } + } + } + } +} /// -/// Replaces Excel OLE objects in a Word document with images, preserving their original dimensions. +/// Replaces embedded Excel OLE objects in a Word document with their corresponding images while maintaining the original size. /// void ReplaceExcelToImage(WordDocument wordDocument) { diff --git a/Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG/Replace-Excel-embedded-image-to-PNG.csproj b/Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image/Replace-embedded-excel-as-image.csproj similarity index 100% rename from Word-to-PDF-Conversion/Replace-Excel-embedded-image-to-PNG/.NET/Replace-Excel-embedded-image-to-PNG/Replace-Excel-embedded-image-to-PNG.csproj rename to Word-to-PDF-Conversion/Replace-embedded-excel-as-image/.NET/Replace-embedded-excel-as-image/Replace-embedded-excel-as-image.csproj