@@ -10,14 +10,16 @@ static void Main(string[] args)
1010 // Creates a new Word document.
1111 using ( WordDocument document = new WordDocument ( ) )
1212 {
13+ // Adds a default section and paragraph to the document.
1314 document . EnsureMinimal ( ) ;
14- //Adds a new Table to the text body.
1515
16+ //Adds a new Table to the text body.
1617 WTable table = document . LastSection . Body . AddTable ( ) as WTable ;
1718
1819 //Insert rows to the table. This will apply the format to a whole table.
1920 table . ResetCells ( 5 , 5 ) ;
2021
22+ // Sample text collection used to populate table cells.
2123 string [ ] randomTexts =
2224 {
2325 "Lorem ipsum dolor sit amet" ,
@@ -31,23 +33,24 @@ static void Main(string[] args)
3133 "Sample paragraph content" ,
3234 "Testing table layout"
3335 } ;
34-
36+ // Populate each table cell with sample text.
3537 for ( int i = 0 ; i < table . Rows . Count ; i ++ )
3638 {
3739 WTableRow row = table . Rows [ i ] ;
3840
3941 for ( int j = 0 ; j < row . Cells . Count ; j ++ )
4042 {
43+ // Add a paragraph to the current cell.
4144 WParagraph paragraph = row . Cells [ j ] . AddParagraph ( ) as WParagraph ;
4245
4346 // Add random text
44- paragraph . AppendText (
45- randomTexts [ ( i * row . Cells . Count + j ) % randomTexts . Length ] ) ;
47+ paragraph . AppendText ( randomTexts [ ( i * row . Cells . Count + j ) % randomTexts . Length ] ) ;
4648 }
4749 }
50+ // Insert page breaks between table rows.
4851 InserPageBreak ( table ) ;
4952 //saves the document
50- document . Save ( Path . GetFullPath ( "../../../ Output/Output.docx" ) ) ;
53+ document . Save ( Path . GetFullPath ( "Output/Output.docx" ) ) ;
5154 }
5255 }
5356
0 commit comments