Table.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * PHPWord
  4. *
  5. * Copyright (c) 2011 PHPWord
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPWord
  22. * @package PHPWord
  23. * @copyright Copyright (c) 010 PHPWord
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version Beta 0.6.3, 08.07.2011
  26. */
  27. /**
  28. * PHPWord_Section_Table
  29. *
  30. * @category PHPWord
  31. * @package PHPWord_Section
  32. * @copyright Copyright (c) 2011 PHPWord
  33. */
  34. class PHPWord_Section_Table {
  35. /**
  36. * Table style
  37. *
  38. * @var PHPWord_Style_Table
  39. */
  40. private $_style;
  41. /**
  42. * Table rows
  43. *
  44. * @var array
  45. */
  46. private $_rows = array();
  47. /**
  48. * Row heights
  49. *
  50. * @var array
  51. */
  52. private $_rowHeights = array();
  53. /**
  54. * Table holder
  55. *
  56. * @var string
  57. */
  58. private $_insideOf = null;
  59. /**
  60. * Table holder count
  61. *
  62. * @var array
  63. */
  64. private $_pCount;
  65. /**
  66. * Create a new table
  67. *
  68. * @param string $insideOf
  69. * @param int $pCount
  70. * @param mixed $style
  71. */
  72. public function __construct($insideOf, $pCount, $style = null) {
  73. $this->_insideOf = $insideOf;
  74. $this->_pCount = $pCount;
  75. if(!is_null($style)) {
  76. if(is_array($style)) {
  77. $this->_style = new PHPWord_Style_Table();
  78. foreach($style as $key => $value) {
  79. if(substr($key, 0, 1) != '_') {
  80. $key = '_'.$key;
  81. }
  82. $this->_style->setStyleValue($key, $value);
  83. }
  84. } else {
  85. $this->_style = $style;
  86. }
  87. }
  88. }
  89. /**
  90. * Add a row
  91. *
  92. * @param int $height
  93. */
  94. public function addRow($height = null) {
  95. $this->_rows[] = array();
  96. $this->_rowHeights[] = $height;
  97. }
  98. /**
  99. * Add a cell
  100. *
  101. * @param int $width
  102. * @param mixed $style
  103. * @return PHPWord_Section_Table_Cell
  104. */
  105. public function addCell($width, $style = null) {
  106. $cell = new PHPWord_Section_Table_Cell($this->_insideOf, $this->_pCount, $width, $style);
  107. $i = count($this->_rows) - 1;
  108. $this->_rows[$i][] = $cell;
  109. return $cell;
  110. }
  111. /**
  112. * Get all rows
  113. *
  114. * @return array
  115. */
  116. public function getRows() {
  117. return $this->_rows;
  118. }
  119. /**
  120. * Get all row heights
  121. *
  122. * @return array
  123. */
  124. public function getRowHeights() {
  125. return $this->_rowHeights;
  126. }
  127. /**
  128. * Get table style
  129. *
  130. * @return PHPWord_Style_Table
  131. */
  132. public function getStyle() {
  133. return $this->_style;
  134. }
  135. }
  136. ?>