@@ -22,8 +22,8 @@ namespace FileFormat_Tests
2222 public class TestDocumentClass
2323 {
2424
25- private static string testDir = "/Users/fahadadeelqazi/github/Aspose/ FileFormat.Words-for-.NET /TestDocs/" ;
26- private static string processedDir = "/Users/fahadadeelqazi/github/Aspose/ FileFormat.Words-for-.NET /TestDocs/ProcessedDocs/" ;
25+ private static string testDir = "/Users/Mustafa/Projects/ FileFormat.Words/TestDocs/" ;
26+ private static string processedDir = "/Users/Mustafa/Projects/ FileFormat.Words/TestDocs/ProcessedDocs/" ;
2727 private static string testDoc = "UbuntuSoftwareCenter" ;
2828 /// <summary>
2929 /// Test #1 Create empty WordprocessingML document and save to disk
@@ -95,8 +95,8 @@ public void TestGetBuiltInDocumentProperties()
9595 [ TestClass ]
9696 public class ParagraphTests
9797 {
98- private static string testDir = "/Users/fahadadeelqazi/github/Aspose/ FileFormat.Words-for-.NET /TestDocs/" ;
99- private static string processedDir = "/Users/fahadadeelqazi/github/Aspose/ FileFormat.Words-for-.NET /TestDocs/ProcessedDocs/" ;
98+ private static string testDir = "/Users/Mustafa/Projects/ FileFormat.Words/TestDocs/" ;
99+ private static string processedDir = "/Users/Mustafa/Projects/ FileFormat.Words/TestDocs/ProcessedDocs/" ;
100100 private static string testDoc = "UbuntuSoftwareCenter" ;
101101
102102 [ TestMethod ]
@@ -253,8 +253,8 @@ public void GetRuns_ReturnsCorrectFormatting()
253253 public class RunTests
254254 {
255255
256- private static string testDir = "/Users/fahadadeelqazi/github/Aspose/ FileFormat.Words-for-.NET /TestDocs/" ;
257- private static string processedDir = "/Users/fahadadeelqazi/github/Aspose/ FileFormat.Words-for-.NET /TestDocs/ProcessedDocs/" ;
256+ private static string testDir = "/Users/Mustafa/Projects/ FileFormat.Words/TestDocs/" ;
257+ private static string processedDir = "/Users/Mustafa/Projects/ FileFormat.Words/TestDocs/ProcessedDocs/" ;
258258 private static string testDoc = "UbuntuSoftwareCenter" ;
259259 [ TestMethod ]
260260 public void TestRunText ( )
@@ -323,18 +323,16 @@ public void TestRunIsItalic()
323323 [ TestClass ]
324324 public class TestsTableClass
325325 {
326- private const string TestFile = "/Users/fahadadeelqazi/github/Aspose/ FileFormat.Words-for-.NET /TestDocs/table .docx" ;
326+ private const string TestFile = "/Users/Mustafa/Projects/ FileFormat.Words/TestDocs/Docs .docx" ;
327327
328328 [ TestMethod ]
329329 public void TestCreateTable ( )
330330 {
331331 var doc = new Document ( ) ;
332- var body = new Body ( doc ) ;
333- Table table = new Table ( ) ;
334- TableRow tableRow = new TableRow ( ) ;
335- TableRow tableRow2 = new TableRow ( ) ;
332+ Body body = new Body ( doc ) ;
336333
337- TableProperties tableProperties = new TableProperties ( ) ;
334+ // ********** this code block creates a table into a word document ********** //
335+ Table table = new Table ( ) ;
338336
339337 TopBorder topBorder = new TopBorder ( ) ;
340338 topBorder . basicBlackSquares_border ( 20 ) ;
@@ -355,91 +353,162 @@ public void TestCreateTable()
355353 insideHorizontalBorder . basicBlackSquares_border ( 20 ) ;
356354
357355 TableBorders tableBorders = new TableBorders ( ) ;
358-
359356 tableBorders . AppendTopBorder ( topBorder ) ;
360357 tableBorders . AppendBottomBorder ( bottomBorder ) ;
361358 tableBorders . AppendRightBorder ( rightBorder ) ;
362359 tableBorders . AppendLeftBorder ( leftBorder ) ;
363360 tableBorders . AppendInsideVerticalBorder ( insideVerticalBorder ) ;
364361 tableBorders . AppendInsideHorizontalBorder ( insideHorizontalBorder ) ;
365362
366- tableProperties . Append ( tableBorders ) ;
363+ // specify its border style of the table
364+ TableProperties tblProp = new TableProperties ( ) ;
365+
366+ tblProp . Append ( tableBorders ) ;
367367
368368 TableJustification tableJustification = new TableJustification ( ) ;
369- tableJustification . AlignRight ( ) ;
370- tableProperties . Append ( tableJustification ) ;
371- table . AppendChild ( tableProperties ) ;
369+ tableJustification . AlignLeft ( ) ;
370+ // set the position of the table to Right.
371+ tblProp . Append ( tableJustification ) ;
372+
373+ // create two table rows
374+ TableRow tableRow = new TableRow ( ) ;
375+ TableRow tableRow2 = new TableRow ( ) ;
372376
377+ // create table cell
373378 TableCell tableCell = new TableCell ( ) ;
379+ Paragraph para = new Paragraph ( ) ;
380+ Run run = new Run ( ) ;
374381
375- TableCellWidth tableCellWidth = new TableCellWidth ( "1400" ) ;
376- TableCellProperties tableCellProperties = new TableCellProperties ( ) ;
377- tableCellProperties . Append ( tableCellWidth ) ;
378- tableCell . Append ( tableCellProperties ) ;
382+ // set the header of the first column
383+ table . TableHeaders ( "Name" ) ;
384+ run . Text = "Mustafa" ;
385+ para . AppendChild ( run ) ;
386+ tableCell . Append ( para ) ;
379387
380- TableCell tableCell2 = new TableCell ( ) ;
381- TableCellWidth tableCellWidth2 = new TableCellWidth ( "900" ) ;
382- TableCellProperties tableCellProperties2 = new TableCellProperties ( ) ;
383- tableCellProperties2 . Append ( tableCellWidth2 ) ;
384- tableCell2 . Append ( tableCellProperties2 ) ;
385-
386- table . TableHeaders ( "name" ) ;
387- table . TableHeaders ( "age" ) ;
388- Paragraph paragraph = new Paragraph ( ) ;
389- Run run = new Run ( ) ;
390- run . Text = "abdul" ;
391- paragraph . AppendChild ( run ) ;
392- tableCell . Append ( paragraph ) ;
388+ // create table properties
389+ TableCellProperties tblCellProps = new TableCellProperties ( ) ;
390+
391+ // set the width of table cell
392+ tblCellProps . Append ( new TableCellWidth ( "2400" ) ) ;
393+ tableCell . Append ( tblCellProps ) ;
393394
394- Paragraph paragraph2 = new Paragraph ( ) ;
395+ TableCell tableCell2 = new TableCell ( ) ;
396+ Paragraph para2 = new Paragraph ( ) ;
395397 Run run2 = new Run ( ) ;
396- run2 . Text = "10" ;
397- paragraph2 . AppendChild ( run2 ) ;
398- tableCell2 . Append ( paragraph2 ) ;
398+
399+ // set the header of the second column
400+ table . TableHeaders ( "Nationality" ) ;
401+ run2 . Text = "Pakistani" ;
402+ para2 . AppendChild ( run2 ) ;
403+ tableCell2 . Append ( para2 ) ;
404+
405+ TableCellProperties tblCellProps2 = new TableCellProperties ( ) ;
406+
407+ VerticalMerge verticalMerge = new VerticalMerge ( ) ;
408+ verticalMerge . MergeRestart = true ;
409+ tblCellProps . Append ( verticalMerge ) ;
410+
411+ HorizontalMerge horizontalMerge = new HorizontalMerge ( ) ;
412+ horizontalMerge . MergeRestart = true ;
413+ tblCellProps2 . Append ( horizontalMerge ) ;
414+
415+ tblCellProps2 . Append ( new TableCellWidth ( "1400" ) ) ;
416+ tableCell2 . Append ( tblCellProps2 ) ;
399417
400418 TableCell tableCell3 = new TableCell ( ) ;
401- Paragraph paragraph3 = new Paragraph ( ) ;
419+ Paragraph para3 = new Paragraph ( ) ;
402420 Run run3 = new Run ( ) ;
403- run3 . Text = "mustafa" ;
404- paragraph3 . AppendChild ( run3 ) ;
405- tableCell3 . Append ( paragraph3 ) ;
406-
407- TableCell tableCell4 = new TableCell ( ) ;
408- Paragraph paragraph4 = new Paragraph ( ) ;
409- Run run4 = new Run ( ) ;
410- run4 . Text = "30" ;
411- paragraph4 . AppendChild ( run4 ) ;
412- tableCell4 . Append ( paragraph4 ) ;
421+ table . TableHeaders ( "Age" ) ;
422+ run3 . Text = "30" ;
423+ para3 . AppendChild ( run3 ) ;
424+ tableCell3 . Append ( para3 ) ;
425+
426+ HorizontalMerge horizontalMerge1 = new HorizontalMerge ( ) ;
427+ horizontalMerge1 . MergeContinue = true ;
428+ TableCellProperties tblCellProps3 = new TableCellProperties ( ) ;
429+ tblCellProps3 . Append ( new TableCellWidth ( "1400" ) ) ;
430+ tblCellProps3 . Append ( horizontalMerge1 ) ;
431+ tableCell3 . Append ( tblCellProps3 ) ;
413432
414433 tableRow . Append ( tableCell ) ;
415434 tableRow . Append ( tableCell2 ) ;
435+ tableRow . Append ( tableCell3 ) ;
436+
437+ // create table cell
438+ TableCell _tableCell = new TableCell ( ) ;
439+ Paragraph _para = new Paragraph ( ) ;
440+ Run _run = new Run ( ) ;
441+
442+ _run . Text = "sultan" ;
443+ _para . AppendChild ( _run ) ;
444+ _tableCell . Append ( _para ) ;
445+
446+ TableCellProperties tblCellProps1_ = new TableCellProperties ( ) ;
447+
448+ VerticalMerge verticalMerge2 = new VerticalMerge ( ) ;
449+ verticalMerge2 . MergeContinue = true ;
450+ tblCellProps1_ . Append ( verticalMerge2 ) ;
451+
452+ tblCellProps1_ . Append ( new TableCellWidth ( "2400" ) ) ;
453+ _tableCell . Append ( tblCellProps1_ ) ;
454+
416455
417- tableRow2 . Append ( tableCell3 ) ;
418- tableRow2 . Append ( tableCell4 ) ;
456+ TableCell _tableCell2 = new TableCell ( ) ;
457+ Paragraph _para2 = new Paragraph ( ) ;
458+ Run _run2 = new Run ( ) ;
459+
460+ _run2 . Text = "British" ;
461+ _para2 . AppendChild ( _run2 ) ;
462+ _tableCell2 . Append ( _para2 ) ;
463+
464+ TableCellProperties tblCellProps2_ = new TableCellProperties ( ) ;
465+ tblCellProps2_ . Append ( new TableCellWidth ( "1400" ) ) ;
466+ _tableCell2 . Append ( tblCellProps2_ ) ;
467+
468+ TableCell _tableCell3 = new TableCell ( ) ;
469+ Paragraph _para3 = new Paragraph ( ) ;
470+ Run _run3 = new Run ( ) ;
471+
472+ _run3 . Text = "2" ;
473+ _para3 . AppendChild ( _run3 ) ;
474+ _tableCell3 . Append ( _para3 ) ;
475+
476+ TableCellProperties tblCellProps3_ = new TableCellProperties ( ) ;
477+ tblCellProps3_ . Append ( new TableCellWidth ( "1400" ) ) ;
478+ _tableCell3 . Append ( tblCellProps3_ ) ;
479+
480+ tableRow2 . Append ( _tableCell ) ;
481+ tableRow2 . Append ( _tableCell2 ) ;
482+ tableRow2 . Append ( _tableCell3 ) ;
483+
484+ table . AppendChild ( tblProp ) ;
419485 table . Append ( tableRow ) ;
420486 table . Append ( tableRow2 ) ;
487+
421488 body . AppendChild ( table ) ;
422- int count = body . FindTableByText ( "name" ) ;
489+
490+
491+ int count = body . FindTableByText ( "Name" ) ;
423492 Assert . AreEqual ( count , 1 ) ;
424493 foreach ( TableRow row in body . FindTableRow ( 0 , 1 ) )
425494 {
426- Assert . AreEqual ( int . Parse ( row . NumberOfCell ) , 2 ) ;
495+ Assert . AreEqual ( int . Parse ( row . NumberOfCell ) , 3 ) ;
427496 }
428497 foreach ( TableCell cell in body . FindTableCell ( 0 , 0 , 0 ) )
429498 {
430- Assert . AreEqual ( cell . CellWidth , "1400 " ) ;
431- Assert . AreEqual ( cell . Text , "name " ) ;
499+ Assert . AreEqual ( cell . CellWidth , "2400 " ) ;
500+ Assert . AreEqual ( cell . Text , "Name " ) ;
432501 }
433502
434503 Assert . AreEqual ( body . getDocumentTables . Count ( ) , 1 ) ;
435504 foreach ( FileFormat . Words . Table . Table props in body . getDocumentTables )
436505 {
437506 Assert . AreEqual ( int . Parse ( props . NumberOfRows ) , 3 ) ;
438- Assert . AreEqual ( int . Parse ( props . NumberOfColumns ) , 2 ) ;
439- Assert . AreEqual ( int . Parse ( props . NumberOfCells ) , 6 ) ;
507+ Assert . AreEqual ( int . Parse ( props . NumberOfColumns ) , 3 ) ;
508+ Assert . AreEqual ( int . Parse ( props . NumberOfCells ) , 9 ) ;
440509 Assert . AreEqual ( props . TableBorder , "basicBlackSquares" ) ;
441- Assert . AreEqual ( props . CellWidth , "1400 " ) ;
442- Assert . AreEqual ( props . TablePosition , "right " ) ;
510+ Assert . AreEqual ( props . CellWidth , "2400 " ) ;
511+ Assert . AreEqual ( props . TablePosition , "left " ) ;
443512
444513 }
445514 Assert . AreEqual ( table . ChangeTextInCell ( TestFile , 0 , 0 , 0 , "changed" ) , "Cell updated successfully" ) ;
@@ -453,8 +522,8 @@ public void TestCreateTable()
453522 [ TestClass ]
454523 public class ImageTests
455524 {
456- private static string testDir = "/Users/fahadadeelqazi/github/Aspose/ FileFormat.Words-for-.NET /TestDocs/" ;
457- private static string processedDir = "/Users/fahadadeelqazi/github/Aspose/ FileFormat.Words-for-.NET /TestDocs/ProcessedDocs/" ;
525+ private static string testDir = "/Users/Mustafa/Projects/ FileFormat.Words/TestDocs/" ;
526+ private static string processedDir = "/Users/Mustafa/Projects/ FileFormat.Words/TestDocs/ProcessedDocs/" ;
458527 private static string testDoc = "UbuntuSoftwareCenter" ;
459528 [ TestMethod ]
460529 public void TestAddImageToDoc ( )
0 commit comments