Support for cell readorder Context/LTR/RTL

This commit is contained in:
MarkBaker 2014-08-17 18:15:44 +01:00
parent 125f39c745
commit d777d0283d
3 changed files with 73 additions and 22 deletions

View File

@ -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()->setWrapText(self::boolean((string) $style->alignment["wrapText"]));
$docStyle->getAlignment()->setShrinkToFit(self::boolean((string) $style->alignment["shrinkToFit"])); $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()->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 // protection

View File

@ -36,49 +36,54 @@
class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable
{ {
/* Horizontal alignment styles */ /* Horizontal alignment styles */
const HORIZONTAL_GENERAL = 'general'; const HORIZONTAL_GENERAL = 'general';
const HORIZONTAL_LEFT = 'left'; const HORIZONTAL_LEFT = 'left';
const HORIZONTAL_RIGHT = 'right'; const HORIZONTAL_RIGHT = 'right';
const HORIZONTAL_CENTER = 'center'; const HORIZONTAL_CENTER = 'center';
const HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous'; const HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous';
const HORIZONTAL_JUSTIFY = 'justify'; const HORIZONTAL_JUSTIFY = 'justify';
const HORIZONTAL_FILL = 'fill'; const HORIZONTAL_FILL = 'fill';
const HORIZONTAL_DISTRIBUTED = 'distributed'; // Excel2007 only const HORIZONTAL_DISTRIBUTED = 'distributed'; // Excel2007 only
/* Vertical alignment styles */ /* Vertical alignment styles */
const VERTICAL_BOTTOM = 'bottom'; const VERTICAL_BOTTOM = 'bottom';
const VERTICAL_TOP = 'top'; const VERTICAL_TOP = 'top';
const VERTICAL_CENTER = 'center'; const VERTICAL_CENTER = 'center';
const VERTICAL_JUSTIFY = 'justify'; const VERTICAL_JUSTIFY = 'justify';
const VERTICAL_DISTRIBUTED = 'distributed'; // Excel2007 only 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 * @var string
*/ */
protected $_horizontal = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL; protected $_horizontal = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
/** /**
* Vertical * Vertical alignment
* *
* @var string * @var string
*/ */
protected $_vertical = PHPExcel_Style_Alignment::VERTICAL_BOTTOM; protected $_vertical = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
/** /**
* Text rotation * Text rotation
* *
* @var int * @var integer
*/ */
protected $_textRotation = 0; protected $_textRotation = 0;
/** /**
* Wrap text * Wrap text
* *
* @var boolean * @var boolean
*/ */
protected $_wrapText = FALSE; protected $_wrapText = FALSE;
/** /**
* Shrink to fit * 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 * 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 * Create a new PHPExcel_Style_Alignment
@ -180,6 +192,9 @@ class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPE
if (isset($pStyles['indent'])) { if (isset($pStyles['indent'])) {
$this->setIndent($pStyles['indent']); $this->setIndent($pStyles['indent']);
} }
if (isset($pStyles['readorder'])) {
$this->setReadorder($pStyles['readorder']);
}
} }
} else { } else {
throw new PHPExcel_Exception("Invalid style array passed."); throw new PHPExcel_Exception("Invalid style array passed.");
@ -389,6 +404,37 @@ class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPE
return $this; 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 * Get hash code
* *
@ -405,6 +451,7 @@ class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPE
. ($this->_wrapText ? 't' : 'f') . ($this->_wrapText ? 't' : 'f')
. ($this->_shrinkToFit ? 't' : 'f') . ($this->_shrinkToFit ? 't' : 'f')
. $this->_indent . $this->_indent
. $this->_readorder
. __CLASS__ . __CLASS__
); );
} }

View File

@ -439,6 +439,9 @@ class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPa
if ($pStyle->getAlignment()->getIndent() > 0) { if ($pStyle->getAlignment()->getIndent() > 0) {
$objWriter->writeAttribute('indent', $pStyle->getAlignment()->getIndent()); $objWriter->writeAttribute('indent', $pStyle->getAlignment()->getIndent());
} }
if ($pStyle->getAlignment()->getReadorder() > 0) {
$objWriter->writeAttribute('readingOrder', $pStyle->getAlignment()->getReadorder());
}
$objWriter->endElement(); $objWriter->endElement();
// protection // protection