説明なし

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\Writer\Word2007\Style;
  18. use PhpOffice\PhpWord\Style\Cell as CellStyle;
  19. /**
  20. * Cell style writer
  21. *
  22. * @since 0.10.0
  23. */
  24. class Cell extends AbstractStyle
  25. {
  26. /**
  27. * @var int Cell width
  28. */
  29. private $width;
  30. /**
  31. * Write style.
  32. *
  33. * @return void
  34. */
  35. public function write()
  36. {
  37. $style = $this->getStyle();
  38. if (!$style instanceof CellStyle) {
  39. return;
  40. }
  41. $xmlWriter = $this->getXmlWriter();
  42. $xmlWriter->startElement('w:tcPr');
  43. // Width
  44. $xmlWriter->startElement('w:tcW');
  45. $xmlWriter->writeAttribute('w:w', $this->width);
  46. $xmlWriter->writeAttribute('w:type', 'dxa');
  47. $xmlWriter->endElement(); // w:tcW
  48. // Text direction
  49. $textDir = $style->getTextDirection();
  50. $xmlWriter->writeElementIf(!is_null($textDir), 'w:textDirection', 'w:val', $textDir);
  51. // Vertical alignment
  52. $vAlign = $style->getVAlign();
  53. $xmlWriter->writeElementIf(!is_null($vAlign), 'w:vAlign', 'w:val', $vAlign);
  54. // Border
  55. if ($style->hasBorder()) {
  56. $xmlWriter->startElement('w:tcBorders');
  57. $styleWriter = new MarginBorder($xmlWriter);
  58. $styleWriter->setSizes($style->getBorderSize());
  59. $styleWriter->setColors($style->getBorderColor());
  60. $styleWriter->setAttributes(array('defaultColor' => CellStyle::DEFAULT_BORDER_COLOR));
  61. $styleWriter->write();
  62. $xmlWriter->endElement();
  63. }
  64. // Shading
  65. $shading = $style->getShading();
  66. if (!is_null($shading)) {
  67. $styleWriter = new Shading($xmlWriter, $shading);
  68. $styleWriter->write();
  69. }
  70. // Colspan & rowspan
  71. $gridSpan = $style->getGridSpan();
  72. $vMerge = $style->getVMerge();
  73. $xmlWriter->writeElementIf(!is_null($gridSpan), 'w:gridSpan', 'w:val', $gridSpan);
  74. $xmlWriter->writeElementIf(!is_null($vMerge), 'w:vMerge', 'w:val', $vMerge);
  75. $xmlWriter->endElement(); // w:tcPr
  76. }
  77. /**
  78. * Set width.
  79. *
  80. * @param int $value
  81. * @return void
  82. */
  83. public function setWidth($value = null)
  84. {
  85. $this->width = $value;
  86. }
  87. }