diff --git a/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Apply_Styles_For_Inserted_Tables.csproj b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Apply_Styles_For_Inserted_Tables.csproj new file mode 100644 index 00000000..5fa1a843 --- /dev/null +++ b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Apply_Styles_For_Inserted_Tables.csproj @@ -0,0 +1,25 @@ + + + + Exe + net8.0 + Apply_Styles_For_Inserted_Tables + enable + enable + + + + + + + + Always + + + Always + + + Always + + + diff --git a/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Data/Table.html b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Data/Table.html new file mode 100644 index 00000000..6252f3a3 --- /dev/null +++ b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Data/Table.html @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NummerNameAbschlussDauerExtras
1Vertrag 115.08.202310 Jahre +
    +
  • Extra 1
  • +
  • Extra 2
  • +
+
2Vertrag 215.08.202312 Jahre +
    +
  1. Extra 1
  2. +
  3. Extra 2
  4. +
+
3Vertrag 315.08.2023100 Jahre +

KEINE EXTRAS

+
\ No newline at end of file diff --git a/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Data/Template.docx b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Data/Template.docx new file mode 100644 index 00000000..bae6fe1e Binary files /dev/null and b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Data/Template.docx differ diff --git a/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Output/.gitkeep b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Output/.gitkeep new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Output/Result.docx b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Output/Result.docx new file mode 100644 index 00000000..80ffaaff Binary files /dev/null and b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Output/Result.docx differ diff --git a/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Program.cs b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Program.cs new file mode 100644 index 00000000..f6765b76 --- /dev/null +++ b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Program.cs @@ -0,0 +1,55 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + + +namespace Apply_Styles_For_Inserted_Tables +{ + class Program + { + static void Main(string[] args) + { + // Open an existing word document + using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open)) + { + // Opens an input Word template + using (WordDocument resultDocument = new WordDocument(inputFileStream, FormatType.Docx)) + { + // Read HTML string from the file. + string html = File.ReadAllText(Path.GetFullPath(@"Data/Table.html")); + + // Insert HTML (table style is not applied automatically) + resultDocument.LastSection.Body.InsertXHTML(html); + + // Append table manually - this one applies the table style from the template + WTable table = resultDocument.LastSection.AddTable() as WTable; + WTableRow row = table.AddRow(); + row.AddCell(); + row.AddCell(); + row.AddCell(); + row.AddCell(); + row.AddCell(); + row.AddCell(); + table.AddRow(); + + for (int rowIndex = 0; rowIndex < 2; rowIndex++) + for (int columnIndex = 0; columnIndex < 6; columnIndex++) + table.Rows[rowIndex].Cells[columnIndex].AddParagraph().Text = (rowIndex * columnIndex).ToString(); + + //Finds all the table in the Word document + List tableList = resultDocument.FindAllItemsByProperty(EntityType.Table, "EntityType", EntityType.Table.ToString()); + foreach (var item in tableList) + { + WTable tableInDocument = item as WTable; + //Apply table style "TableGrid" to the table + tableInDocument.ApplyStyle(BuiltinTableStyle.TableGrid); + } + // Save the document to output file + using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create)) + { + resultDocument.Save(outputStream, FormatType.Docx); + } + } + } + } + } +} diff --git a/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply_Styles_For_Inserted_Tables.sln b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply_Styles_For_Inserted_Tables.sln new file mode 100644 index 00000000..f531082c --- /dev/null +++ b/Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply_Styles_For_Inserted_Tables.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36915.13 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apply_Styles_For_Inserted_Tables", "Apply-Styles-For-Inserted-Tables\Apply_Styles_For_Inserted_Tables.csproj", "{55EDD229-1D8D-A828-43A7-430288CEBC04}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {55EDD229-1D8D-A828-43A7-430288CEBC04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {55EDD229-1D8D-A828-43A7-430288CEBC04}.Debug|Any CPU.Build.0 = Debug|Any CPU + {55EDD229-1D8D-A828-43A7-430288CEBC04}.Release|Any CPU.ActiveCfg = Release|Any CPU + {55EDD229-1D8D-A828-43A7-430288CEBC04}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8B2F0716-0623-4FBF-B1DA-825CD7ED6A26} + EndGlobalSection +EndGlobal