Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Apply_Styles_For_Inserted_Tables</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>
<ItemGroup>
<None Update="Data\Template.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\Table.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<table>
<thead>
<tr>
<td>Nummer</td>
<td>Name</td>
<td>Abschluss</td>
<td>Dauer</td>
<td>Extras</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Vertrag 1</td>
<td>15.08.2023</td>
<td>10 Jahre</td>
<td>
<ul>
<li>Extra 1</li>
<li>Extra 2</li>
</ul>
</td>
</tr>
<tr>
<td>2</td>
<td>Vertrag 2</td>
<td>15.08.2023</td>
<td>12 Jahre</td>
<td>
<ol>
<li>Extra 1</li>
<li>Extra 2</li>
</ol>
</td>
</tr>
<tr>
<td>3</td>
<td>Vertrag 3</td>
<td>15.08.2023</td>
<td>100 Jahre</td>
<td>
<p style="color: red">KEINE EXTRAS</p>
</td>
</tr>
</tbody>
</table>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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<Entity> 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);
}
}
}
}
}
}
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.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
Loading