Skip to content

Commit

Permalink
Excel API: allow alignments to be specified
Browse files Browse the repository at this point in the history
Affects #13290: Allow more control over excel export format
  • Loading branch information
rombert committed Sep 21, 2011
1 parent 79afb16 commit 8cc56ce
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions core/excel_api.php
Expand Up @@ -523,6 +523,7 @@ class ExcelStyle {
private $interior;
private $font;
private $border;
private $alignment;

/**
* @param string $p_id The unique style id
Expand Down Expand Up @@ -611,6 +612,33 @@ function setBorder( $p_color, $p_line_style = 'Continuous', $p_weight = 1) {
}
}

/**
* Sets the aligment for the style
*
* @param int $p_wrap_text 1 to wrap, 0 to not wrap
* @param string $p_horizontal Automatic, Left, Center, Right, Fill, Justify, CenterAcrossSelection, Distributed, and JustifyDistributed
* @param string $p_vertical Automatic, Top, Bottom, Center, Justify, Distributed, and JustifyDistributed
*/
function setAlignment( $p_wrap_text, $p_horizontal = '', $p_vertical = '') {

if ( ! isset ( $this->alignment ) ) {
$this->alignment = new Alignment();
}

if ( $p_wrap_text != '' ) {
$this->alignment->wrapText = $p_wrap_text;
}

if ( $p_horizontal != '' ) {
$this->alignment->horizontal = $p_horizontal;
}

if ( $p_vertical != '' ) {
$this->alignment->vertical = $p_vertical;
}

}

function asXml() {

$xml = '<ss:Style ss:ID="' . $this->id.'" ss:Name="'.$this->id.'" ';
Expand All @@ -627,6 +655,9 @@ function asXml() {
if ( $this->border ) {
$xml .= $this->border->asXml();
}
if ( $this->alignment ) {
$xml .= $this->alignment->asXml();
}
$xml .= '</ss:Style>'."\n";

return $xml;
Expand Down Expand Up @@ -721,3 +752,31 @@ function asXml() {
return $xml;
}
}

class Alignment {

public $wrapText;
public $horizontal;
public $vertical;

function asXml() {

$xml = '<ss:Alignment ';

if ( $this->wrapText ) {
$xml .= 'ss:WrapText="' . $this->wrapText.'" ';
}

if ( $this->horizontal ) {
$xml .= 'ss:Horizontal="' . $this->horizontal.'" ';
}

if ( $this->vertical ) {
$xml .= 'ss:Vertical="' . $this->vertical.'" ';
}

$xml .= '/>';

return $xml;
}
}

0 comments on commit 8cc56ce

Please sign in to comment.