shapes_table.rst 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. .. _shapes_table:
  2. Tables
  3. ======
  4. To create a table, use `createTableShape` method of slide.
  5. Example:
  6. .. code-block:: php
  7. $tableShape = $slide->createTableShape($columns);
  8. Rows
  9. -------
  10. A row is a child of a table. For creating a row, use `createRow` method of a Table shape.
  11. .. code-block:: php
  12. $tableShape = $slide->createTableShape($columns);
  13. $row = $tableShape->createRow();
  14. Cells
  15. -------
  16. A cell is a child of a row.
  17. You can access cell objects with `nextCell` method of a Row object.
  18. .. code-block:: php
  19. $tableShape = $slide->createTableShape($columns);
  20. $row = $tableShape->createRow();
  21. // Get the first cell
  22. $cellA1 = $row->nextCell();
  23. // Get the second cell
  24. $cellA2 = $row->nextCell();
  25. You can access cell object directly.
  26. .. code-block:: php
  27. $tableShape = $slide->createTableShape($columns);
  28. $row = $tableShape->createRow();
  29. // Get the first cell
  30. $cellA1 = $row->getCell(0);
  31. // Get the second cell
  32. $cellA2 = $row->getCell(1);
  33. Define margins of a cell
  34. ~~~~~~~~~~~~~~~~~~~~~~~~
  35. Margins of cells are defined by margins of the first paragraph of cell.
  36. Margins of cells are defined in pixels.
  37. For defining margins of cell, you can use the `setMargin*` method of a Alignment object of the active paragraph of a Cell object.
  38. .. code-block:: php
  39. $tableShape = $slide->createTableShape($columns);
  40. $row = $tableShape->createRow();
  41. $cellA1 = $row->nextCell();
  42. $cellA1->getActiveParagraph()->getAlignment()
  43. ->setMarginBottom(20)
  44. ->setMarginLeft(40)
  45. ->setMarginRight(60)
  46. ->setMarginTop(80);
  47. Define the text direction of a cell
  48. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49. For defining the text direction of cell, you can use the `setTextDirection` method of the `getAlignment` method of a Cell object.
  50. The width is in pixels.
  51. .. code-block:: php
  52. $tableShape = $slide->createTableShape($columns);
  53. $row = $tableShape->createRow();
  54. $cellA1 = $row->nextCell();
  55. $cellA1->getAlignment()->setTextDirection(\PhpOffice\PhpPresentation\Style\Alignment::TEXT_DIRECTION_VERTICAL_270);
  56. Define the width of a cell
  57. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  58. The width of cells are defined by the width of cell of the first row.
  59. If not defined, all cells widths are calculated from the width of the shape and the number of columns.
  60. For defining the width of cell, you can use the `setWidth` method of a Cell object.
  61. The width is in pixels.
  62. .. code-block:: php
  63. $tableShape = $slide->createTableShape($columns);
  64. $row = $tableShape->createRow();
  65. $cellA1 = $row->nextCell();
  66. $cellA1->setWidth(100);