From d777d0283d35af6eda09ae131ed08042e97d5688 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sun, 17 Aug 2014 18:15:44 +0100 Subject: [PATCH] Support for cell readorder Context/LTR/RTL --- Classes/PHPExcel/Reader/Excel2007.php | 1 + Classes/PHPExcel/Style/Alignment.php | 91 ++++++++++++++++----- Classes/PHPExcel/Writer/Excel2007/Style.php | 3 + 3 files changed, 73 insertions(+), 22 deletions(-) diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index d5c947ee..afe3b5c8 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -1893,6 +1893,7 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE $docStyle->getAlignment()->setWrapText(self::boolean((string) $style->alignment["wrapText"])); $docStyle->getAlignment()->setShrinkToFit(self::boolean((string) $style->alignment["shrinkToFit"])); $docStyle->getAlignment()->setIndent( intval((string)$style->alignment["indent"]) > 0 ? intval((string)$style->alignment["indent"]) : 0 ); + $docStyle->getAlignment()->setReadorder( intval((string)$style->alignment["readingOrder"]) > 0 ? intval((string)$style->alignment["readingOrder"]) : 0 ); } // protection diff --git a/Classes/PHPExcel/Style/Alignment.php b/Classes/PHPExcel/Style/Alignment.php index 7577da53..00825deb 100644 --- a/Classes/PHPExcel/Style/Alignment.php +++ b/Classes/PHPExcel/Style/Alignment.php @@ -36,49 +36,54 @@ class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable { /* Horizontal alignment styles */ - const HORIZONTAL_GENERAL = 'general'; - const HORIZONTAL_LEFT = 'left'; - const HORIZONTAL_RIGHT = 'right'; - const HORIZONTAL_CENTER = 'center'; - const HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous'; - const HORIZONTAL_JUSTIFY = 'justify'; - const HORIZONTAL_FILL = 'fill'; - const HORIZONTAL_DISTRIBUTED = 'distributed'; // Excel2007 only + const HORIZONTAL_GENERAL = 'general'; + const HORIZONTAL_LEFT = 'left'; + const HORIZONTAL_RIGHT = 'right'; + const HORIZONTAL_CENTER = 'center'; + const HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous'; + const HORIZONTAL_JUSTIFY = 'justify'; + const HORIZONTAL_FILL = 'fill'; + const HORIZONTAL_DISTRIBUTED = 'distributed'; // Excel2007 only /* Vertical alignment styles */ - const VERTICAL_BOTTOM = 'bottom'; - const VERTICAL_TOP = 'top'; - const VERTICAL_CENTER = 'center'; - const VERTICAL_JUSTIFY = 'justify'; - const VERTICAL_DISTRIBUTED = 'distributed'; // Excel2007 only + const VERTICAL_BOTTOM = 'bottom'; + const VERTICAL_TOP = 'top'; + const VERTICAL_CENTER = 'center'; + const VERTICAL_JUSTIFY = 'justify'; + const VERTICAL_DISTRIBUTED = 'distributed'; // Excel2007 only + + /* Read order */ + const READORDER_CONTEXT = 0; + const READORDER_LTR = 1; + const READORDER_RTL = 2; /** - * Horizontal + * Horizontal alignment * * @var string */ - protected $_horizontal = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL; + protected $_horizontal = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL; /** - * Vertical + * Vertical alignment * * @var string */ - protected $_vertical = PHPExcel_Style_Alignment::VERTICAL_BOTTOM; + protected $_vertical = PHPExcel_Style_Alignment::VERTICAL_BOTTOM; /** * Text rotation * - * @var int + * @var integer */ - protected $_textRotation = 0; + protected $_textRotation = 0; /** * Wrap text * * @var boolean */ - protected $_wrapText = FALSE; + protected $_wrapText = FALSE; /** * Shrink to fit @@ -90,9 +95,16 @@ class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPE /** * Indent - only possible with horizontal alignment left and right * - * @var int + * @var integer */ - protected $_indent = 0; + protected $_indent = 0; + + /** + * Read order + * + * @var integer + */ + protected $_readorder = 0; /** * Create a new PHPExcel_Style_Alignment @@ -180,6 +192,9 @@ class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPE if (isset($pStyles['indent'])) { $this->setIndent($pStyles['indent']); } + if (isset($pStyles['readorder'])) { + $this->setReadorder($pStyles['readorder']); + } } } else { throw new PHPExcel_Exception("Invalid style array passed."); @@ -389,6 +404,37 @@ class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPE return $this; } + /** + * Get read order + * + * @return integer + */ + public function getReadorder() { + if ($this->_isSupervisor) { + return $this->getSharedComponent()->getReadorder(); + } + return $this->_readorder; + } + + /** + * Set read order + * + * @param int $pValue + * @return PHPExcel_Style_Alignment + */ + public function setReadorder($pValue = 0) { + if ($pValue < 0 || $pValue > 2) { + $pValue = 0; + } + if ($this->_isSupervisor) { + $styleArray = $this->getStyleArray(array('readorder' => $pValue)); + $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); + } else { + $this->_readorder = $pValue; + } + return $this; + } + /** * Get hash code * @@ -405,6 +451,7 @@ class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPE . ($this->_wrapText ? 't' : 'f') . ($this->_shrinkToFit ? 't' : 'f') . $this->_indent + . $this->_readorder . __CLASS__ ); } diff --git a/Classes/PHPExcel/Writer/Excel2007/Style.php b/Classes/PHPExcel/Writer/Excel2007/Style.php index 9857043b..d38c6eac 100644 --- a/Classes/PHPExcel/Writer/Excel2007/Style.php +++ b/Classes/PHPExcel/Writer/Excel2007/Style.php @@ -439,6 +439,9 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa if ($pStyle->getAlignment()->getIndent() > 0) { $objWriter->writeAttribute('indent', $pStyle->getAlignment()->getIndent()); } + if ($pStyle->getAlignment()->getReadorder() > 0) { + $objWriter->writeAttribute('readingOrder', $pStyle->getAlignment()->getReadorder()); + } $objWriter->endElement(); // protection