Cell.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. * @see https://github.com/PHPOffice/PHPWord
  14. * @copyright 2010-2018 PHPWord contributors
  15. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  16. */
  17. namespace PhpOffice\PhpWord\Style;
  18. use PhpOffice\PhpWord\SimpleType\TblWidth;
  19. use PhpOffice\PhpWord\SimpleType\VerticalJc;
  20. /**
  21. * Table cell style
  22. */
  23. class Cell extends Border
  24. {
  25. /**
  26. * Vertical alignment constants
  27. *
  28. * @const string
  29. * @deprecated Use \PhpOffice\PhpWord\SimpleType\VerticalJc::TOP instead
  30. */
  31. const VALIGN_TOP = 'top';
  32. /**
  33. * @deprecated Use \PhpOffice\PhpWord\SimpleType\VerticalJc::CENTER instead
  34. */
  35. const VALIGN_CENTER = 'center';
  36. /**
  37. * @deprecated Use \PhpOffice\PhpWord\SimpleType\VerticalJc::BOTTOM instead
  38. */
  39. const VALIGN_BOTTOM = 'bottom';
  40. /**
  41. * @deprecated Use \PhpOffice\PhpWord\SimpleType\VerticalJc::BOTH instead
  42. */
  43. const VALIGN_BOTH = 'both';
  44. //Text direction constants
  45. /**
  46. * Left to Right, Top to Bottom
  47. */
  48. const TEXT_DIR_LRTB = 'lrTb';
  49. /**
  50. * Top to Bottom, Right to Left
  51. */
  52. const TEXT_DIR_TBRL = 'tbRl';
  53. /**
  54. * Bottom to Top, Left to Right
  55. */
  56. const TEXT_DIR_BTLR = 'btLr';
  57. /**
  58. * Left to Right, Top to Bottom Rotated
  59. */
  60. const TEXT_DIR_LRTBV = 'lrTbV';
  61. /**
  62. * Top to Bottom, Right to Left Rotated
  63. */
  64. const TEXT_DIR_TBRLV = 'tbRlV';
  65. /**
  66. * Top to Bottom, Left to Right Rotated
  67. */
  68. const TEXT_DIR_TBLRV = 'tbLrV';
  69. /**
  70. * Vertical merge (rowspan) constants
  71. *
  72. * @const string
  73. */
  74. const VMERGE_RESTART = 'restart';
  75. const VMERGE_CONTINUE = 'continue';
  76. /**
  77. * Default border color
  78. *
  79. * @const string
  80. */
  81. const DEFAULT_BORDER_COLOR = '000000';
  82. /**
  83. * Vertical align (top, center, both, bottom)
  84. *
  85. * @var string
  86. */
  87. private $vAlign;
  88. /**
  89. * Text Direction
  90. *
  91. * @var string
  92. */
  93. private $textDirection;
  94. /**
  95. * colspan
  96. *
  97. * @var int
  98. */
  99. private $gridSpan;
  100. /**
  101. * rowspan (restart, continue)
  102. *
  103. * - restart: Start/restart merged region
  104. * - continue: Continue merged region
  105. *
  106. * @var string
  107. */
  108. private $vMerge;
  109. /**
  110. * Shading
  111. *
  112. * @var \PhpOffice\PhpWord\Style\Shading
  113. */
  114. private $shading;
  115. /**
  116. * Width
  117. *
  118. * @var int
  119. */
  120. private $width;
  121. /**
  122. * Width unit
  123. *
  124. * @var string
  125. */
  126. private $unit = TblWidth::TWIP;
  127. /**
  128. * Get vertical align.
  129. *
  130. * @return string
  131. */
  132. public function getVAlign()
  133. {
  134. return $this->vAlign;
  135. }
  136. /**
  137. * Set vertical align
  138. *
  139. * @param string $value
  140. * @return self
  141. */
  142. public function setVAlign($value = null)
  143. {
  144. VerticalJc::validate($value);
  145. $this->vAlign = $this->setEnumVal($value, VerticalJc::values(), $this->vAlign);
  146. return $this;
  147. }
  148. /**
  149. * Get text direction.
  150. *
  151. * @return string
  152. */
  153. public function getTextDirection()
  154. {
  155. return $this->textDirection;
  156. }
  157. /**
  158. * Set text direction
  159. *
  160. * @param string $value
  161. * @return self
  162. */
  163. public function setTextDirection($value = null)
  164. {
  165. $enum = array(self::TEXT_DIR_BTLR, self::TEXT_DIR_TBRL);
  166. $this->textDirection = $this->setEnumVal($value, $enum, $this->textDirection);
  167. return $this;
  168. }
  169. /**
  170. * Get background
  171. *
  172. * @return string
  173. */
  174. public function getBgColor()
  175. {
  176. if ($this->shading !== null) {
  177. return $this->shading->getFill();
  178. }
  179. return null;
  180. }
  181. /**
  182. * Set background
  183. *
  184. * @param string $value
  185. * @return self
  186. */
  187. public function setBgColor($value = null)
  188. {
  189. return $this->setShading(array('fill' => $value));
  190. }
  191. /**
  192. * Get grid span (colspan).
  193. *
  194. * @return int
  195. */
  196. public function getGridSpan()
  197. {
  198. return $this->gridSpan;
  199. }
  200. /**
  201. * Set grid span (colspan)
  202. *
  203. * @param int $value
  204. * @return self
  205. */
  206. public function setGridSpan($value = null)
  207. {
  208. $this->gridSpan = $this->setIntVal($value, $this->gridSpan);
  209. return $this;
  210. }
  211. /**
  212. * Get vertical merge (rowspan).
  213. *
  214. * @return string
  215. */
  216. public function getVMerge()
  217. {
  218. return $this->vMerge;
  219. }
  220. /**
  221. * Set vertical merge (rowspan)
  222. *
  223. * @param string $value
  224. * @return self
  225. */
  226. public function setVMerge($value = null)
  227. {
  228. $enum = array(self::VMERGE_RESTART, self::VMERGE_CONTINUE);
  229. $this->vMerge = $this->setEnumVal($value, $enum, $this->vMerge);
  230. return $this;
  231. }
  232. /**
  233. * Get shading
  234. *
  235. * @return \PhpOffice\PhpWord\Style\Shading
  236. */
  237. public function getShading()
  238. {
  239. return $this->shading;
  240. }
  241. /**
  242. * Set shading
  243. *
  244. * @param mixed $value
  245. * @return self
  246. */
  247. public function setShading($value = null)
  248. {
  249. $this->setObjectVal($value, 'Shading', $this->shading);
  250. return $this;
  251. }
  252. /**
  253. * Get cell width
  254. *
  255. * @return int
  256. */
  257. public function getWidth()
  258. {
  259. return $this->width;
  260. }
  261. /**
  262. * Set cell width
  263. *
  264. * @param int $value
  265. * @return self
  266. */
  267. public function setWidth($value)
  268. {
  269. $this->setIntVal($value);
  270. return $this;
  271. }
  272. /**
  273. * Get width unit
  274. *
  275. * @return string
  276. */
  277. public function getUnit()
  278. {
  279. return $this->unit;
  280. }
  281. /**
  282. * Set width unit
  283. *
  284. * @param string $value
  285. */
  286. public function setUnit($value)
  287. {
  288. $this->unit = $this->setEnumVal($value, array(TblWidth::AUTO, TblWidth::PERCENT, TblWidth::TWIP), TblWidth::TWIP);
  289. return $this;
  290. }
  291. /**
  292. * Get default border color
  293. *
  294. * @deprecated 0.10.0
  295. *
  296. * @codeCoverageIgnore
  297. */
  298. public function getDefaultBorderColor()
  299. {
  300. return self::DEFAULT_BORDER_COLOR;
  301. }
  302. }