Skip to content

Commit 74bb725

Browse files
Added the sample
1 parent 7676c46 commit 74bb725

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35309.182
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Reduce-height-of-empty-cells", "Reduce-height-of-empty-cells\Reduce-height-of-empty-cells.csproj", "{1AEC5D8C-07B6-4479-AC12-4E78E7D7EEFF}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{1AEC5D8C-07B6-4479-AC12-4E78E7D7EEFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1AEC5D8C-07B6-4479-AC12-4E78E7D7EEFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1AEC5D8C-07B6-4479-AC12-4E78E7D7EEFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{1AEC5D8C-07B6-4479-AC12-4E78E7D7EEFF}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {68CB8A37-B495-44F3-83A1-89D81324EA06}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
// Open the existing Word document ("Template.docx") for reading and writing.
5+
using (FileStream inputFileStream = new FileStream(Path.GetFullPath("Data/Template.docx"), FileMode.Open, FileAccess.ReadWrite))
6+
{
7+
//Opens an input Word template.
8+
using (WordDocument document = new WordDocument(inputFileStream, FormatType.Docx))
9+
{
10+
// Retrieve the last section of the document.
11+
IWSection section = document.LastSection;
12+
// Retrieve the first table from the section.
13+
IWTable table = section.Body.Tables[0];
14+
// Iterate through each row in the table.
15+
foreach (WTableRow row in table.Rows)
16+
{
17+
// Set the row height type to "AtLeast" and height to 0 to minimize height.
18+
row.HeightType = TableRowHeightType.AtLeast;
19+
row.Height = 0;
20+
// Iterate through each cell in the row.
21+
foreach (WTableCell cell in row.Cells)
22+
{
23+
// Remove top and bottom margins of the cell.
24+
cell.CellFormat.Paddings.Top = 0;
25+
cell.CellFormat.Paddings.Bottom = 0;
26+
// Iterate through paragraphs in each cell.
27+
foreach (IWParagraph paragraph in cell.Paragraphs)
28+
{
29+
paragraph.BreakCharacterFormat.FontSize = 8;
30+
}
31+
}
32+
}
33+
//Save the document.
34+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath("Output/Result.docx"), FileMode.Create, FileAccess.Write))
35+
{
36+
document.Save(outputFileStream, FormatType.Docx);
37+
}
38+
//Close the document.
39+
document.Close();
40+
}
41+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Reduce_Height_of_Empty_Cells</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Template.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
</Project>

0 commit comments

Comments
 (0)