Skip to content

Commit 4911d4d

Browse files
committedSep 21, 2011
Excel API: allow alignments to be specified
Affects #13290: Allow more control over excel export format
1 parent 4080786 commit 4911d4d

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
@@ -498,6 +498,7 @@ class ExcelStyle {
498498
private $interior;
499499
private $font;
500500
private $border;
501+
private $alignment;
501502

502503
/**
503504
* @param string $p_id The unique style id
@@ -586,6 +587,33 @@ function setBorder( $p_color, $p_line_style = 'Continuous', $p_weight = 1) {
586587
}
587588
}
588589

590+
/**
591+
* Sets the aligment for the style
592+
*
593+
* @param int $p_wrap_text 1 to wrap, 0 to not wrap
594+
* @param string $p_horizontal Automatic, Left, Center, Right, Fill, Justify, CenterAcrossSelection, Distributed, and JustifyDistributed
595+
* @param string $p_vertical Automatic, Top, Bottom, Center, Justify, Distributed, and JustifyDistributed
596+
*/
597+
function setAlignment( $p_wrap_text, $p_horizontal = '', $p_vertical = '') {
598+
599+
if ( ! isset ( $this->alignment ) ) {
600+
$this->alignment = new Alignment();
601+
}
602+
603+
if ( $p_wrap_text != '' ) {
604+
$this->alignment->wrapText = $p_wrap_text;
605+
}
606+
607+
if ( $p_horizontal != '' ) {
608+
$this->alignment->horizontal = $p_horizontal;
609+
}
610+
611+
if ( $p_vertical != '' ) {
612+
$this->alignment->vertical = $p_vertical;
613+
}
614+
615+
}
616+
589617
function asXml() {
590618

591619
$xml = '<ss:Style ss:ID="' . $this->id.'" ss:Name="'.$this->id.'" ';
@@ -602,6 +630,9 @@ function asXml() {
602630
if ( $this->border ) {
603631
$xml .= $this->border->asXml();
604632
}
633+
if ( $this->alignment ) {
634+
$xml .= $this->alignment->asXml();
635+
}
605636
$xml .= '</ss:Style>'."\n";
606637

607638
return $xml;
@@ -696,3 +727,31 @@ function asXml() {
696727
return $xml;
697728
}
698729
}
730+
731+
class Alignment {
732+
733+
public $wrapText;
734+
public $horizontal;
735+
public $vertical;
736+
737+
function asXml() {
738+
739+
$xml = '<ss:Alignment ';
740+
741+
if ( $this->wrapText ) {
742+
$xml .= 'ss:WrapText="' . $this->wrapText.'" ';
743+
}
744+
745+
if ( $this->horizontal ) {
746+
$xml .= 'ss:Horizontal="' . $this->horizontal.'" ';
747+
}
748+
749+
if ( $this->vertical ) {
750+
$xml .= 'ss:Vertical="' . $this->vertical.'" ';
751+
}
752+
753+
$xml .= '/>';
754+
755+
return $xml;
756+
}
757+
}

0 commit comments

Comments
 (0)
Please sign in to comment.