Skip to content

Commit eed7d95

Browse files
Added sample
1 parent 87b7556 commit eed7d95

5 files changed

Lines changed: 304 additions & 0 deletions

File tree

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.14.37411.7 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add_and_Position_Tables_Side_by_Side", "Add_and_Position_Tables_Side_by_Side\Add_and_Position_Tables_Side_by_Side.csproj", "{5A19AC6F-E017-207A-5D91-D717B4F0C24D}"
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+
{5A19AC6F-E017-207A-5D91-D717B4F0C24D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5A19AC6F-E017-207A-5D91-D717B4F0C24D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5A19AC6F-E017-207A-5D91-D717B4F0C24D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{5A19AC6F-E017-207A-5D91-D717B4F0C24D}.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 = {7E7AF95A-EE42-4955-953A-7734BDEC5EBA}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
<ItemGroup>
15+
<None Update="Output\.gitkeep">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
namespace Add_and_Position_Tables_Side_by_Side
5+
{
6+
class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
//Creates an instance of WordDocument class
11+
using ( WordDocument document = new WordDocument())
12+
{
13+
//Adds a section.
14+
IWSection section = document.AddSection();
15+
16+
#region Left side Table
17+
//Adds the (first Around table) into the section.
18+
IWTable table1 = section.AddTable();
19+
//Set WrapTextAround as true to set the table as a floating table.
20+
table1.TableFormat.WrapTextAround = true;
21+
//Specifies the total number of rows & columns
22+
table1.ResetCells(2, 1);
23+
24+
//Gets the first row first cell of the first table.
25+
WTableCell cell = table1[0, 0];
26+
//Formatting the cell
27+
cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Cleared;
28+
cell.CellFormat.BackColor = Syncfusion.Drawing.Color.Gray;
29+
cell.Width = 240;
30+
//Adds a paragraph into the cell.
31+
IWParagraph para = cell.AddParagraph();
32+
para.AppendText("PRESCRIBER");
33+
//Center aligns the text of the paragraph.
34+
para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
35+
36+
//Gets the second row of the first table.
37+
WTableRow row = table1.Rows[1];
38+
//Set the height of the row.
39+
row.Height = 120f;
40+
41+
//Gets the second row first cell of the first table.
42+
cell = table1[1, 0];
43+
//Formatting the cell
44+
cell.Width = 240;
45+
//Adds a paragraph into the cell.
46+
cell.AddParagraph().AppendText("Dr. John, Bertha");
47+
//Adds a nested table into the cell (second row, first cell).
48+
IWTable nestTable = cell.AddTable();
49+
//Clears the cell borders.
50+
nestTable.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
51+
//Creates the specified number of rows and columns to nested table
52+
nestTable.ResetCells(6, 3);
53+
54+
//Accesses the instance of the nested table cell (first row, first cell)
55+
WTableCell nestedCell = nestTable.Rows[0].Cells[0];
56+
nestedCell.Width = 56f;
57+
nestedCell.AddParagraph().AppendText("DEA#");
58+
//Accesses the instance of the nested table cell (first row, second cell)
59+
nestedCell = nestTable.Rows[0].Cells[1];
60+
nestedCell.Width = 10f;
61+
nestedCell.AddParagraph().AppendText(":");
62+
//Accesses the instance of the nested table cell (first row, third cell)
63+
nestedCell = nestTable.Rows[0].Cells[2];
64+
nestedCell.AddParagraph().AppendText("BD5541443");
65+
nestedCell.Width = 150f;
66+
67+
68+
//Accesses the instance of the nested table cell (second row, first cell)
69+
nestedCell = nestTable.Rows[1].Cells[0];
70+
nestedCell.Width = 56f;
71+
//Adds the content into nested cell
72+
nestedCell.AddParagraph().AppendText("LIC#");
73+
//Accesses the instance of the nested table cell (second row, second cell)
74+
nestedCell = nestTable.Rows[1].Cells[1];
75+
nestedCell.Width = 10f;
76+
nestedCell.AddParagraph().AppendText(":");
77+
//Accesses the instance of the nested table cell (second row, third cell)
78+
nestedCell = nestTable.Rows[1].Cells[2];
79+
nestedCell.AddParagraph().AppendText("199399");
80+
nestedCell.Width = 150f;
81+
82+
//Accesses the instance of the nested table cell (third row, first cell)
83+
nestedCell = nestTable.Rows[2].Cells[0];
84+
nestedCell.Width = 56f;
85+
//Adds the content into nested cell
86+
nestedCell.AddParagraph().AppendText("NPI#");
87+
//Accesses the instance of the nested table cell (third row, second cell)
88+
nestedCell = nestTable.Rows[2].Cells[1];
89+
nestedCell.Width = 10f;
90+
nestedCell.AddParagraph().AppendText(":");
91+
//Accesses the instance of the nested table cell (third row, third cell)
92+
nestedCell = nestTable.Rows[2].Cells[2];
93+
nestedCell.AddParagraph().AppendText("1225021009");
94+
nestedCell.Width = 150f;
95+
96+
97+
//Accesses the instance of the nested table cell (fourth row, first cell)
98+
nestedCell = nestTable.Rows[3].Cells[0];
99+
nestedCell.Width = 56f;
100+
//Adds the content into nested cell
101+
nestedCell.AddParagraph().AppendText("Address");
102+
//Accesses the instance of the nested table cell (fourth row, second cell)
103+
nestedCell = nestTable.Rows[3].Cells[1];
104+
nestedCell.Width = 10f;
105+
nestedCell.AddParagraph().AppendText(":");
106+
//Accesses the instance of the nested table cell (fourth row, third cell)
107+
nestedCell = nestTable.Rows[3].Cells[2];
108+
nestedCell.AddParagraph().AppendText("212 E 106th St,New York, NY, 10029");
109+
nestedCell.Width = 150f;
110+
111+
112+
//Accesses the instance of the nested table cell (fifth row, first cell)
113+
nestedCell = nestTable.Rows[4].Cells[0];
114+
nestedCell.Width = 56f;
115+
//Adds the content into nested cell
116+
nestedCell.AddParagraph().AppendText("Phone");
117+
//Accesses the instance of the nested table cell (fifth row, second cell)
118+
nestedCell = nestTable.Rows[4].Cells[1];
119+
nestedCell.Width = 10f;
120+
nestedCell.AddParagraph().AppendText(":");
121+
//Accesses the instance of the nested table cell (fifth row, third cell)
122+
nestedCell = nestTable.Rows[4].Cells[2];
123+
nestedCell.AddParagraph().AppendText("(212) 360-2600");
124+
nestedCell.Width = 150f;
125+
126+
127+
//Accesses the instance of the nested table cell (sixth row, first cell)
128+
nestedCell = nestTable.Rows[5].Cells[0];
129+
nestedCell.Width = 56f;
130+
//Adds the content into nested cell
131+
nestedCell.AddParagraph().AppendText("Fax");
132+
//Accesses the instance of the nested table cell (sixth row, second cell)
133+
nestedCell = nestTable.Rows[5].Cells[1];
134+
nestedCell.Width = 10f;
135+
nestedCell.AddParagraph().AppendText(":");
136+
//Accesses the instance of the nested table cell (sixth row, tthird cell)
137+
nestedCell = nestTable.Rows[5].Cells[2];
138+
nestedCell.AddParagraph().AppendText("(212) 360-2616");
139+
nestedCell.Width = 150f;
140+
#endregion
141+
142+
#region Right side Table
143+
//Second around table
144+
IWTable table2 = section.AddTable();
145+
//Sets the table format.
146+
table2.TableFormat.WrapTextAround = true;
147+
table2.TableFormat.Positioning.HorizPosition = 250f;
148+
//Creates the specified number of rows and columns to table.
149+
table2.ResetCells(2, 1);
150+
151+
//Gets the second row first cell of the first table.
152+
cell = table2[0, 0];
153+
//Adds a paragraph into the cell.
154+
para = cell.AddParagraph();
155+
//Appends text to paragraph.
156+
para.AppendText("PATIENT");
157+
//Sets paragraph alignment as center.
158+
para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
159+
//Cell formats
160+
cell.CellFormat.BackColor = Syncfusion.Drawing.Color.Gray;
161+
cell.Width = 240;
162+
163+
//Gets the second row of the second table.
164+
row = table2.Rows[1];
165+
//Sets the row height.
166+
row.Height = 120f;
167+
168+
//Gets the second row first cell of the second table.
169+
cell = table2[1, 0];
170+
cell.Width = 240;
171+
cell.AddParagraph().AppendText("Alam, Carep");
172+
IWTable nestTable2 = cell.AddTable();
173+
nestTable2.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
174+
//Creates the specified number of rows and columns to nested table
175+
nestTable2.ResetCells(5, 3);
176+
177+
//Accesses the instance of the nested table cell (first row, first cell)
178+
WTableCell nestedCell2 = nestTable2.Rows[0].Cells[0];
179+
nestedCell2.Width = 56f;
180+
//Adds the content into nested cell
181+
nestedCell2.AddParagraph().AppendText("DOB");
182+
//Accesses the instance of the nested table cell (first row, second cell)
183+
nestedCell2 = nestTable2.Rows[0].Cells[1];
184+
nestedCell2.Width = 10f;
185+
nestedCell2.AddParagraph().AppendText(":");
186+
//Accesses the instance of the nested table cell (first row, third cell)
187+
nestedCell2 = nestTable2.Rows[0].Cells[2];
188+
nestedCell2.AddParagraph().AppendText("06/02/1954");
189+
nestedCell2.Width = 150f;
190+
191+
//Accesses the instance of the nested table cell (second row, first cell)
192+
nestedCell2 = nestTable2.Rows[1].Cells[0];
193+
nestedCell2.Width = 56f;
194+
//Adds the content into nested cell
195+
nestedCell2.AddParagraph().AppendText("Gender");
196+
//Accesses the instance of the nested table cell (second row, second cell)
197+
nestedCell2 = nestTable2.Rows[1].Cells[1];
198+
nestedCell2.Width = 10f;
199+
nestedCell2.AddParagraph().AppendText(":");
200+
//Accesses the instance of the nested table cell (second row, third cell)
201+
nestedCell2 = nestTable2.Rows[1].Cells[2];
202+
nestedCell2.AddParagraph().AppendText("M");
203+
nestedCell2.Width = 150f;
204+
205+
//Accesses the instance of the nested table cell (third row, first cell)
206+
nestedCell2 = nestTable2.Rows[2].Cells[0];
207+
nestedCell2.Width = 56f;
208+
//Adds the content into nested cell
209+
nestedCell2.AddParagraph().AppendText("Facility");
210+
//Accesses the instance of the nested table cell (third row, second cell)
211+
nestedCell2 = nestTable2.Rows[2].Cells[1];
212+
nestedCell2.Width = 10f;
213+
nestedCell2.AddParagraph().AppendText(":");
214+
//Accesses the instance of the nested table cell (third row, third cell)
215+
nestedCell2 = nestTable2.Rows[2].Cells[2];
216+
nestedCell2.AddParagraph().AppendText("1");
217+
nestedCell2.Width = 150f;
218+
219+
220+
//Accesses the instance of the nested table cell (fourth row, first cell)
221+
nestedCell2 = nestTable2.Rows[3].Cells[0];
222+
nestedCell2.Width = 56f;
223+
//Adds the content into nested cell
224+
nestedCell2.AddParagraph().AppendText("Address");
225+
//Accesses the instance of the nested table cell (fourth row, second cell)
226+
nestedCell2 = nestTable2.Rows[3].Cells[1];
227+
nestedCell2.Width = 10f;
228+
nestedCell2.AddParagraph().AppendText(":");
229+
//Accesses the instance of the nested table cell (fourth row, third cell)
230+
nestedCell2 = nestTable2.Rows[3].Cells[2];
231+
nestedCell2.AddParagraph().AppendText("G7, Schenectady, NY, 12345");
232+
nestedCell2.Width = 150f;
233+
234+
235+
//Accesses the instance of the nested table cell (fifth row, first cell)
236+
nestedCell2 = nestTable2.Rows[4].Cells[0];
237+
nestedCell2.Width = 56f;
238+
//Adds the content into nested cell
239+
nestedCell2.AddParagraph().AppendText("Phone");
240+
//Accesses the instance of the nested table cell (fifth row, second cell)
241+
nestedCell2 = nestTable2.Rows[4].Cells[1];
242+
nestedCell2.Width = 10f;
243+
nestedCell2.AddParagraph().AppendText(":");
244+
//Accesses the instance of the nested table cell (fifth row, third cell)
245+
nestedCell2 = nestTable2.Rows[4].Cells[2];
246+
nestedCell2.AddParagraph().AppendText("(123) 231-2342");
247+
nestedCell2.Width = 150f;
248+
#endregion
249+
250+
//Saves the Word document to MemoryStream
251+
using (FileStream stream = new FileStream(@"../../../Output/Result.docx", FileMode.OpenOrCreate))
252+
{
253+
document.Save(stream, FormatType.Docx);
254+
}
255+
}
256+
}
257+
}
258+
}

0 commit comments

Comments
 (0)