Skip to content

Commit 8cc56ce

Browse files
committedSep 21, 2011
Excel API: allow alignments to be specified
Affects #13290: Allow more control over excel export format
1 parent 79afb16 commit 8cc56ce

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
 

‎core/excel_api.php

+59
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ class ExcelStyle {
523523
private $interior;
524524
private $font;
525525
private $border;
526+
private $alignment;
526527

527528
/**
528529
* @param string $p_id The unique style id
@@ -611,6 +612,33 @@ function setBorder( $p_color, $p_line_style = 'Continuous', $p_weight = 1) {
611612
}
612613
}
613614

615+
/**
616+
* Sets the aligment for the style
617+
*
618+
* @param int $p_wrap_text 1 to wrap, 0 to not wrap
619+
* @param string $p_horizontal Automatic, Left, Center, Right, Fill, Justify, CenterAcrossSelection, Distributed, and JustifyDistributed
620+
* @param string $p_vertical Automatic, Top, Bottom, Center, Justify, Distributed, and JustifyDistributed
621+
*/
622+
function setAlignment( $p_wrap_text, $p_horizontal = '', $p_vertical = '') {
623+
624+
if ( ! isset ( $this->alignment ) ) {
625+
$this->alignment = new Alignment();
626+
}
627+
628+
if ( $p_wrap_text != '' ) {
629+
$this->alignment->wrapText = $p_wrap_text;
630+
}
631+
632+
if ( $p_horizontal != '' ) {
633+
$this->alignment->horizontal = $p_horizontal;
634+
}
635+
636+
if ( $p_vertical != '' ) {
637+
$this->alignment->vertical = $p_vertical;
638+
}
639+
640+
}
641+
614642
function asXml() {
615643

616644
$xml = '<ss:Style ss:ID="' . $this->id.'" ss:Name="'.$this->id.'" ';
@@ -627,6 +655,9 @@ function asXml() {
627655
if ( $this->border ) {
628656
$xml .= $this->border->asXml();
629657
}
658+
if ( $this->alignment ) {
659+
$xml .= $this->alignment->asXml();
660+
}
630661
$xml .= '</ss:Style>'."\n";
631662

632663
return $xml;
@@ -721,3 +752,31 @@ function asXml() {
721752
return $xml;
722753
}
723754
}
755+
756+
class Alignment {
757+
758+
public $wrapText;
759+
public $horizontal;
760+
public $vertical;
761+
762+
function asXml() {
763+
764+
$xml = '<ss:Alignment ';
765+
766+
if ( $this->wrapText ) {
767+
$xml .= 'ss:WrapText="' . $this->wrapText.'" ';
768+
}
769+
770+
if ( $this->horizontal ) {
771+
$xml .= 'ss:Horizontal="' . $this->horizontal.'" ';
772+
}
773+
774+
if ( $this->vertical ) {
775+
$xml .= 'ss:Vertical="' . $this->vertical.'" ';
776+
}
777+
778+
$xml .= '/>';
779+
780+
return $xml;
781+
}
782+
}

0 commit comments

Comments
 (0)
Please sign in to comment.