File tree 1 file changed +6
-3
lines changed
Mail-Merge/Generate-Documents-for-each-record/.NET/Generate-Documents-for-each-record
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 1
- using Syncfusion . DocIO ;
1
+ using Syncfusion . DocIO ;
2
2
using Syncfusion . DocIO . DLS ;
3
3
using System . Data ;
4
4
using System . IO ;
@@ -13,13 +13,15 @@ static void Main(string[] args)
13
13
using ( FileStream fileStream = new FileStream ( Path . GetFullPath ( @"Data/Template.docx" ) , FileMode . Open ) )
14
14
{
15
15
//Load file stream into Word document.
16
- using ( WordDocument document = new WordDocument ( fileStream , FormatType . Docx ) )
16
+ using ( WordDocument template = new WordDocument ( fileStream , FormatType . Docx ) )
17
17
{
18
18
//Get the data for mail merge.
19
19
DataTable table = GetDataTable ( ) ;
20
20
//Iterate to the each row and generate mail merged document for each rows.
21
21
for ( int i = 0 ; i < table . Rows . Count ; i ++ )
22
22
{
23
+ //Clones the template document for creating new document for each record in the data source
24
+ WordDocument document = template . Clone ( ) ;
23
25
//Executes mail merge using the data row.
24
26
document . MailMerge . Execute ( table . Rows [ i ] ) ;
25
27
@@ -29,6 +31,8 @@ static void Main(string[] args)
29
31
//Save the Word document to the file stream.
30
32
document . Save ( outputFileStream , FormatType . Docx ) ;
31
33
}
34
+ //Releases the resources occupied by WordDocument instance
35
+ document . Dispose ( ) ;
32
36
}
33
37
}
34
38
}
@@ -67,4 +71,3 @@ static DataTable GetDataTable()
67
71
}
68
72
}
69
73
}
70
-
You can’t perform that action at this time.
0 commit comments