-
Notifications
You must be signed in to change notification settings - Fork 56
ES-942135-How to set same table style for all newly inserted tables in a Word document #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GOPINATH-SF4767
wants to merge
3
commits into
main
Choose a base branch
from
ES-942135-Table
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...rted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Apply_Styles_For_Inserted_Tables.csproj
This file contains hidden or 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 @@ | ||
| <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> |
46 changes: 46 additions & 0 deletions
46
...es/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Data/Table.html
This file contains hidden or 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,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 added
BIN
+19.6 KB
...Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Data/Template.docx
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...es/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Output/.gitkeep
This file contains hidden or 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 @@ | ||
| |
Binary file added
BIN
+15.5 KB
...Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Output/Result.docx
Binary file not shown.
55 changes: 55 additions & 0 deletions
55
Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Program.cs
This file contains hidden or 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,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(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplify code by AppendTable |
||
| 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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply_Styles_For_Inserted_Tables.sln
This file contains hidden or 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.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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why using stream, open directly