@@ -375,7 +375,187 @@ public void CreateTableWithCellStylingsInASlide(string documentDirectory = exist
375
375
throw new FileFormat . Slides . Common . FileFormatException ( "An error occurred." , ex ) ;
376
376
}
377
377
}
378
+ /// <summary>
379
+ /// Creates a table with a predefined theme applied to the entire table in a slide of a PowerPoint presentation.
380
+ /// </summary>
381
+ /// <param name="documentDirectory">The directory where the PowerPoint presentation is located.</param>
382
+ /// <param name="filename">The name of the PowerPoint file.</param>
383
+ public void CreateTableWithThemeInASlide ( string documentDirectory = existingDocsDirectory , string filename = "test.pptx" )
384
+ {
385
+ try
386
+ {
387
+ // Create instance of presentation
388
+ Presentation presentation = Presentation . Open ( $ "{ documentDirectory } /{ filename } ") ;
389
+ // Get desired slide
390
+ Slide slide = presentation . GetSlides ( ) [ 1 ] ;
391
+ // Create a new table
392
+ Table table = new Table ( ) ;
393
+ // Set theme of a table
394
+ table . Theme = Table . TableStyle . LightStyle1 ;
395
+ // Define table columns
396
+ TableColumn col1 = new TableColumn ( ) ;
397
+ col1 . Name = "ID" ;
398
+ table . Columns . Add ( col1 ) ;
399
+ TableColumn col2 = new TableColumn ( ) ;
400
+ col2 . Name = "Name" ;
401
+ table . Columns . Add ( col2 ) ;
402
+ TableColumn col3 = new TableColumn ( ) ;
403
+ col3 . Name = "City" ;
404
+ table . Columns . Add ( col3 ) ;
405
+
406
+ //1st row
407
+ TableRow row1 = new TableRow ( table ) ;
408
+ // Create cells of first row
409
+
410
+ // Assign values to the properties of Stylings
411
+ Stylings stylings = new Stylings ( ) ;
412
+ stylings . FontSize = 14 ;
413
+ stylings . Alignment = FileFormat . Slides . Common . Enumerations . TextAlignment . Left ;
414
+ stylings . FontFamily = "Baguet Script" ;
415
+ stylings . TextColor = Colors . Red ;
416
+
417
+ TableCell cell11 = new TableCell ( row1 ) ;
418
+ cell11 . CellStylings = stylings ;
419
+ cell11 . Text = "907" ;
420
+ cell11 . ID = col1 . Name ;
421
+ row1 . AddCell ( cell11 ) ;
422
+ TableCell cell12 = new TableCell ( row1 ) ;
423
+ cell12 . Text = "John" ;
424
+ cell12 . ID = col2 . Name ;
425
+ row1 . AddCell ( cell12 ) ;
426
+ TableCell cell13 = new TableCell ( row1 ) ;
427
+ cell13 . Text = "Chicago" ;
428
+ cell13 . ID = col3 . Name ;
429
+ // Add cells to row
430
+ row1 . AddCell ( cell13 ) ;
431
+ // Add row to table
432
+ table . AddRow ( row1 ) ;
378
433
434
+ //2nd Row
435
+ TableRow row2 = new TableRow ( table ) ;
436
+ TableCell cell21 = new TableCell ( row2 ) ;
437
+ cell21 . Text = "908" ;
438
+ cell21 . ID = col1 . Name ;
439
+ row2 . AddCell ( cell21 ) ;
440
+ TableCell cell22 = new TableCell ( row2 ) ;
441
+ cell22 . Text = "Chris" ;
442
+ cell22 . ID = col2 . Name ;
443
+ row2 . AddCell ( cell22 ) ;
444
+ TableCell cell23 = new TableCell ( row2 ) ;
445
+ cell23 . Text = "New York" ;
446
+ cell23 . ID = col3 . Name ;
447
+ row2 . AddCell ( cell23 ) ;
448
+ table . AddRow ( row2 ) ;
449
+ //Set Table dimensions
450
+ table . Width = 500.0 ;
451
+ table . Height = 200.0 ;
452
+ table . X = 300.0 ;
453
+ table . Y = 500.0 ;
454
+ slide . AddTable ( table ) ;
455
+
456
+ presentation . Save ( ) ;
457
+ }
458
+ catch ( System . Exception ex )
459
+ {
460
+ throw new FileFormat . Slides . Common . FileFormatException ( "An error occurred." , ex ) ;
461
+ }
462
+ }
463
+
464
+ /// <summary>
465
+ /// Adds a new row to an existing table in a slide of a PowerPoint presentation.
466
+ /// </summary>
467
+ /// <param name="documentDirectory">The directory where the PowerPoint presentation is located.</param>
468
+ /// <param name="filename">The name of the PowerPoint file.</param>
469
+ public void AddRowInAnExistingTableInASlide ( string documentDirectory = existingDocsDirectory , string filename = "test.pptx" )
470
+ {
471
+ try
472
+ {
473
+ // Create instance of presentation
474
+ Presentation presentation = Presentation . Open ( $ "{ documentDirectory } /{ filename } ") ;
475
+ // Get desired slide
476
+ Slide slide = presentation . GetSlides ( ) [ 1 ] ;
477
+ // Get desired table
478
+ Table table = slide . Tables [ 0 ] ;
479
+
480
+ // Create row
481
+ TableRow row2 = new TableRow ( table ) ;
482
+ TableCell cell21 = new TableCell ( row2 ) ;
483
+ cell21 . Text = "915" ;
484
+ // Set the cell ID
485
+ cell21 . ID = table . Columns [ 0 ] . Name ;
486
+ row2 . AddCell ( cell21 ) ;
487
+ TableCell cell22 = new TableCell ( row2 ) ;
488
+ cell22 . Text = "Allen" ;
489
+ cell22 . ID = table . Columns [ 1 ] . Name ;
490
+ row2 . AddCell ( cell22 ) ;
491
+ TableCell cell23 = new TableCell ( row2 ) ;
492
+ cell23 . Text = "New York" ;
493
+ cell23 . ID = table . Columns [ 2 ] . Name ;
494
+ row2 . AddCell ( cell23 ) ;
495
+ // Add row to table
496
+ table . AddRow ( row2 ) ;
497
+ // Update table
498
+ table . Update ( ) ;
499
+ // Save presentation
500
+ presentation . Save ( ) ;
501
+ }
502
+ catch ( System . Exception ex )
503
+ {
504
+ throw new FileFormat . Slides . Common . FileFormatException ( "An error occurred." , ex ) ;
505
+ }
506
+ }
507
+
508
+ /// <summary>
509
+ /// Adds a new column with cell values to an existing table in a slide of a PowerPoint presentation.
510
+ /// </summary>
511
+ /// <param name="documentDirectory">The directory where the PowerPoint presentation is located.</param>
512
+ /// <param name="filename">The name of the PowerPoint file.</param>
513
+ public void AddColumnWithCellValuesInAnExistingTableInASlide ( string documentDirectory = existingDocsDirectory , string filename = "test.pptx" )
514
+ {
515
+ try
516
+ {
517
+ // Create instance of presentation
518
+ Presentation presentation = Presentation . Open ( $ "{ documentDirectory } /{ filename } ") ;
519
+ // Get desired slide
520
+ Slide slide = presentation . GetSlides ( ) [ 1 ] ;
521
+ // Get desired table
522
+ Table table = slide . Tables [ 0 ] ;
523
+
524
+ TableColumn col3 = new TableColumn ( ) ;
525
+ col3 . Name = "City" ;
526
+ table . Columns . Add ( col3 ) ;
527
+
528
+ // Create a new cells for the new column
529
+ TableCell newCell1 = new TableCell ( ) ;
530
+ newCell1 . Text = "Chicago" ;
531
+ newCell1 . ID = col3 . Name ;
532
+ table . Rows [ 0 ] . AddCell ( newCell1 ) ;
533
+
534
+ TableCell newCell2 = new TableCell ( ) ;
535
+ newCell2 . ID = col3 . Name ;
536
+ newCell2 . Text = "New York" ;
537
+ table . Rows [ 1 ] . AddCell ( newCell2 ) ;
538
+
539
+ TableCell newCell3 = new TableCell ( ) ;
540
+ newCell3 . ID = col3 . Name ;
541
+ newCell3 . Text = "Chicago" ;
542
+ table . Rows [ 2 ] . AddCell ( newCell3 ) ;
543
+
544
+ TableCell newCell4 = new TableCell ( ) ;
545
+ newCell4 . ID = col3 . Name ;
546
+ newCell4 . Text = "California" ;
547
+ table . Rows [ 3 ] . AddCell ( newCell4 ) ;
548
+
549
+ // Update table
550
+ table . Update ( ) ;
551
+ // Save presentation
552
+ presentation . Save ( ) ;
553
+ }
554
+ catch ( System . Exception ex )
555
+ {
556
+ throw new FileFormat . Slides . Common . FileFormatException ( "An error occurred." , ex ) ;
557
+ }
558
+ }
379
559
380
560
}
381
561
0 commit comments