Skip to content

Commit

Permalink
Config settings for strict null comparision for array export, fixes i…
Browse files Browse the repository at this point in the history
…ssue #135
  • Loading branch information
patrickbrouwers committed May 29, 2014
1 parent fa9cd5e commit 0bd516b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Maatwebsite/Excel/Classes/LaravelExcelWorksheet.php
Expand Up @@ -365,6 +365,26 @@ public function fromModel($source = NULL, $headingGeneration = true)
return parent::fromArray($this->data);
}

/**
* Fill worksheet from values in array
*
* @param array $source Source array
* @param mixed $nullValue Value in source array that stands for blank cell
* @param string $startCell Insert array starting from this cell address as the top left coordinate
* @param boolean $strictNullComparison Apply strict comparison when testing for null values in the array
* @throws PHPExcel_Exception
* @return PHPExcel_Worksheet
*/
public function fromArray($source = null, $nullValue = null, $startCell = false, $strictNullComparison = false)
{
// Set defaults
$nullValue = !is_null($nullValue) ? $nullValue : $this->getDefaultNullValue();
$startCell = $startCell ? $startCell : $this->getDefaultStartCell();
$strictNullComparison = $strictNullComparison ? $strictNullComparison : $this->getDefaultStrictNullComparison();

return parent::fromArray($source, $nullValue, $startCell, $strictNullComparison);
}

/**
* Add vars to the data array
* @param [type] $key [description]
Expand Down Expand Up @@ -909,6 +929,34 @@ protected function getStartRow()
return $this->getHighestRow() + 1;
}

/**
* Return default null value
* @return string/integer/null
*/
protected function getDefaultNullValue()
{
return Config::get('excel::export.sheets.nullValue', null);
}

/**
* Return default null value
* @return string/integer/null
*/
protected function getDefaultStartCell()
{
return Config::get('excel::export.sheets.startCell', 'A1');
}


/**
* Return default strict null comparison
* @return boolean
*/
protected function getDefaultStrictNullComparison()
{
return Config::get('excel::export.sheets.strictNullComparison', false);
}

/**
* Dynamically call methods
* @param [type] $method [description]
Expand Down
30 changes: 30 additions & 0 deletions src/config/export.php
Expand Up @@ -24,6 +24,36 @@
*/
'generate_heading_by_indices' => true,


/*
|--------------------------------------------------------------------------
| Default sheet settings
|--------------------------------------------------------------------------
*/
'sheets' => array(

/*
|--------------------------------------------------------------------------
| Value in source array that stands for blank cell
|--------------------------------------------------------------------------
*/
'nullValue' => null,

/*
|--------------------------------------------------------------------------
| Insert array starting from this cell address as the top left coordinate
|--------------------------------------------------------------------------
*/
'startCell' => 'A2',

/*
|--------------------------------------------------------------------------
| Apply strict comparison when testing for null values in the array
|--------------------------------------------------------------------------
*/
'strictNullComparison' => false
),

/*
|--------------------------------------------------------------------------
| Store settings
Expand Down

0 comments on commit 0bd516b

Please sign in to comment.