Nessuna descrizione

containers.rst 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. .. _containers:
  2. Containers
  3. ==========
  4. Containers are objects where you can put elements (texts, lists, tables,
  5. etc). There are 3 main containers, i.e. sections, headers, and footers.
  6. There are 3 elements that can also act as containers, i.e. textruns,
  7. table cells, and footnotes.
  8. Sections
  9. --------
  10. Every visible element in word is placed inside of a section. To create a
  11. section, use the following code:
  12. .. code-block:: php
  13. $section = $phpWord->addSection($sectionStyle);
  14. The ``$sectionStyle`` is an optional associative array that sets the
  15. section. Example:
  16. .. code-block:: php
  17. $sectionStyle = array(
  18. 'orientation' => 'landscape',
  19. 'marginTop' => 600,
  20. 'colsNum' => 2,
  21. );
  22. Page number
  23. ~~~~~~~~~~~
  24. You can change a section page number by using the ``pageNumberingStart``
  25. style of the section.
  26. .. code-block:: php
  27. // Method 1
  28. $section = $phpWord->addSection(array('pageNumberingStart' => 1));
  29. // Method 2
  30. $section = $phpWord->addSection();
  31. $section->getStyle()->setPageNumberingStart(1);
  32. Multicolumn
  33. ~~~~~~~~~~~
  34. You can change a section layout to multicolumn (like in a newspaper) by
  35. using the ``breakType`` and ``colsNum`` style of the section.
  36. .. code-block:: php
  37. // Method 1
  38. $section = $phpWord->addSection(array('breakType' => 'continuous', 'colsNum' => 2));
  39. // Method 2
  40. $section = $phpWord->addSection();
  41. $section->getStyle()->setBreakType('continuous');
  42. $section->getStyle()->setColsNum(2);
  43. Line numbering
  44. ~~~~~~~~~~~~~~
  45. You can apply line numbering to a section by using the ``lineNumbering``
  46. style of the section.
  47. .. code-block:: php
  48. // Method 1
  49. $section = $phpWord->addSection(array('lineNumbering' => array()));
  50. // Method 2
  51. $section = $phpWord->addSection();
  52. $section->getStyle()->setLineNumbering(array());
  53. Below are the properties of the line numbering style.
  54. - ``start`` Line numbering starting value
  55. - ``increment`` Line number increments
  56. - ``distance`` Distance between text and line numbering in twip
  57. - ``restart`` Line numbering restart setting
  58. continuous\|newPage\|newSection
  59. Headers
  60. -------
  61. Each section can have its own header reference. To create a header use
  62. the ``addHeader`` method:
  63. .. code-block:: php
  64. $header = $section->addHeader();
  65. Be sure to save the result in a local object. You can use all elements
  66. that are available for the footer. See "Footer" section for detail.
  67. Additionally, only inside of the header reference you can add watermarks
  68. or background pictures. See "Watermarks" section.
  69. Footers
  70. -------
  71. Each section can have its own footer reference. To create a footer, use
  72. the ``addFooter`` method:
  73. .. code-block:: php
  74. $footer = $section->addFooter();
  75. Be sure to save the result in a local object to add elements to a
  76. footer. You can add the following elements to footers:
  77. - Texts ``addText`` and ``createTextrun``
  78. - Text breaks
  79. - Images
  80. - Tables
  81. - Preserve text
  82. See the "Elements" section for the detail of each elements.
  83. Other containers
  84. ----------------
  85. Textruns, table cells, and footnotes are elements that can also act as
  86. containers. See the corresponding "Elements" section for the detail of
  87. each elements.