暂无描述

Cell.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /**
  3. * This file is part of PHPWord - A pure PHP library for reading and writing
  4. * word processing documents.
  5. *
  6. * PHPWord is free software distributed under the terms of the GNU Lesser
  7. * General Public License version 3 as published by the Free Software Foundation.
  8. *
  9. * For the full copyright and license information, please read the LICENSE
  10. * file that was distributed with this source code. For the full list of
  11. * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
  12. *
  13. * @link https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2014 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Style;
  18. /**
  19. * Table cell style
  20. */
  21. class Cell extends Border
  22. {
  23. /**
  24. * Vertical alignment constants
  25. *
  26. * @const string
  27. */
  28. const VALIGN_TOP = 'top';
  29. const VALIGN_CENTER = 'center';
  30. const VALIGN_BOTTOM = 'bottom';
  31. const VALIGN_BOTH = 'both';
  32. /**
  33. * Text direction constants
  34. *
  35. * @const string
  36. */
  37. const TEXT_DIR_BTLR = 'btLr';
  38. const TEXT_DIR_TBRL = 'tbRl';
  39. /**
  40. * Vertical merge (rowspan) constants
  41. *
  42. * @const string
  43. */
  44. const VMERGE_RESTART = 'restart';
  45. const VMERGE_CONTINUE = 'continue';
  46. /**
  47. * Default border color
  48. *
  49. * @const string
  50. */
  51. const DEFAULT_BORDER_COLOR = '000000';
  52. /**
  53. * Vertical align (top, center, both, bottom)
  54. *
  55. * @var string
  56. */
  57. private $vAlign;
  58. /**
  59. * Text Direction
  60. *
  61. * @var string
  62. */
  63. private $textDirection;
  64. /**
  65. * colspan
  66. *
  67. * @var integer
  68. */
  69. private $gridSpan;
  70. /**
  71. * rowspan (restart, continue)
  72. *
  73. * - restart: Start/restart merged region
  74. * - continue: Continue merged region
  75. *
  76. * @var string
  77. */
  78. private $vMerge;
  79. /**
  80. * Shading
  81. *
  82. * @var \PhpOffice\PhpWord\Style\Shading
  83. */
  84. private $shading;
  85. /**
  86. * Get vertical align.
  87. *
  88. * @return string
  89. */
  90. public function getVAlign()
  91. {
  92. return $this->vAlign;
  93. }
  94. /**
  95. * Set vertical align
  96. *
  97. * @param string $value
  98. * @return self
  99. */
  100. public function setVAlign($value = null)
  101. {
  102. $enum = array(self::VALIGN_TOP, self::VALIGN_CENTER, self::VALIGN_BOTTOM, self::VALIGN_BOTH);
  103. $this->vAlign = $this->setEnumVal($value, $enum, $this->vAlign);
  104. return $this;
  105. }
  106. /**
  107. * Get text direction.
  108. *
  109. * @return string
  110. */
  111. public function getTextDirection()
  112. {
  113. return $this->textDirection;
  114. }
  115. /**
  116. * Set text direction
  117. *
  118. * @param string $value
  119. * @return self
  120. */
  121. public function setTextDirection($value = null)
  122. {
  123. $enum = array(self::TEXT_DIR_BTLR, self::TEXT_DIR_TBRL);
  124. $this->textDirection = $this->setEnumVal($value, $enum, $this->textDirection);
  125. return $this;
  126. }
  127. /**
  128. * Get background
  129. *
  130. * @return string
  131. */
  132. public function getBgColor()
  133. {
  134. if ($this->shading !== null) {
  135. return $this->shading->getFill();
  136. } else {
  137. return null;
  138. }
  139. }
  140. /**
  141. * Set background
  142. *
  143. * @param string $value
  144. * @return self
  145. */
  146. public function setBgColor($value = null)
  147. {
  148. return $this->setShading(array('fill' => $value));
  149. }
  150. /**
  151. * Get grid span (colspan).
  152. *
  153. * @return integer
  154. */
  155. public function getGridSpan()
  156. {
  157. return $this->gridSpan;
  158. }
  159. /**
  160. * Set grid span (colspan)
  161. *
  162. * @param int $value
  163. * @return self
  164. */
  165. public function setGridSpan($value = null)
  166. {
  167. $this->gridSpan = $this->setIntVal($value, $this->gridSpan);
  168. return $this;
  169. }
  170. /**
  171. * Get vertical merge (rowspan).
  172. *
  173. * @return string
  174. */
  175. public function getVMerge()
  176. {
  177. return $this->vMerge;
  178. }
  179. /**
  180. * Set vertical merge (rowspan)
  181. *
  182. * @param string $value
  183. * @return self
  184. */
  185. public function setVMerge($value = null)
  186. {
  187. $enum = array(self::VMERGE_RESTART, self::VMERGE_CONTINUE);
  188. $this->vMerge = $this->setEnumVal($value, $enum, $this->vMerge);
  189. return $this;
  190. }
  191. /**
  192. * Get shading
  193. *
  194. * @return \PhpOffice\PhpWord\Style\Shading
  195. */
  196. public function getShading()
  197. {
  198. return $this->shading;
  199. }
  200. /**
  201. * Set shading
  202. *
  203. * @param mixed $value
  204. * @return self
  205. */
  206. public function setShading($value = null)
  207. {
  208. $this->setObjectVal($value, 'Shading', $this->shading);
  209. return $this;
  210. }
  211. /**
  212. * Get default border color
  213. *
  214. * @deprecated 0.10.0
  215. * @codeCoverageIgnore
  216. */
  217. public function getDefaultBorderColor()
  218. {
  219. return self::DEFAULT_BORDER_COLOR;
  220. }
  221. }