Skip to content

Commit

Permalink
excel format: support for date/time values
Browse files Browse the repository at this point in the history
Change-Id: I14399921ae7d107a3d8f814c050dc2728d066a9a
  • Loading branch information
s7eph4n committed Jun 2, 2014
1 parent 8bae53d commit 14daff1
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions formats/excel/SRF_Excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ protected function setOrAppendStringDataValue( $object ) {

$cell = $this->sheet->getCellByColumnAndRow( $this->colNum, $this->rowNum );
$existingValue = $cell->getValue();
if($existingValue){
$value = $cell->getValue().','.$value;
if ( $existingValue ) {
$value = $existingValue . ', ' . $value;
}
$cell->setValueExplicit($value,$type);
$cell->setValueExplicit( $value, $type );
}

/**
Expand Down Expand Up @@ -182,6 +182,25 @@ protected function setQuantityDataValue( $object ) {
->setFormatCode( '0 "' . $unit . '"' );
}

/**
* Sets a date/time value at the given col,row location
*
* @param $object the raw data value object
*/
protected function setTimeDataValue ( \SMWTimeValue $object ) {
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$value = \PHPExcel_Shared_Date::stringToExcel( str_replace( 'T', ' ', $object->getISO8601Date() ) );

$this->sheet
->getCellByColumnAndRow( $this->colNum, $this->rowNum )
->setValueExplicit( $value, $type );

$this->sheet
->getStyleByColumnAndRow( $this->colNum, $this->rowNum )
->getNumberFormat()
->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY);
}

/**
* Populates the PHPExcel sheet with the headers from the result query
*
Expand Down Expand Up @@ -246,6 +265,8 @@ protected function setValueAccordingToType( $object ) {
$this->setQuantityDataValue($object);
} else if( $object instanceof \SMWNumberValue ) {
$this->setNumberDataValue($object);
} else if ( $object instanceof \SMWTimeValue ) {
$this->setTimeDataValue( $object );
} else {
$this->setOrAppendStringDataValue($object);
}
Expand Down

2 comments on commit 14daff1

@JeroenDeDauw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s7eph4n can you update the RELEASE-NOTES.md?

@s7eph4n
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I forget that AGAIN? :)
Will do.

Please sign in to comment.