Laravel version update
Laravel version update
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<?php namespace Maatwebsite\Excel\Classes;
|
||||
|
||||
use PHPExcel_Settings;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use PHPExcel_CachedObjectStorageFactory;
|
||||
|
||||
class Cache {
|
||||
@@ -16,7 +15,7 @@ class Cache {
|
||||
* Available caching drivers
|
||||
* @var array
|
||||
*/
|
||||
protected $available = array(
|
||||
protected $available = [
|
||||
'memory' => 'cache_in_memory',
|
||||
'gzip' => 'cache_in_memory_gzip',
|
||||
'serialized' => 'cache_in_memory_serialized',
|
||||
@@ -28,7 +27,7 @@ class Cache {
|
||||
'wincache' => 'cache_to_wincache',
|
||||
'sqlite' => 'cache_to_sqlite',
|
||||
'sqlite3' => 'cache_to_sqlite3'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* The name of the config file
|
||||
@@ -42,8 +41,8 @@ class Cache {
|
||||
public function __construct()
|
||||
{
|
||||
// Get driver and settings from the config
|
||||
$this->driver = Config::get($this->configName . '.driver', 'memory');
|
||||
$this->settings = Config::get($this->configName . '.settings', array());
|
||||
$this->driver = config($this->configName . '.driver', 'memory');
|
||||
$this->settings = config($this->configName . '.settings', []);
|
||||
|
||||
// Init if caching is enabled
|
||||
if ($this->isEnabled())
|
||||
@@ -97,19 +96,19 @@ class Cache {
|
||||
case 'memcache':
|
||||
|
||||
// Add extra memcache settings
|
||||
$this->settings = array_merge($this->settings, array(
|
||||
'memcacheServer' => Config::get($this->configName . '.memcache.host', 'localhost'),
|
||||
'memcachePort' => Config::get($this->configName . '.memcache.port', 11211)
|
||||
));
|
||||
$this->settings = array_merge($this->settings, [
|
||||
'memcacheServer' => config($this->configName . '.memcache.host', 'localhost'),
|
||||
'memcachePort' => config($this->configName . '.memcache.port', 11211)
|
||||
]);
|
||||
|
||||
break;
|
||||
|
||||
case 'discISAM':
|
||||
|
||||
// Add dir
|
||||
$this->settings = array_merge($this->settings, array(
|
||||
'dir' => Config::get($this->configName . '.dir', storage_path('cache')),
|
||||
));
|
||||
$this->settings = array_merge($this->settings, [
|
||||
'dir' => config($this->configName . '.dir', storage_path('cache')),
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -121,6 +120,6 @@ class Cache {
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
return Config::get($this->configName . '.enable', true) ? true : false;
|
||||
return config($this->configName . '.enable', true) ? true : false;
|
||||
}
|
||||
}
|
@@ -12,7 +12,7 @@ class FormatIdentifier {
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
protected $formats = array(
|
||||
protected $formats = [
|
||||
'Excel2007',
|
||||
'Excel5',
|
||||
'Excel2003XML',
|
||||
@@ -22,7 +22,7 @@ class FormatIdentifier {
|
||||
'CSV',
|
||||
'HTML',
|
||||
'PDF'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Construct new format identifier
|
||||
|
@@ -5,7 +5,6 @@ use PHPExcel_Cell;
|
||||
use PHPExcel_Exception;
|
||||
use PHPExcel_Worksheet;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Maatwebsite\Excel\Writers\CellWriter;
|
||||
use Maatwebsite\Excel\Exceptions\LaravelExcelException;
|
||||
use PHPExcel_Worksheet_PageSetup;
|
||||
@@ -46,19 +45,19 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
* Data
|
||||
* @var array
|
||||
*/
|
||||
public $data = array();
|
||||
public $data = [];
|
||||
|
||||
/**
|
||||
* Merge data
|
||||
* @var array
|
||||
*/
|
||||
public $mergeData = array();
|
||||
public $mergeData = [];
|
||||
|
||||
/**
|
||||
* Allowed page setup
|
||||
* @var array
|
||||
*/
|
||||
public $allowedPageSetup = array(
|
||||
public $allowedPageSetup = [
|
||||
'orientation',
|
||||
'paperSize',
|
||||
'scale',
|
||||
@@ -71,17 +70,17 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
'verticalCentered',
|
||||
'printArea',
|
||||
'firstPageNumber'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Allowed page setup
|
||||
* @var array
|
||||
*/
|
||||
public $allowedStyles = array(
|
||||
public $allowedStyles = [
|
||||
'fontFamily',
|
||||
'fontSize',
|
||||
'fontBold'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Check if the file was autosized
|
||||
@@ -112,7 +111,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
$this->setParent($pParent);
|
||||
// check if we should generate headings
|
||||
// defaults to true if not overridden by settings
|
||||
$this->autoGenerateHeading = Config::get('excel.export.generate_heading_by_indices', true);
|
||||
$this->autoGenerateHeading = config('excel.export.generate_heading_by_indices', true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,15 +129,15 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
list($setter, $set) = $this->_setSetter($setup);
|
||||
|
||||
// get the value
|
||||
$value = Config::get('excel.sheets.pageSetup.' . $setup, null);
|
||||
$value = config('excel.sheets.pageSetup.' . $setup, null);
|
||||
|
||||
// Set the page setup value
|
||||
if (!is_null($value))
|
||||
call_user_func_array(array($pageSetup, $setter), array($value));
|
||||
call_user_func_array([$pageSetup, $setter], [$value]);
|
||||
}
|
||||
|
||||
// Set default page margins
|
||||
$this->setPageMargin(Config::get('excel.export.sheets.page_margin', false));
|
||||
$this->setPageMargin(config('excel.export.sheets.page_margin', false));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +148,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
{
|
||||
if (!is_array($margin))
|
||||
{
|
||||
$marginArray = array($margin, $margin, $margin, $margin);
|
||||
$marginArray = [$margin, $margin, $margin, $margin];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -225,7 +224,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
* @param boolean $explicit
|
||||
* @return LaravelExcelWorksheet
|
||||
*/
|
||||
public function rows($rows = array(), $explicit = false)
|
||||
public function rows($rows = [], $explicit = false)
|
||||
{
|
||||
// Get the start row
|
||||
$startRow = $this->getStartRow();
|
||||
@@ -354,7 +353,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
*/
|
||||
public function setView()
|
||||
{
|
||||
return call_user_func_array(array($this, 'loadView'), func_get_args());
|
||||
return call_user_func_array([$this, 'loadView'], func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,7 +363,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
* @param array $mergeData
|
||||
* @return LaravelExcelWorksheet
|
||||
*/
|
||||
public function loadView($view, $data = array(), $mergeData = array())
|
||||
public function loadView($view, $data = [], $mergeData = [])
|
||||
{
|
||||
// Init the parser
|
||||
if (!$this->parser)
|
||||
@@ -491,47 +490,47 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
*/
|
||||
public function createSheetFromArray($source = null, $nullValue = null, $startCell = 'A1', $strictNullComparison = false)
|
||||
{
|
||||
if (is_array($source))
|
||||
{
|
||||
// Convert a 1-D array to 2-D (for ease of looping)
|
||||
if (!is_array(end($source)))
|
||||
{
|
||||
$source = array($source);
|
||||
}
|
||||
|
||||
// start coordinate
|
||||
list ($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($startCell);
|
||||
|
||||
// Loop through $source
|
||||
foreach ($source as $rowData)
|
||||
{
|
||||
$currentColumn = $startColumn;
|
||||
foreach ($rowData as $cellValue)
|
||||
{
|
||||
if ($strictNullComparison)
|
||||
{
|
||||
if ($cellValue !== $nullValue)
|
||||
{
|
||||
// Set cell value
|
||||
$this->setValueOfCell($cellValue, $currentColumn, $startRow);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($cellValue != $nullValue)
|
||||
{
|
||||
// Set cell value
|
||||
$this->setValueOfCell($cellValue, $currentColumn, $startRow);
|
||||
}
|
||||
}
|
||||
++$currentColumn;
|
||||
}
|
||||
++$startRow;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!is_array($source))
|
||||
throw new PHPExcel_Exception("Parameter \$source should be an array.");
|
||||
|
||||
// Convert a 1-D array to 2-D (for ease of looping)
|
||||
if (!is_array(end($source)))
|
||||
{
|
||||
$source = [$source];
|
||||
}
|
||||
|
||||
// start coordinate
|
||||
list ($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($startCell);
|
||||
|
||||
$currentRow = $startRow;
|
||||
// Loop through $source
|
||||
foreach ($source as $rowData)
|
||||
{
|
||||
if (!is_array($rowData))
|
||||
throw new PHPExcel_Exception("Row `$rowData` must be array.");
|
||||
|
||||
$currentColumn = $startColumn;
|
||||
foreach ($rowData as $cellValue)
|
||||
{
|
||||
if ($strictNullComparison)
|
||||
{
|
||||
if ($cellValue !== $nullValue)
|
||||
{
|
||||
// Set cell value
|
||||
$this->setValueOfCell($cellValue, $currentColumn, $currentRow);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($cellValue != $nullValue)
|
||||
{
|
||||
// Set cell value
|
||||
$this->setValueOfCell($cellValue, $currentColumn, $currentRow);
|
||||
}
|
||||
}
|
||||
$currentColumn++;
|
||||
}
|
||||
$currentRow++;
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -580,13 +579,12 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
*/
|
||||
protected function addData($array)
|
||||
{
|
||||
// If a parser was set
|
||||
if ($this->parser)
|
||||
{
|
||||
// Don't change anything
|
||||
$data = $array;
|
||||
}
|
||||
else
|
||||
// Return empty array
|
||||
if (empty($array))
|
||||
return $this->data;
|
||||
|
||||
// If a parser wasn't set
|
||||
if (!$this->parser)
|
||||
{
|
||||
// Transform model/collection to array
|
||||
if ($array instanceof Collection)
|
||||
@@ -596,22 +594,16 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
$firstRow = reset($array);
|
||||
|
||||
// Check if the array has array values
|
||||
if (count($firstRow) != count($firstRow, 1))
|
||||
if (is_array($firstRow) && count($firstRow) != count($firstRow, 1))
|
||||
{
|
||||
// Loop through the data to remove arrays
|
||||
$data = array();
|
||||
$r = 0;
|
||||
foreach ($array as $row)
|
||||
$data = [];
|
||||
foreach ($array as $key1 => &$row)
|
||||
{
|
||||
$data[$r] = array();
|
||||
foreach ($row as $key => $cell)
|
||||
{
|
||||
if (!is_array($cell))
|
||||
{
|
||||
$data[$r][$key] = $cell;
|
||||
}
|
||||
}
|
||||
$r++;
|
||||
$data[$key1] = [];
|
||||
array_walk($row, function($cell, $key2) use ($key1, &$data) {
|
||||
$data[$key1][$key2] = is_array($cell) ? '': $cell;
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -635,12 +627,16 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = $array;
|
||||
}
|
||||
|
||||
// Add results
|
||||
if (!empty($data))
|
||||
$this->data = !empty($this->data) ? array_merge($this->data, $data) : $data;
|
||||
return !empty($this->data) ? array_merge($this->data, $data) : $data;
|
||||
|
||||
// return data
|
||||
// Return data
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
@@ -693,16 +689,16 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
if (in_array($key, $this->allowedPageSetup))
|
||||
{
|
||||
// Set params
|
||||
$params = is_array($params) ? $params : array($params);
|
||||
$params = is_array($params) ? $params : [$params];
|
||||
|
||||
// Call the setter
|
||||
return call_user_func_array(array($this->getPageSetup(), $setter), $params);
|
||||
return call_user_func_array([$this->getPageSetup(), $setter], $params);
|
||||
}
|
||||
|
||||
// If is a style
|
||||
elseif (in_array($key, $this->allowedStyles))
|
||||
{
|
||||
return $this->setDefaultStyles($setter, $key, $params);
|
||||
return $this->setDefaultStyles($setter, $key, $params);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -720,12 +716,12 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
protected function setDefaultStyles($setter, $key, $params)
|
||||
{
|
||||
$caller = $this->getDefaultStyle();
|
||||
$params = is_array($params) ? $params : array($params);
|
||||
$params = is_array($params) ? $params : [$params];
|
||||
|
||||
if (str_contains($key, 'font'))
|
||||
return $this->setFontStyle($caller, $setter, $key, $params);
|
||||
|
||||
return call_user_func_array(array($caller, $setter), $params);
|
||||
return call_user_func_array([$caller, $setter], $params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -766,7 +762,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
{
|
||||
// Set caller to font
|
||||
$caller = $caller->getFont();
|
||||
$params = is_array($params) ? $params : array($params);
|
||||
$params = is_array($params) ? $params : [$params];
|
||||
|
||||
// Clean the setter name
|
||||
$setter = lcfirst(str_replace('Font', '', $setter));
|
||||
@@ -774,7 +770,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
// Replace special cases
|
||||
$setter = str_replace('Family', 'Name', $setter);
|
||||
|
||||
return call_user_func_array(array($caller, $setter), $params);
|
||||
return call_user_func_array([$caller, $setter], $params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -795,7 +791,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
}
|
||||
|
||||
// Return the setter method and the key
|
||||
return array($setter, $key);
|
||||
return [$setter, $key];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -957,7 +953,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
if (isset($this->autoSize))
|
||||
return $this->autoSize;
|
||||
|
||||
return Config::get('excel.export.autosize', true);
|
||||
return config('excel.export.autosize', true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1051,13 +1047,13 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
*/
|
||||
public function setAllBorders($weight = 'thin')
|
||||
{
|
||||
$styleArray = array(
|
||||
'borders' => array(
|
||||
'allborders' => array(
|
||||
$styleArray = [
|
||||
'borders' => [
|
||||
'allborders' => [
|
||||
'style' => $weight
|
||||
)
|
||||
)
|
||||
);
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
// Apply the style
|
||||
$this->getDefaultStyle()
|
||||
@@ -1100,7 +1096,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
// Set center alignment on merge cells
|
||||
$this->cells($pRange, function ($cell) use ($alignment)
|
||||
{
|
||||
$aligment = is_string($alignment) ? $alignment : Config::get('excel.export.merged_cell_alignment', 'left');
|
||||
$aligment = is_string($alignment) ? $alignment : config('excel.export.merged_cell_alignment', 'left');
|
||||
$cell->setAlignment($aligment);
|
||||
});
|
||||
|
||||
@@ -1173,7 +1169,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
*/
|
||||
protected function getDefaultNullValue()
|
||||
{
|
||||
return Config::get('excel.export.sheets.nullValue', null);
|
||||
return config('excel.export.sheets.nullValue', null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1182,7 +1178,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
*/
|
||||
protected function getDefaultStartCell()
|
||||
{
|
||||
return Config::get('excel.export.sheets.startCell', 'A1');
|
||||
return config('excel.export.sheets.startCell', 'A1');
|
||||
}
|
||||
|
||||
|
||||
@@ -1192,7 +1188,7 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
*/
|
||||
protected function getDefaultStrictNullComparison()
|
||||
{
|
||||
return Config::get('excel.export.sheets.strictNullComparison', false);
|
||||
return config('excel.export.sheets.strictNullComparison', false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1270,4 +1266,22 @@ class LaravelExcelWorksheet extends PHPExcel_Worksheet {
|
||||
? $this->getCell($currentColumn . $startRow)->setValueExplicit($cellValue)
|
||||
: $this->getCell($currentColumn . $startRow)->setValue($cellValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allowed page setup
|
||||
* @return array
|
||||
*/
|
||||
public function getAllowedPageSetup()
|
||||
{
|
||||
return $this->allowedPageSetup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allowed page setup
|
||||
* @return array
|
||||
*/
|
||||
public function getAllowedStyles()
|
||||
{
|
||||
return $this->allowedStyles;
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
<?php namespace Maatwebsite\Excel\Classes;
|
||||
|
||||
use PHPExcel as PHPOffice_PHPExcel;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -20,7 +19,7 @@ class PHPExcel extends PHPOffice_PHPExcel {
|
||||
* Allowed autofill properties
|
||||
* @var array
|
||||
*/
|
||||
public $allowedProperties = array(
|
||||
public $allowedProperties = [
|
||||
'creator',
|
||||
'lastModifiedBy',
|
||||
'description',
|
||||
@@ -29,7 +28,7 @@ class PHPExcel extends PHPOffice_PHPExcel {
|
||||
'category',
|
||||
'manager',
|
||||
'company'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Create sheet and add it to this workbook
|
||||
@@ -80,10 +79,10 @@ class PHPExcel extends PHPOffice_PHPExcel {
|
||||
$method = 'set' . ucfirst($prop);
|
||||
|
||||
// get the value
|
||||
$value = in_array($prop, array_keys($custom)) ? $custom[$prop] : Config::get('excel.properties.' . $prop, null);
|
||||
$value = in_array($prop, array_keys($custom)) ? $custom[$prop] : config('excel.properties.' . $prop, null);
|
||||
|
||||
// set the property
|
||||
call_user_func_array(array($properties, $method), array($value));
|
||||
call_user_func_array([$properties, $method], [$value]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,7 @@ class CellCollection extends ExcelCollection {
|
||||
* @param array $items
|
||||
* @return \Maatwebsite\Excel\Collections\CellCollection
|
||||
*/
|
||||
public function __construct(array $items = array())
|
||||
public function __construct(array $items = [])
|
||||
{
|
||||
$this->setItems($items);
|
||||
}
|
||||
@@ -29,30 +29,25 @@ class CellCollection extends ExcelCollection {
|
||||
*/
|
||||
public function setItems($items)
|
||||
{
|
||||
foreach ($items as $name => $value)
|
||||
{
|
||||
$value = !empty($value) || is_numeric($value) ? $value : null;
|
||||
|
||||
if ($name)
|
||||
{
|
||||
$this->put($name, $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->push($value);
|
||||
}
|
||||
foreach ($items as $name => $value) {
|
||||
$name = trim($name) !== '' && !empty($name) ? $name : null;
|
||||
$value = !empty($value) || is_numeric($value) || is_bool($value) ? $value : null;
|
||||
$this->put($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically get values
|
||||
* @param string $key
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
if ($this->has($key))
|
||||
if ($this->has($key)) {
|
||||
return $this->get($key);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -13,4 +13,27 @@
|
||||
*/
|
||||
class RowCollection extends ExcelCollection {
|
||||
|
||||
}
|
||||
/**
|
||||
* Sheet heading
|
||||
* @var array
|
||||
*/
|
||||
protected $heading;
|
||||
|
||||
/**
|
||||
* Get the heading
|
||||
* @return array
|
||||
*/
|
||||
public function getHeading()
|
||||
{
|
||||
return $this->heading;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the heading
|
||||
* @param array $heading
|
||||
*/
|
||||
public function setHeading(array $heading)
|
||||
{
|
||||
$this->heading = $heading;
|
||||
}
|
||||
}
|
||||
|
@@ -24,10 +24,10 @@ class Excel {
|
||||
* Filter
|
||||
* @var array
|
||||
*/
|
||||
protected $filters = array(
|
||||
'registered' => array(),
|
||||
'enabled' => array()
|
||||
);
|
||||
protected $filters = [
|
||||
'registered' => [],
|
||||
'enabled' => []
|
||||
];
|
||||
|
||||
/**
|
||||
* Excel object
|
||||
@@ -83,7 +83,7 @@ class Excel {
|
||||
$writer->setTitle($filename);
|
||||
|
||||
// Do the callback
|
||||
if ($callback instanceof Closure)
|
||||
if (is_callable($callback))
|
||||
call_user_func($callback, $writer);
|
||||
|
||||
// Return the writer object
|
||||
@@ -97,7 +97,8 @@ class Excel {
|
||||
* @param string $file The file we want to load
|
||||
* @param callback|null $callback
|
||||
* @param string|null $encoding
|
||||
* @param bool $noBasePath
|
||||
* @param bool $noBasePath
|
||||
* @param callback|null $callbackConfigReader
|
||||
* @return LaravelExcelReader
|
||||
*/
|
||||
public function load($file, $callback = null, $encoding = null, $noBasePath = false, $callbackConfigReader = null)
|
||||
@@ -130,7 +131,7 @@ class Excel {
|
||||
* @param $sheets
|
||||
* @return LaravelExcelReader
|
||||
*/
|
||||
public function selectSheets($sheets = array())
|
||||
public function selectSheets($sheets = [])
|
||||
{
|
||||
$sheets = is_array($sheets) ? $sheets : func_get_args();
|
||||
$this->reader->setSelectedSheets($sheets);
|
||||
@@ -143,7 +144,7 @@ class Excel {
|
||||
* @param array $sheets
|
||||
* @return $this
|
||||
*/
|
||||
public function selectSheetsByIndex($sheets = array())
|
||||
public function selectSheetsByIndex($sheets = [])
|
||||
{
|
||||
$sheets = is_array($sheets) ? $sheets : func_get_args();
|
||||
$this->reader->setSelectedSheetIndices($sheets);
|
||||
@@ -171,7 +172,7 @@ class Excel {
|
||||
* @param array $mergeData
|
||||
* @return LaravelExcelWriter
|
||||
*/
|
||||
public function shareView($view, $data = array(), $mergeData = array())
|
||||
public function shareView($view, $data = [], $mergeData = [])
|
||||
{
|
||||
return $this->create($view)->shareView($view, $data, $mergeData);
|
||||
}
|
||||
@@ -183,7 +184,7 @@ class Excel {
|
||||
* @param array $mergeData
|
||||
* @return LaravelExcelWriter
|
||||
*/
|
||||
public function loadView($view, $data = array(), $mergeData = array())
|
||||
public function loadView($view, $data = [], $mergeData = [])
|
||||
{
|
||||
return $this->shareView($view, $data, $mergeData);
|
||||
}
|
||||
@@ -193,7 +194,7 @@ class Excel {
|
||||
* @param array $filters
|
||||
* @return Excel
|
||||
*/
|
||||
public function registerFilters($filters = array())
|
||||
public function registerFilters($filters = [])
|
||||
{
|
||||
// If enabled array key exists
|
||||
if(array_key_exists('enabled', $filters))
|
||||
@@ -263,14 +264,14 @@ class Excel {
|
||||
if (method_exists($this->excel, $method))
|
||||
{
|
||||
// Call the method from the excel object with the given params
|
||||
return call_user_func_array(array($this->excel, $method), $params);
|
||||
return call_user_func_array([$this->excel, $method], $params);
|
||||
}
|
||||
|
||||
// If reader method exists, call that one
|
||||
if (method_exists($this->reader, $method))
|
||||
{
|
||||
// Call the method from the reader object with the given params
|
||||
return call_user_func_array(array($this->reader, $method), $params);
|
||||
return call_user_func_array([$this->reader, $method], $params);
|
||||
}
|
||||
|
||||
throw new LaravelExcelException('Laravel Excel method [' . $method . '] does not exist');
|
||||
|
@@ -4,9 +4,9 @@ use PHPExcel_Settings;
|
||||
use PHPExcel_Shared_Font;
|
||||
use Maatwebsite\Excel\Readers\Html;
|
||||
use Maatwebsite\Excel\Classes\Cache;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Maatwebsite\Excel\Classes\PHPExcel;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Maatwebsite\Excel\Parsers\CssParser;
|
||||
use Maatwebsite\Excel\Parsers\ViewParser;
|
||||
@@ -14,6 +14,7 @@ use Maatwebsite\Excel\Classes\FormatIdentifier;
|
||||
use Maatwebsite\Excel\Readers\LaravelExcelReader;
|
||||
use Maatwebsite\Excel\Writers\LaravelExcelWriter;
|
||||
use TijsVerkoyen\CssToInlineStyles\CssToInlineStyles;
|
||||
use Laravel\Lumen\Application as LumenApplication;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -42,9 +43,13 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
|
||||
public function boot()
|
||||
{
|
||||
$this->publishes([
|
||||
__DIR__ . '/../../config/excel.php' => config_path('excel.php'),
|
||||
]);
|
||||
if ($this->app instanceof LumenApplication) {
|
||||
$this->app->configure('excel');
|
||||
} else {
|
||||
$this->publishes([
|
||||
__DIR__ . '/../../config/excel.php' => config_path('excel.php'),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->mergeConfigFrom(
|
||||
__DIR__ . '/../../config/excel.php', 'excel'
|
||||
@@ -52,6 +57,18 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
|
||||
//Set the autosizing settings
|
||||
$this->setAutoSizingSettings();
|
||||
|
||||
//Enable an "export" method on Eloquent collections. ie: model::all()->export('file');
|
||||
if (method_exists(Collection::class, 'macro')) {
|
||||
Collection::macro('export', function($filename, $type = 'xlsx', $method = 'download') {
|
||||
$model = $this;
|
||||
Facades\Excel::create($filename, function($excel) use ($model, $filename) {
|
||||
$excel->sheet($filename, function($sheet) use ($model) {
|
||||
$sheet->fromModel($model);
|
||||
});
|
||||
})->$method($type);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +97,7 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
$me = $this;
|
||||
|
||||
// Bind the PHPExcel class
|
||||
$this->app['phpexcel'] = $this->app->share(function () use ($me)
|
||||
$this->app->singleton('phpexcel', function () use ($me)
|
||||
{
|
||||
// Set locale
|
||||
$me->setLocale();
|
||||
@@ -93,6 +110,8 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
$excel->setDefaultProperties();
|
||||
return $excel;
|
||||
});
|
||||
|
||||
$this->app->alias('phpexcel', PHPExcel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +120,7 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
protected function bindCssParser()
|
||||
{
|
||||
// Bind css parser
|
||||
$this->app['excel.parsers.css'] = $this->app->share(function ()
|
||||
$this->app->singleton('excel.parsers.css', function ()
|
||||
{
|
||||
return new CssParser(
|
||||
new CssToInlineStyles()
|
||||
@@ -116,7 +135,7 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
protected function bindReaders()
|
||||
{
|
||||
// Bind the laravel excel reader
|
||||
$this->app['excel.reader'] = $this->app->share(function ($app)
|
||||
$this->app->singleton('excel.reader', function ($app)
|
||||
{
|
||||
return new LaravelExcelReader(
|
||||
$app['files'],
|
||||
@@ -126,7 +145,7 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
});
|
||||
|
||||
// Bind the html reader class
|
||||
$this->app['excel.readers.html'] = $this->app->share(function ($app)
|
||||
$this->app->singleton('excel.readers.html', function ($app)
|
||||
{
|
||||
return new Html(
|
||||
$app['excel.parsers.css']
|
||||
@@ -141,7 +160,7 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
protected function bindParsers()
|
||||
{
|
||||
// Bind the view parser
|
||||
$this->app['excel.parsers.view'] = $this->app->share(function ($app)
|
||||
$this->app->singleton('excel.parsers.view', function ($app)
|
||||
{
|
||||
return new ViewParser(
|
||||
$app['excel.readers.html']
|
||||
@@ -156,7 +175,7 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
protected function bindWriters()
|
||||
{
|
||||
// Bind the excel writer
|
||||
$this->app['excel.writer'] = $this->app->share(function ($app)
|
||||
$this->app->singleton('excel.writer', function ($app)
|
||||
{
|
||||
return new LaravelExcelWriter(
|
||||
$app->make(Response::class),
|
||||
@@ -173,7 +192,7 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
protected function bindExcel()
|
||||
{
|
||||
// Bind the Excel class and inject its dependencies
|
||||
$this->app['excel'] = $this->app->share(function ($app)
|
||||
$this->app->singleton('excel', function ($app)
|
||||
{
|
||||
$excel = new Excel(
|
||||
$app['phpexcel'],
|
||||
@@ -186,8 +205,8 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
|
||||
return $excel;
|
||||
});
|
||||
|
||||
$this->app->alias('phpexcel', PHPExcel::class);
|
||||
|
||||
$this->app->alias('excel', Excel::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,7 +216,7 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
protected function bindClasses()
|
||||
{
|
||||
// Bind the format identifier
|
||||
$this->app['excel.identifier'] = $this->app->share(function ($app)
|
||||
$this->app->singleton('excel.identifier', function ($app)
|
||||
{
|
||||
return new FormatIdentifier($app['files']);
|
||||
});
|
||||
@@ -217,7 +236,7 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
*/
|
||||
public function setLocale()
|
||||
{
|
||||
$locale = Config::get('app.locale', 'en_us');
|
||||
$locale = config('app.locale', 'en_us');
|
||||
PHPExcel_Settings::setLocale($locale);
|
||||
}
|
||||
|
||||
@@ -226,7 +245,7 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
*/
|
||||
public function setAutoSizingSettings()
|
||||
{
|
||||
$method = Config::get('excel.export.autosize-method', PHPExcel_Shared_Font::AUTOSIZE_METHOD_APPROX);
|
||||
$method = config('excel.export.autosize-method', PHPExcel_Shared_Font::AUTOSIZE_METHOD_APPROX);
|
||||
PHPExcel_Shared_Font::setAutoSizeMethod($method);
|
||||
}
|
||||
|
||||
@@ -237,13 +256,13 @@ class ExcelServiceProvider extends ServiceProvider {
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'excel',
|
||||
'phpexcel',
|
||||
'excel.reader',
|
||||
'excel.readers.html',
|
||||
'excel.parsers.view',
|
||||
'excel.writer'
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -33,14 +33,11 @@ class ChunkReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
* @param string $column
|
||||
* @param integer $row
|
||||
* @param string $worksheetName
|
||||
* @return booleaan
|
||||
* @return boolean
|
||||
*/
|
||||
public function readCell($column, $row, $worksheetName = '')
|
||||
{
|
||||
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
|
||||
if (($row == config('excel.import.startRow')) || ($row >= $this->_startRow && $row <= $this->_endRow)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ($row == config('excel.import.startRow')) || ($row >= $this->_startRow && $row <= $this->_endRow);
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ class CssParser {
|
||||
* Style sheet links
|
||||
* @var array
|
||||
*/
|
||||
protected $links = array();
|
||||
protected $links = [];
|
||||
|
||||
/**
|
||||
* Construct the css parser
|
||||
@@ -48,23 +48,15 @@ class CssParser {
|
||||
*/
|
||||
public function transformCssToInlineStyles($html)
|
||||
{
|
||||
// Clean-up html
|
||||
$this->cssInliner->setCleanup(true);
|
||||
|
||||
// Set html
|
||||
$this->cssInliner->setHtml($html);
|
||||
|
||||
// Use inline style blocks
|
||||
$this->cssInliner->setUseInlineStylesBlock(true);
|
||||
$css = '';
|
||||
|
||||
// Loop through all stylesheets
|
||||
foreach($this->links as $link)
|
||||
{
|
||||
$css = file_get_contents($link);
|
||||
$this->cssInliner->setCSS($css);
|
||||
$css .= file_get_contents($link);
|
||||
}
|
||||
|
||||
return $this->cssInliner->convert();
|
||||
return $this->cssInliner->convert($html, $css);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,12 +1,14 @@
|
||||
<?php namespace Maatwebsite\Excel\Parsers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Maatwebsite\Excel\Classes\LaravelExcelWorksheet;
|
||||
use Maatwebsite\Excel\Classes\PHPExcel;
|
||||
use Maatwebsite\Excel\Readers\LaravelExcelReader;
|
||||
use PHPExcel_Cell;
|
||||
use PHPExcel_Exception;
|
||||
use PHPExcel_Shared_Date;
|
||||
use Illuminate\Support\Str;
|
||||
use PHPExcel_Style_NumberFormat;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Maatwebsite\Excel\Collections\RowCollection;
|
||||
use Maatwebsite\Excel\Collections\CellCollection;
|
||||
use Maatwebsite\Excel\Collections\SheetCollection;
|
||||
@@ -51,7 +53,7 @@ class ExcelParser {
|
||||
|
||||
/**
|
||||
* Row object
|
||||
* @var PHPExcel_Worksheet_Row
|
||||
* @var \PHPExcel_Worksheet_Row
|
||||
*/
|
||||
protected $row;
|
||||
|
||||
@@ -71,7 +73,7 @@ class ExcelParser {
|
||||
* Columns we want to fetch
|
||||
* @var array
|
||||
*/
|
||||
protected $columns = array();
|
||||
protected $columns = [];
|
||||
|
||||
/**
|
||||
* Row counter
|
||||
@@ -86,16 +88,14 @@ class ExcelParser {
|
||||
protected $defaultStartRow = 1;
|
||||
|
||||
/**
|
||||
* Construct excel parser
|
||||
* @param LaravelExcelReader $reader
|
||||
* @return \Maatwebsite\Excel\Parsers\ExcelParser
|
||||
*/
|
||||
public function __construct($reader)
|
||||
{
|
||||
$this->reader = $reader;
|
||||
$this->excel = $reader->excel;
|
||||
|
||||
$this->defaultStartRow = $this->currentRow = Config::get('excel.import.startRow', 1);
|
||||
$this->defaultStartRow = $this->currentRow = $reader->getHeaderRow();
|
||||
|
||||
// Reset
|
||||
$this->reset();
|
||||
@@ -106,7 +106,7 @@ class ExcelParser {
|
||||
* @param array $columns
|
||||
* @return SheetCollection
|
||||
*/
|
||||
public function parseFile($columns = array())
|
||||
public function parseFile($columns = [])
|
||||
{
|
||||
// Init new sheet collection
|
||||
$workbook = new SheetCollection();
|
||||
@@ -164,7 +164,7 @@ class ExcelParser {
|
||||
protected function parseAsMultiple()
|
||||
{
|
||||
return ($this->excel->getSheetCount() > 1 && count($this->reader->getSelectedSheetIndices()) !== 1)
|
||||
|| Config::get('excel.import.force_sheets_collection', false);
|
||||
|| config('excel.import.force_sheets_collection', false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,7 +177,7 @@ class ExcelParser {
|
||||
$this->excel->setActiveSheetIndex($this->w);
|
||||
|
||||
// Fetch the labels
|
||||
$this->indices = $this->reader->hasHeading() ? $this->getIndices() : array();
|
||||
$this->indices = $this->reader->hasHeading() ? $this->getIndices() : [];
|
||||
|
||||
// Parse the rows
|
||||
return $this->parseRows();
|
||||
@@ -193,11 +193,10 @@ class ExcelParser {
|
||||
$this->row = $this->worksheet->getRowIterator($this->defaultStartRow)->current();
|
||||
|
||||
// Set empty labels array
|
||||
$this->indices = array();
|
||||
$this->indices = [];
|
||||
|
||||
// Loop through the cells
|
||||
foreach ($this->row->getCellIterator() as $this->cell)
|
||||
{
|
||||
foreach ($this->row->getCellIterator() as $this->cell) {
|
||||
$this->indices[] = $this->getIndex($this->cell);
|
||||
}
|
||||
|
||||
@@ -213,7 +212,7 @@ class ExcelParser {
|
||||
protected function getIndex($cell)
|
||||
{
|
||||
// Get heading type
|
||||
$config = Config::get('excel.import.heading', true);
|
||||
$config = config('excel.import.heading', true);
|
||||
$config = $config === true ? 'slugged' : $config;
|
||||
|
||||
// Get value
|
||||
@@ -222,10 +221,10 @@ class ExcelParser {
|
||||
switch ($config)
|
||||
{
|
||||
case 'slugged':
|
||||
return $this->getSluggedIndex($value, Config::get('excel.import.to_ascii', true));
|
||||
return $this->getSluggedIndex($value, config('excel.import.to_ascii', true));
|
||||
break;
|
||||
case 'slugged_with_count':
|
||||
$index = $this->getSluggedIndex($value, Config::get('excel.import.to_ascii', true));
|
||||
$index = $this->getSluggedIndex($value, config('excel.import.to_ascii', true));
|
||||
if(in_array($index,$this->indices)){
|
||||
$index = $this->appendOrIncreaseStringCount($index);
|
||||
}
|
||||
@@ -240,6 +239,10 @@ class ExcelParser {
|
||||
return $this->getHashedIndex($value);
|
||||
break;
|
||||
|
||||
case 'hashed_with_lower':
|
||||
return $this->getHashedIndex(strtolower(trim($value)));
|
||||
break;
|
||||
|
||||
case 'trans':
|
||||
return $this->getTranslatedIndex($value);
|
||||
break;
|
||||
@@ -296,7 +299,7 @@ class ExcelParser {
|
||||
$value = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $value);
|
||||
|
||||
// Remove all characters that are not the separator, letters, numbers, or whitespace.
|
||||
$value = preg_replace('![^' . preg_quote($separator) . '\pL\pN\s]+!u', '', mb_strtolower($value));
|
||||
$value = preg_replace('![^' . preg_quote(config('excel.import.slug_whitelist', $separator)) . '\pL\pN\s]+!u', '', mb_strtolower($value));
|
||||
|
||||
// Replace all separator characters and whitespace by a single separator
|
||||
$value = preg_replace('![' . preg_quote($separator) . '\s]+!u', $separator, $value);
|
||||
@@ -356,6 +359,9 @@ class ExcelParser {
|
||||
// set sheet title
|
||||
$parsedRows->setTitle($this->excel->getActiveSheet()->getTitle());
|
||||
|
||||
// set sheet heading
|
||||
$parsedRows->setHeading($this->indices);
|
||||
|
||||
// Get the start row
|
||||
$startRow = $this->getStartRow();
|
||||
|
||||
@@ -369,7 +375,7 @@ class ExcelParser {
|
||||
foreach ($rows as $this->row)
|
||||
{
|
||||
// Limit the results when needed
|
||||
if ( $this->hasReachedLimit() )
|
||||
if ( $this->hasReachedLimitRows() )
|
||||
break;
|
||||
|
||||
// Push the parsed cells inside the parsed rows
|
||||
@@ -408,16 +414,16 @@ class ExcelParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for the limit
|
||||
* Check for the row limit
|
||||
* @return boolean
|
||||
*/
|
||||
protected function hasReachedLimit()
|
||||
protected function hasReachedLimitRows()
|
||||
{
|
||||
// Get skip
|
||||
$limit = $this->reader->getLimit();
|
||||
$rowsLimit = $this->reader->getLimitRows();
|
||||
|
||||
// If we have a limit, check if we hit this limit
|
||||
return $limit && $this->currentRow > $limit ? true : false;
|
||||
return $rowsLimit && $this->currentRow > $rowsLimit ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -426,12 +432,17 @@ class ExcelParser {
|
||||
*/
|
||||
protected function parseCells()
|
||||
{
|
||||
$i = 0;
|
||||
$parsedCells = array();
|
||||
|
||||
// Skip the columns when needed
|
||||
$startColumn = $this->reader->getTargetSkipColumns();
|
||||
|
||||
// Limit the columns when needed
|
||||
$endColumn = $this->reader->getTargetLimitColumns();
|
||||
|
||||
try {
|
||||
// Set the cell iterator
|
||||
$cellIterator = $this->row->getCellIterator();
|
||||
$cellIterator = $this->row->getCellIterator($startColumn, $endColumn);
|
||||
|
||||
// Ignore empty cells if needed
|
||||
$cellIterator->setIterateOnlyExistingCells($this->reader->needsIgnoreEmpty());
|
||||
@@ -440,16 +451,18 @@ class ExcelParser {
|
||||
foreach ($cellIterator as $this->cell)
|
||||
{
|
||||
// Check how we need to save the parsed array
|
||||
$index = ($this->reader->hasHeading() && isset($this->indices[$i])) ? $this->indices[$i] : $this->getIndexFromColumn();
|
||||
// Use the index from column as the initial position
|
||||
// Or else PHPExcel skips empty cells (even between non-empty) cells and it will cause
|
||||
// data to end up in the result object
|
||||
$index = $this->getIndexFromColumn() - 1;
|
||||
$index = ($this->reader->hasHeading() && isset($this->indices[$index])) ? $this->indices[$index] : $index;
|
||||
|
||||
// Check if we want to select this column
|
||||
if ( $this->cellNeedsParsing($index) )
|
||||
{
|
||||
// Set the value
|
||||
// Set the value1
|
||||
$parsedCells[(string) $index] = $this->parseCell($index);
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
} catch (PHPExcel_Exception $e) {
|
||||
@@ -458,11 +471,18 @@ class ExcelParser {
|
||||
throw $e;
|
||||
}
|
||||
// make sure that we return an empty CellCollection
|
||||
$parsedCells = array();
|
||||
$parsedCells = [];
|
||||
}
|
||||
|
||||
// Return array with parsed cells
|
||||
return new CellCollection($parsedCells);
|
||||
$cells = new CellCollection($parsedCells);
|
||||
|
||||
if (! $this->reader->hasHeading()) {
|
||||
// Cell index starts at 0 when no heading
|
||||
return $cells->values();
|
||||
}
|
||||
|
||||
return $cells;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -522,7 +542,7 @@ class ExcelParser {
|
||||
protected function encode($value)
|
||||
{
|
||||
// Get input and output encoding
|
||||
list($input, $output) = array_values(Config::get('excel.import.encoding', array('UTF-8', 'UTF-8')));
|
||||
list($input, $output) = array_values(config('excel.import.encoding', array('UTF-8', 'UTF-8')));
|
||||
|
||||
// If they are the same, return the value
|
||||
if ( $input == $output )
|
||||
@@ -560,8 +580,15 @@ class ExcelParser {
|
||||
// If has a date
|
||||
if ( $cellContent = $this->cell->getCalculatedValue() )
|
||||
{
|
||||
// Convert excel time to php date object
|
||||
$date = PHPExcel_Shared_Date::ExcelToPHPObject($this->cell->getCalculatedValue())->format('Y-m-d H:i:s');
|
||||
try
|
||||
{
|
||||
// Convert excel time to php date object
|
||||
$date = PHPExcel_Shared_Date::ExcelToPHPObject($this->cell->getCalculatedValue())->format('Y-m-d H:i:s');
|
||||
}
|
||||
catch( \ErrorException $ex )
|
||||
{
|
||||
return null ;
|
||||
}
|
||||
|
||||
// Parse with carbon
|
||||
$date = Carbon::parse($date);
|
||||
@@ -661,7 +688,7 @@ class ExcelParser {
|
||||
*/
|
||||
protected function reset()
|
||||
{
|
||||
$this->indices = array();
|
||||
$this->indices = [];
|
||||
$this->isParsed = false;
|
||||
}
|
||||
}
|
||||
|
@@ -26,13 +26,13 @@ class ViewParser {
|
||||
* Data array
|
||||
* @var array
|
||||
*/
|
||||
public $data = array();
|
||||
public $data = [];
|
||||
|
||||
/**
|
||||
* View merge data
|
||||
* @var array
|
||||
*/
|
||||
public $mergeData = array();
|
||||
public $mergeData = [];
|
||||
|
||||
/**
|
||||
* Construct the view parser
|
||||
@@ -108,7 +108,7 @@ class ViewParser {
|
||||
* Set the data
|
||||
* @param array $data
|
||||
*/
|
||||
public function setData($data = array())
|
||||
public function setData($data = [])
|
||||
{
|
||||
if (!empty($data))
|
||||
$this->data = array_merge($this->data, $data);
|
||||
@@ -118,7 +118,7 @@ class ViewParser {
|
||||
* Set the merge data
|
||||
* @param array $mergeData
|
||||
*/
|
||||
public function setMergeData($mergeData = array())
|
||||
public function setMergeData($mergeData = [])
|
||||
{
|
||||
if (!empty($mergeData))
|
||||
$this->mergeData = array_merge($this->mergeData, $mergeData);
|
||||
|
@@ -27,17 +27,17 @@ class Batch {
|
||||
* Batch files
|
||||
* @var array
|
||||
*/
|
||||
public $files = array();
|
||||
public $files = [];
|
||||
|
||||
/**
|
||||
* Set allowed file extensions
|
||||
* @var array
|
||||
*/
|
||||
protected $allowedFileExtensions = array(
|
||||
protected $allowedFileExtensions = [
|
||||
'xls',
|
||||
'xlsx',
|
||||
'csv'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Start the Batach
|
||||
@@ -112,7 +112,7 @@ class Batch {
|
||||
*/
|
||||
protected function _getFilesByArray($array)
|
||||
{
|
||||
$files = array();
|
||||
$files = [];
|
||||
// Make sure we have real paths
|
||||
foreach ($array as $i => $file)
|
||||
{
|
||||
@@ -137,7 +137,7 @@ class Batch {
|
||||
$glob = glob($folder . '/*.{' . implode(',', $this->allowedFileExtensions) . '}', GLOB_BRACE);
|
||||
|
||||
// If no matches, return empty array
|
||||
if ($glob === false) return array();
|
||||
if ($glob === false) return [];
|
||||
|
||||
// Return files
|
||||
return array_filter($glob, function ($file)
|
||||
|
@@ -2,12 +2,15 @@
|
||||
|
||||
namespace Maatwebsite\Excel\Readers;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Maatwebsite\Excel\Filters\ChunkReadFilter;
|
||||
use SuperClosure\Serializer;
|
||||
|
||||
class ChunkedReadJob implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
@@ -42,17 +45,23 @@ class ChunkedReadJob implements ShouldQueue
|
||||
* @var bool
|
||||
*/
|
||||
private $shouldQueue;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $encoding;
|
||||
|
||||
/**
|
||||
* ChunkedReadJob constructor.
|
||||
*
|
||||
* @param $file
|
||||
* @param null $sheets
|
||||
* @param int $startRow
|
||||
* @param $startIndex
|
||||
* @param $chunkSize
|
||||
* @param callable $callback
|
||||
* @param bool $shouldQueue
|
||||
* @param $file
|
||||
* @param null $sheets
|
||||
* @param int $startRow
|
||||
* @param $startIndex
|
||||
* @param $chunkSize
|
||||
* @param callable $callback
|
||||
* @param bool $shouldQueue
|
||||
* @param string|null $encoding
|
||||
*/
|
||||
public function __construct(
|
||||
$file,
|
||||
@@ -61,7 +70,8 @@ class ChunkedReadJob implements ShouldQueue
|
||||
$startIndex,
|
||||
$chunkSize,
|
||||
callable $callback,
|
||||
$shouldQueue = true
|
||||
$shouldQueue = true,
|
||||
$encoding = null
|
||||
) {
|
||||
$this->startRow = $startRow;
|
||||
$this->chunkSize = $chunkSize;
|
||||
@@ -71,6 +81,7 @@ class ChunkedReadJob implements ShouldQueue
|
||||
$this->callback = $shouldQueue ? (new Serializer)->serialize($callback) : $callback;
|
||||
$this->sheets = $sheets;
|
||||
$this->shouldQueue = $shouldQueue;
|
||||
$this->encoding = $encoding;
|
||||
}
|
||||
|
||||
/***
|
||||
@@ -86,6 +97,11 @@ class ChunkedReadJob implements ShouldQueue
|
||||
$reader->reader->setLoadSheetsOnly($this->sheets);
|
||||
$reader->reader->setReadFilter($filter);
|
||||
$reader->reader->setReadDataOnly(true);
|
||||
|
||||
// Set encoding
|
||||
if (! is_null($this->encoding)) {
|
||||
$reader->reader->setInputEncoding($this->encoding);
|
||||
}
|
||||
|
||||
// Set the rows for the chunking
|
||||
$filter->setRows($this->startRow, $this->chunkSize);
|
||||
@@ -94,7 +110,7 @@ class ChunkedReadJob implements ShouldQueue
|
||||
$reader->excel = $reader->reader->load($this->file);
|
||||
|
||||
// Slice the results
|
||||
$results = $reader->get()->slice($this->startIndex, $this->chunkSize);
|
||||
$results = $reader->limitRows($this->chunkSize, $this->startIndex)->get();
|
||||
|
||||
$callback = $this->shouldQueue ? (new Serializer)->unserialize($this->callback) : $this->callback;
|
||||
|
||||
|
@@ -3,7 +3,6 @@
|
||||
use Closure;
|
||||
use PHPExcel;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Maatwebsite\Excel\Collections\SheetCollection;
|
||||
use Maatwebsite\Excel\Exceptions\LaravelExcelException;
|
||||
|
||||
@@ -161,7 +160,7 @@ class ConfigReader {
|
||||
*/
|
||||
protected function getCoordinateByKey($field)
|
||||
{
|
||||
return Config::get($this->configName . '.' . $this->sheetName . '.' . $field, false);
|
||||
return config($this->configName . '.' . $this->sheetName . '.' . $field, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -14,7 +14,6 @@ use PHPExcel_Style_Font;
|
||||
use PHPExcel_Style_Border;
|
||||
use PHPExcel_Worksheet_Drawing;
|
||||
use PHPExcel_Style_Alignment;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Maatwebsite\Excel\Parsers\CssParser;
|
||||
use Maatwebsite\Excel\Classes\LaravelExcelWorksheet;
|
||||
|
||||
@@ -36,11 +35,11 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
* Style per range
|
||||
* @var array
|
||||
*/
|
||||
protected $styles = array();
|
||||
protected $styles = [];
|
||||
|
||||
protected $_dataArray = array();
|
||||
protected $_dataArray = [];
|
||||
|
||||
protected $_nestedColumn = array('A');
|
||||
protected $_nestedColumn = ['A'];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
@@ -63,7 +62,7 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
* HTML tags formatting settings
|
||||
* @var array
|
||||
*/
|
||||
protected $_formats = array();
|
||||
protected $_formats = [];
|
||||
|
||||
/**
|
||||
* The current colspan
|
||||
@@ -127,7 +126,7 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
*/
|
||||
protected function setStyleFormats()
|
||||
{
|
||||
$this->_formats = Config::get('excel.views.styles', array());
|
||||
$this->_formats = config('excel.views.styles', []);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,7 +272,7 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
// If is a dom element
|
||||
elseif ( $child instanceof DOMElement )
|
||||
{
|
||||
$attributeArray = array();
|
||||
$attributeArray = [];
|
||||
|
||||
// Set row (=parent) styles
|
||||
if ( isset($this->styles[$row]) )
|
||||
@@ -744,7 +743,7 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
protected function insertImageBySrc($sheet, $column, $row, $attributes)
|
||||
{
|
||||
// Get attributes
|
||||
$src = $attributes->getAttribute('src');
|
||||
$src = urldecode($attributes->getAttribute('src'));
|
||||
$width = (float) $attributes->getAttribute('width');
|
||||
$height = (float) $attributes->getAttribute('height');
|
||||
$alt = $attributes->getAttribute('alt');
|
||||
@@ -758,7 +757,7 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
$drawing->setWorksheet($sheet);
|
||||
$drawing->setCoordinates($column . $row);
|
||||
$drawing->setResizeProportional();
|
||||
$drawing->setOffsetX($drawing->getWidth() - $drawing->getWidth() / 5);
|
||||
$drawing->setOffsetX(0);
|
||||
$drawing->setOffsetY(10);
|
||||
|
||||
// Set height and width
|
||||
@@ -769,8 +768,8 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
$drawing->setHeight($height);
|
||||
|
||||
// Set cell width based on image
|
||||
$this->parseWidth($sheet, $column, $row, $drawing->getWidth() / 3);
|
||||
$this->parseHeight($sheet, $column, $row, $drawing->getHeight());
|
||||
$this->parseWidth($sheet, $column, $row, $drawing->getWidth() / 6);
|
||||
$this->parseHeight($sheet, $column, $row, $drawing->getHeight() * 0.9);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -921,7 +920,7 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
|
||||
if ( $horizontal )
|
||||
$cells->getAlignment()->applyFromArray(
|
||||
array('horizontal' => $horizontal)
|
||||
['horizontal' => $horizontal]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -960,7 +959,7 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
|
||||
if ( $vertical )
|
||||
$cells->getAlignment()->applyFromArray(
|
||||
array('vertical' => $vertical)
|
||||
['vertical' => $vertical]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -988,7 +987,7 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
* @param array @styles
|
||||
* @return void
|
||||
*/
|
||||
protected function parseCssAttributes($sheet, $column, $row, $styles = array())
|
||||
protected function parseCssAttributes($sheet, $column, $row, $styles = [])
|
||||
{
|
||||
foreach ($styles as $tag)
|
||||
{
|
||||
@@ -1033,10 +1032,10 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
$value = $this->getColor($value);
|
||||
|
||||
$cells->getFill()->applyFromArray(
|
||||
array(
|
||||
[
|
||||
'type' => PHPExcel_Style_Fill::FILL_SOLID,
|
||||
'color' => array('rgb' => $value)
|
||||
)
|
||||
'color' => ['rgb' => $value]
|
||||
]
|
||||
);
|
||||
|
||||
break;
|
||||
@@ -1045,7 +1044,7 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
case 'color':
|
||||
$value = $this->getColor($value);
|
||||
$cells->getFont()->getColor()->applyFromArray(
|
||||
array('rgb' => $value)
|
||||
['rgb' => $value]
|
||||
);
|
||||
break;
|
||||
|
||||
@@ -1069,7 +1068,7 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
// FONT FACE
|
||||
case 'font-family':
|
||||
$cells->getFont()->applyFromArray(
|
||||
array('name' => $value)
|
||||
['name' => $value]
|
||||
);
|
||||
break;
|
||||
|
||||
@@ -1113,7 +1112,7 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
|
||||
if ( $horizontal )
|
||||
$cells->getAlignment()->applyFromArray(
|
||||
array('horizontal' => $horizontal)
|
||||
['horizontal' => $horizontal]
|
||||
);
|
||||
|
||||
break;
|
||||
@@ -1144,7 +1143,7 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
|
||||
if ( $vertical )
|
||||
$cells->getAlignment()->applyFromArray(
|
||||
array('vertical' => $vertical)
|
||||
['vertical' => $vertical]
|
||||
);
|
||||
break;
|
||||
|
||||
@@ -1152,67 +1151,77 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
case 'border':
|
||||
case 'borders':
|
||||
$borders = explode(' ', $value);
|
||||
$style = $borders[1];
|
||||
$color = end($borders);
|
||||
$color = $this->getColor($color);
|
||||
$borderStyle = $this->borderStyle($style);
|
||||
if (!empty($borders[1])) {
|
||||
$style = $borders[1];
|
||||
$color = end($borders);
|
||||
$color = $this->getColor($color);
|
||||
$borderStyle = $this->borderStyle($style);
|
||||
|
||||
$cells->getBorders()->applyFromArray(
|
||||
array('allborders' => array('style' => $borderStyle, 'color' => array('rgb' => $color)))
|
||||
);
|
||||
$cells->getBorders()->applyFromArray(
|
||||
['allborders' => ['style' => $borderStyle, 'color' => ['rgb' => $color]]]
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
// Border-top
|
||||
case 'border-top':
|
||||
$borders = explode(' ', $value);
|
||||
$style = $borders[1];
|
||||
$color = end($borders);
|
||||
$color = $this->getColor($color);
|
||||
if (!empty($borders[1])) {
|
||||
$style = $borders[1];
|
||||
$color = end($borders);
|
||||
$color = $this->getColor($color);
|
||||
|
||||
$borderStyle = $this->borderStyle($style);
|
||||
$borderStyle = $this->borderStyle($style);
|
||||
|
||||
$cells->getBorders()->getTop()->applyFromArray(
|
||||
array('style' => $borderStyle, 'color' => array('rgb' => $color))
|
||||
);
|
||||
$cells->getBorders()->getTop()->applyFromArray(
|
||||
['style' => $borderStyle, 'color' => ['rgb' => $color]]
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
// Border-bottom
|
||||
case 'border-bottom':
|
||||
$borders = explode(' ', $value);
|
||||
$style = $borders[1];
|
||||
$color = end($borders);
|
||||
$color = $this->getColor($color);
|
||||
$borderStyle = $this->borderStyle($style);
|
||||
if (!empty($borders[1])) {
|
||||
$style = $borders[1];
|
||||
$color = end($borders);
|
||||
$color = $this->getColor($color);
|
||||
$borderStyle = $this->borderStyle($style);
|
||||
|
||||
$cells->getBorders()->getBottom()->applyFromArray(
|
||||
array('style' => $borderStyle, 'color' => array('rgb' => $color))
|
||||
);
|
||||
$cells->getBorders()->getBottom()->applyFromArray(
|
||||
['style' => $borderStyle, 'color' => ['rgb' => $color]]
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
// Border-right
|
||||
case 'border-right':
|
||||
$borders = explode(' ', $value);
|
||||
$style = $borders[1];
|
||||
$color = end($borders);
|
||||
$color = $this->getColor($color);
|
||||
$borderStyle = $this->borderStyle($style);
|
||||
if (!empty($borders[1])) {
|
||||
$style = $borders[1];
|
||||
$color = end($borders);
|
||||
$color = $this->getColor($color);
|
||||
$borderStyle = $this->borderStyle($style);
|
||||
|
||||
$cells->getBorders()->getRight()->applyFromArray(
|
||||
array('style' => $borderStyle, 'color' => array('rgb' => $color))
|
||||
);
|
||||
$cells->getBorders()->getRight()->applyFromArray(
|
||||
['style' => $borderStyle, 'color' => ['rgb' => $color]]
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
// Border-left
|
||||
case 'border-left':
|
||||
$borders = explode(' ', $value);
|
||||
$style = $borders[1];
|
||||
$color = end($borders);
|
||||
$color = $this->getColor($color);
|
||||
$borderStyle = $this->borderStyle($style);
|
||||
if (!empty($borders[1])) {
|
||||
$style = $borders[1];
|
||||
$color = end($borders);
|
||||
$color = $this->getColor($color);
|
||||
$borderStyle = $this->borderStyle($style);
|
||||
|
||||
$cells->getBorders()->getLeft()->applyFromArray(
|
||||
array('style' => $borderStyle, 'color' => array('rgb' => $color))
|
||||
);
|
||||
$cells->getBorders()->getLeft()->applyFromArray(
|
||||
['style' => $borderStyle, 'color' => ['rgb' => $color]]
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
// wrap-text
|
||||
@@ -1362,6 +1371,6 @@ class Html extends PHPExcel_Reader_HTML {
|
||||
}
|
||||
}
|
||||
|
||||
return array($column, $cellContent);
|
||||
return [$column, $cellContent];
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
<?php namespace Maatwebsite\Excel\Readers;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Maatwebsite\Excel\Classes\PHPExcel;
|
||||
@@ -97,18 +96,39 @@ class LaravelExcelReader
|
||||
public $calculate;
|
||||
|
||||
/**
|
||||
* Limit data
|
||||
* Limit of rows
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $limit = false;
|
||||
protected $limitRows = false;
|
||||
|
||||
/**
|
||||
* Amount of rows to skip
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $skip = 0;
|
||||
protected $skipRows = 0;
|
||||
|
||||
/**
|
||||
* Target columns
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $targetColumns = [];
|
||||
|
||||
/**
|
||||
* Limit of columns
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $limitColumns = false;
|
||||
|
||||
/**
|
||||
* Amount of columns to skip
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $skipColumns = 0;
|
||||
|
||||
/**
|
||||
* Slug separator
|
||||
@@ -226,6 +246,13 @@ class LaravelExcelReader
|
||||
*/
|
||||
protected $dispatcher;
|
||||
|
||||
/**
|
||||
* The line containing the header title, by default
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headerRow;
|
||||
|
||||
/**
|
||||
* Construct new reader
|
||||
*
|
||||
@@ -351,6 +378,15 @@ class LaravelExcelReader
|
||||
$this->selectedSheets = $sheets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define a different header row than the global config
|
||||
* @param int $number
|
||||
*/
|
||||
public function setHeaderRow($number)
|
||||
{
|
||||
$this->headerRow = $number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if sheets were selected
|
||||
*
|
||||
@@ -375,7 +411,7 @@ class LaravelExcelReader
|
||||
return true;
|
||||
}
|
||||
|
||||
return in_array($index, $selectedSheets) ? true : false;
|
||||
return in_array($index, $selectedSheets);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -442,7 +478,20 @@ class LaravelExcelReader
|
||||
public function take($amount)
|
||||
{
|
||||
// Set limit
|
||||
$this->limit = $amount;
|
||||
return $this->takeRows($amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take x rows
|
||||
*
|
||||
* @param integer $amount
|
||||
*
|
||||
* @return LaravelExcelReader
|
||||
*/
|
||||
public function takeRows($amount)
|
||||
{
|
||||
// Set limit
|
||||
$this->limitRows = $amount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -457,7 +506,20 @@ class LaravelExcelReader
|
||||
public function skip($amount)
|
||||
{
|
||||
// Set skip amount
|
||||
$this->skip = $amount;
|
||||
return $this->skipRows($amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip x rows
|
||||
*
|
||||
* @param integer $amount
|
||||
*
|
||||
* @return LaravelExcelReader
|
||||
*/
|
||||
public function skipRows($amount)
|
||||
{
|
||||
// Set skip amount
|
||||
$this->skipRows = $amount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -471,12 +533,75 @@ class LaravelExcelReader
|
||||
* @return LaravelExcelReader
|
||||
*/
|
||||
public function limit($take, $skip = 0)
|
||||
{
|
||||
// Limit the results by x
|
||||
return $this->limitRows($take, $skip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the results by x
|
||||
*
|
||||
* @param integer $take
|
||||
* @param integer $skip
|
||||
*
|
||||
* @return LaravelExcelReader
|
||||
*/
|
||||
public function limitRows($take, $skip = 0)
|
||||
{
|
||||
// Skip x records
|
||||
$this->skip($skip);
|
||||
$this->skipRows($skip);
|
||||
|
||||
// Take x records
|
||||
$this->take($take);
|
||||
$this->takeRows($take);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take x columns
|
||||
*
|
||||
* @param integer $amount
|
||||
*
|
||||
* @return LaravelExcelReader
|
||||
*/
|
||||
public function takeColumns($amount)
|
||||
{
|
||||
// Set limit
|
||||
$this->limitColumns = $amount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip x columns
|
||||
*
|
||||
* @param integer $amount
|
||||
*
|
||||
* @return LaravelExcelReader
|
||||
*/
|
||||
public function skipColumns($amount)
|
||||
{
|
||||
// Set skip amount
|
||||
$this->skipColumns = $amount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit the results by x
|
||||
*
|
||||
* @param integer $take
|
||||
* @param integer $skip
|
||||
*
|
||||
* @return LaravelExcelReader
|
||||
*/
|
||||
public function limitColumns($take, $skip = 0)
|
||||
{
|
||||
// Skip x records
|
||||
$this->skipColumns($skip);
|
||||
|
||||
// Take x records
|
||||
$this->takeColumns($take);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -516,7 +641,7 @@ class LaravelExcelReader
|
||||
*/
|
||||
public function first($columns = [])
|
||||
{
|
||||
return $this->take(1)->get($columns)->first();
|
||||
return $this->get($columns)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -546,9 +671,9 @@ class LaravelExcelReader
|
||||
/**
|
||||
* Parse the file in chunks and queues the processing of each chunk
|
||||
*
|
||||
* @param int $size
|
||||
* @param callable $callback
|
||||
* @param bool $shouldQueue
|
||||
* @param int $size
|
||||
* @param callable $callback
|
||||
* @param bool|string $shouldQueue
|
||||
*/
|
||||
public function chunk($size = 10, callable $callback, $shouldQueue = true)
|
||||
{
|
||||
@@ -560,8 +685,14 @@ class LaravelExcelReader
|
||||
for ($startRow = 0; $startRow < $totalRows; $startRow += $chunkSize) {
|
||||
|
||||
// Set start index
|
||||
$startIndex = ($startRow == 0) ? $startRow : $startRow - 1;
|
||||
$chunkSize = ($startRow == 0) ? $size + 1 : $size;
|
||||
$startIndex = ($startRow == 0 || !$this->hasHeading()) ? $startRow : $startRow - 1;
|
||||
$chunkSize = ($startRow == 0 && $this->hasHeading()) ? $size + 1 : $size;
|
||||
|
||||
$encoding = null;
|
||||
|
||||
if ($this->format == 'CSV') {
|
||||
$encoding = $this->reader->getInputEncoding($encoding);
|
||||
}
|
||||
|
||||
$job = new ChunkedReadJob(
|
||||
$this->file,
|
||||
@@ -570,10 +701,15 @@ class LaravelExcelReader
|
||||
$startIndex,
|
||||
$chunkSize,
|
||||
$callback,
|
||||
$shouldQueue
|
||||
$shouldQueue,
|
||||
$encoding
|
||||
);
|
||||
|
||||
if ($shouldQueue) {
|
||||
// If a string is passed (which also evaluates to true if not empty), assign to that named queue
|
||||
if(is_string($shouldQueue)) {
|
||||
$job->onQueue($shouldQueue);
|
||||
}
|
||||
$this->dispatcher->dispatch($job);
|
||||
} else {
|
||||
$break = $job->handle();
|
||||
@@ -736,7 +872,7 @@ class LaravelExcelReader
|
||||
protected function _setFile($file, $noBasePath = false)
|
||||
{
|
||||
// check if we have a correct path
|
||||
if (!$noBasePath && !realpath($file)) {
|
||||
if (!is_file($file) && !$noBasePath && !realpath($file)) {
|
||||
$file = base_path($file);
|
||||
}
|
||||
|
||||
@@ -903,7 +1039,7 @@ class LaravelExcelReader
|
||||
*
|
||||
* @param boolean $boolean
|
||||
*
|
||||
* @return LaraveExcelReader
|
||||
* @return LaravelExcelReader
|
||||
*/
|
||||
public function ignoreEmpty($boolean = true)
|
||||
{
|
||||
@@ -920,7 +1056,7 @@ class LaravelExcelReader
|
||||
public function hasHeading()
|
||||
{
|
||||
if (!$this->noHeading) {
|
||||
$config = Config::get('excel.import.heading', true);
|
||||
$config = config('excel.import.heading', true);
|
||||
|
||||
return $config !== false && $config !== 'numeric';
|
||||
}
|
||||
@@ -939,7 +1075,7 @@ class LaravelExcelReader
|
||||
return $this->separator;
|
||||
}
|
||||
|
||||
return Config::get('excel.import.separator', Config::get('excel.import.seperator', '_'));
|
||||
return config('excel.import.separator', config('excel.import.seperator', '_'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -999,7 +1135,17 @@ class LaravelExcelReader
|
||||
*/
|
||||
public function getSkip()
|
||||
{
|
||||
return $this->skip;
|
||||
return $this->getSkipRows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the amount of rows to skip
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getSkipRows()
|
||||
{
|
||||
return $this->skipRows;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1009,7 +1155,88 @@ class LaravelExcelReader
|
||||
*/
|
||||
public function getLimit()
|
||||
{
|
||||
return $this->limit;
|
||||
return $this->getLimitRows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the amount of rows to take
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getLimitRows()
|
||||
{
|
||||
return $this->limitRows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the amount of columns to skip
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getSkipColumns()
|
||||
{
|
||||
return $this->skipColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the target of columns to skip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTargetSkipColumns()
|
||||
{
|
||||
if (empty($this->skipColumns)) {
|
||||
return 'A';
|
||||
}
|
||||
|
||||
$columns = $this->getTargetColumns();
|
||||
|
||||
return $columns[$this->skipColumns];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the target columns
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getTargetColumns()
|
||||
{
|
||||
if (!empty($this->targetColumns)) {
|
||||
return $this->targetColumns;
|
||||
}
|
||||
|
||||
$this->targetColumns = [];
|
||||
for ($letter = 'A'; $letter <= 'ZZZ'; $letter++) {
|
||||
$this->targetColumns[] = $letter;
|
||||
}
|
||||
|
||||
return $this->targetColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the amount of columns to take
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getLimitColumns()
|
||||
{
|
||||
return $this->limitColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the target of columns to take
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTargetLimitColumns()
|
||||
{
|
||||
if (empty($this->limitColumns)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$columns = $this->getTargetColumns();
|
||||
|
||||
return $columns[$this->limitColumns -1];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1035,6 +1262,7 @@ class LaravelExcelReader
|
||||
{
|
||||
$spreadsheetInfo = $this->reader->listWorksheetInfo($this->file);
|
||||
|
||||
$index = null ;
|
||||
// Loop through the info
|
||||
foreach ($spreadsheetInfo as $key => $value) {
|
||||
// When we hit the right worksheet
|
||||
@@ -1042,6 +1270,10 @@ class LaravelExcelReader
|
||||
$index = $key;
|
||||
}
|
||||
}
|
||||
if( $index === null )
|
||||
{
|
||||
throw new LaravelExcelException('Active sheet not found (active sheet name: "'.$this->getActiveSheet()->getTitle().'")');
|
||||
}
|
||||
|
||||
// return total rows
|
||||
return $spreadsheetInfo[$index];
|
||||
@@ -1095,6 +1327,15 @@ class LaravelExcelReader
|
||||
return pathinfo($this->file, PATHINFO_FILENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the row containing the header
|
||||
* @return int
|
||||
*/
|
||||
public function getHeaderRow()
|
||||
{
|
||||
return $this->headerRow ?: config('excel.import.startRow', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the writer has the called method
|
||||
*
|
||||
@@ -1176,7 +1417,7 @@ class LaravelExcelReader
|
||||
{
|
||||
if ($this->format == 'CSV') {
|
||||
// If no encoding was given, use the config value
|
||||
$encoding = $encoding ? $encoding : Config::get('excel.import.encoding.input', 'UTF-8');
|
||||
$encoding = $encoding ? $encoding : config('excel.import.encoding.input', 'UTF-8');
|
||||
$this->reader->setInputEncoding($encoding);
|
||||
}
|
||||
|
||||
@@ -1194,35 +1435,35 @@ class LaravelExcelReader
|
||||
if ($this->format == 'CSV') {
|
||||
// If no delimiter was given, take from config
|
||||
if (!$this->delimiter) {
|
||||
$this->reader->setDelimiter(Config::get('excel.csv.delimiter', ','));
|
||||
$this->reader->setDelimiter(config('excel.csv.delimiter', ','));
|
||||
} else {
|
||||
$this->reader->setDelimiter($this->delimiter);
|
||||
}
|
||||
|
||||
if (!$this->enclosure) {
|
||||
$this->reader->setEnclosure(Config::get('excel.csv.enclosure', '"'));
|
||||
$this->reader->setEnclosure(config('excel.csv.enclosure', '"'));
|
||||
} else {
|
||||
$this->reader->setEnclosure($this->enclosure);
|
||||
}
|
||||
}
|
||||
|
||||
// Set default calculate
|
||||
$this->calculate = Config::get('excel.import.calculate', true);
|
||||
$this->calculate = config('excel.import.calculate', true);
|
||||
|
||||
// Set default for ignoring empty cells
|
||||
$this->ignoreEmpty = Config::get('excel.import.ignoreEmpty', true);
|
||||
$this->ignoreEmpty = config('excel.import.ignoreEmpty', true);
|
||||
|
||||
// Set default date format
|
||||
$this->dateFormat = Config::get('excel.import.dates.format', 'Y-m-d');
|
||||
$this->dateFormat = config('excel.import.dates.format', 'Y-m-d');
|
||||
|
||||
// Date formatting disabled/enabled
|
||||
$this->formatDates = Config::get('excel.import.dates.enabled', true);
|
||||
$this->formatDates = config('excel.import.dates.enabled', true);
|
||||
|
||||
// Set default date columns
|
||||
$this->dateColumns = Config::get('excel.import.dates.columns', []);
|
||||
$this->dateColumns = config('excel.import.dates.columns', []);
|
||||
|
||||
// Set default include charts
|
||||
$this->reader->setIncludeCharts(Config::get('excel.import.includeCharts', false));
|
||||
$this->reader->setIncludeCharts(config('excel.import.includeCharts', false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -13,7 +13,8 @@ use Maatwebsite\Excel\Classes\LaravelExcelWorksheet;
|
||||
* @author Maatwebsite <info@maatwebsite.nl>
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
*/
|
||||
class CellWriter {
|
||||
class CellWriter
|
||||
{
|
||||
|
||||
/**
|
||||
* Current $sheet
|
||||
@@ -46,14 +47,28 @@ class CellWriter {
|
||||
public function setValue($value)
|
||||
{
|
||||
// Only set cell value for single cells
|
||||
if (!str_contains($this->cells, ':'))
|
||||
{
|
||||
if (!str_contains($this->cells, ':')) {
|
||||
$this->sheet->setCellValue($this->cells, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cell url
|
||||
* @param [type] $url
|
||||
* @return CellWriter
|
||||
*/
|
||||
public function setUrl($url)
|
||||
{
|
||||
// Only set cell value for single cells
|
||||
if (!str_contains($this->cells, ':')) {
|
||||
$this->sheet->getCell($this->cells)->getHyperlink()->setUrl($url);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the background
|
||||
* @param string $color
|
||||
@@ -94,9 +109,9 @@ class CellWriter {
|
||||
*/
|
||||
public function setFontFamily($family)
|
||||
{
|
||||
return $this->setStyle('font', array(
|
||||
'name' => $family
|
||||
));
|
||||
return $this->setStyle('font', [
|
||||
'name' => $family,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,9 +121,9 @@ class CellWriter {
|
||||
*/
|
||||
public function setFontSize($size)
|
||||
{
|
||||
return $this->setStyle('font', array(
|
||||
'size' => $size
|
||||
));
|
||||
return $this->setStyle('font', [
|
||||
'size' => $size,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,9 +133,9 @@ class CellWriter {
|
||||
*/
|
||||
public function setFontWeight($bold = true)
|
||||
{
|
||||
return $this->setStyle('font', array(
|
||||
'bold' => ($bold == 'bold' || $bold) ? true : false
|
||||
));
|
||||
return $this->setStyle('font', [
|
||||
'bold' => ($bold === 'bold' || $bold === true),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,20 +149,20 @@ class CellWriter {
|
||||
public function setBorder($top = 'none', $right = 'none', $bottom = 'none', $left = 'none')
|
||||
{
|
||||
// Set the border styles
|
||||
$styles = is_array($top) ? $top : array(
|
||||
'top' => array(
|
||||
'style' => $top
|
||||
),
|
||||
'left' => array(
|
||||
$styles = is_array($top) ? $top : [
|
||||
'top' => [
|
||||
'style' => $top,
|
||||
],
|
||||
'left' => [
|
||||
'style' => $left,
|
||||
),
|
||||
'right' => array(
|
||||
],
|
||||
'right' => [
|
||||
'style' => $right,
|
||||
),
|
||||
'bottom' => array(
|
||||
],
|
||||
'bottom' => [
|
||||
'style' => $bottom,
|
||||
)
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
return $this->setStyle('borders', $styles);
|
||||
}
|
||||
@@ -159,8 +174,8 @@ class CellWriter {
|
||||
*/
|
||||
public function setTextRotation($degrees)
|
||||
{
|
||||
$style = $this->getCellStyle()->getAlignment()->setTextRotation($degrees);
|
||||
return $this;
|
||||
$style = $this->getCellStyle()->getAlignment()->setTextRotation($degrees);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,9 +185,9 @@ class CellWriter {
|
||||
*/
|
||||
public function setAlignment($alignment)
|
||||
{
|
||||
return $this->setStyle('alignment', array(
|
||||
'horizontal' => $alignment
|
||||
));
|
||||
return $this->setStyle('alignment', [
|
||||
'horizontal' => $alignment,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,9 +197,9 @@ class CellWriter {
|
||||
*/
|
||||
public function setValignment($alignment)
|
||||
{
|
||||
return $this->setStyle('alignment', array(
|
||||
'vertical' => $alignment
|
||||
));
|
||||
return $this->setStyle('alignment', [
|
||||
'vertical' => $alignment,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,8 +209,8 @@ class CellWriter {
|
||||
*/
|
||||
public function setTextIndent($indent)
|
||||
{
|
||||
$style = $this->getCellStyle()->getAlignment()->setIndent((int)$indent);
|
||||
return $this;
|
||||
$style = $this->getCellStyle()->getAlignment()->setIndent((int) $indent);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,10 +224,10 @@ class CellWriter {
|
||||
protected function setColorStyle($styleType, $color, $type = false, $colorType = 'rgb')
|
||||
{
|
||||
// Set the styles
|
||||
$styles = is_array($color) ? $color : array(
|
||||
$styles = is_array($color) ? $color : [
|
||||
'type' => $type,
|
||||
'color' => array($colorType => str_replace('#', '', $color))
|
||||
);
|
||||
'color' => [$colorType => str_replace('#', '', $color)],
|
||||
];
|
||||
|
||||
return $this->setStyle($styleType, $styles);
|
||||
}
|
||||
@@ -229,9 +244,9 @@ class CellWriter {
|
||||
$style = $this->getCellStyle();
|
||||
|
||||
// Apply style from array
|
||||
$style->applyFromArray(array(
|
||||
$styleType => $styles
|
||||
));
|
||||
$style->applyFromArray([
|
||||
$styleType => $styles,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ use Closure;
|
||||
use Carbon\Carbon;
|
||||
use PHPExcel_IOFactory;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Maatwebsite\Excel\Classes\FormatIdentifier;
|
||||
use Maatwebsite\Excel\Classes\LaravelExcelWorksheet;
|
||||
@@ -72,6 +71,22 @@ class LaravelExcelWriter {
|
||||
*/
|
||||
public $ext = 'xls';
|
||||
|
||||
/**
|
||||
* Valid file extensions.
|
||||
* @var array
|
||||
*/
|
||||
private $validExtensions = [
|
||||
'xlsx', 'xlsm', 'xltx', 'xltm', //Excel 2007
|
||||
'xls', 'xlt', //Excel5
|
||||
'ods', 'ots', //OOCalc
|
||||
'slk', //SYLK
|
||||
'xml', //Excel2003XML
|
||||
'gnumeric', //gnumeric
|
||||
'htm', 'html', //HTML
|
||||
'csv','txt' //CSV
|
||||
,'pdf' //PDF
|
||||
];
|
||||
|
||||
/**
|
||||
* Path the file will be stored to
|
||||
* @var string
|
||||
@@ -152,7 +167,7 @@ class LaravelExcelWriter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title
|
||||
* Get the filename
|
||||
* @return string
|
||||
*/
|
||||
public function getFileName()
|
||||
@@ -167,7 +182,7 @@ class LaravelExcelWriter {
|
||||
* @param array $mergeData
|
||||
* @return LaravelExcelWriter
|
||||
*/
|
||||
public function shareView($view, $data = array(), $mergeData = array())
|
||||
public function shareView($view, $data = [], $mergeData = [])
|
||||
{
|
||||
// Get the parser
|
||||
$this->getParser();
|
||||
@@ -186,7 +201,7 @@ class LaravelExcelWriter {
|
||||
*/
|
||||
public function setView()
|
||||
{
|
||||
return call_user_func_array(array($this, 'shareView'), func_get_args());
|
||||
return call_user_func_array([$this, 'shareView'], func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,7 +210,7 @@ class LaravelExcelWriter {
|
||||
*/
|
||||
public function loadView()
|
||||
{
|
||||
return call_user_func_array(array($this, 'shareView'), func_get_args());
|
||||
return call_user_func_array([$this, 'shareView'], func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,12 +235,12 @@ class LaravelExcelWriter {
|
||||
$this->sheet->setDefaultPageSetup();
|
||||
|
||||
// Do the callback
|
||||
if ($callback instanceof Closure)
|
||||
if (is_callable($callback))
|
||||
call_user_func($callback, $this->sheet);
|
||||
|
||||
// Autosize columns when no user didn't change anything about column sizing
|
||||
if (!$this->sheet->hasFixedSizeColumns())
|
||||
$this->sheet->setAutosize(Config::get('excel.export.autosize', false));
|
||||
$this->sheet->setAutosize(config('excel.export.autosize', false));
|
||||
|
||||
// Parse the sheet
|
||||
$this->sheet->parsed();
|
||||
@@ -252,21 +267,10 @@ class LaravelExcelWriter {
|
||||
* @param array $headers
|
||||
* @throws LaravelExcelException
|
||||
*/
|
||||
public function export($ext = 'xls', Array $headers = array())
|
||||
public function export($ext = 'xls', Array $headers = [])
|
||||
{
|
||||
// Set the extension
|
||||
$this->ext = $ext;
|
||||
|
||||
//Fix borders for merged cells
|
||||
foreach($this->getAllSheets() as $sheet){
|
||||
|
||||
foreach($sheet->getMergeCells() as $cells){
|
||||
|
||||
$style = $sheet->getStyle(explode(':', $cells)[0]);
|
||||
|
||||
$sheet->duplicateStyle($style, $cells);
|
||||
}
|
||||
}
|
||||
$this->ext = mb_strtolower($ext);
|
||||
|
||||
// Render the file
|
||||
$this->_render();
|
||||
@@ -275,12 +279,26 @@ class LaravelExcelWriter {
|
||||
$this->_download($headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if input file extension is valid.
|
||||
* @param $ext
|
||||
*/
|
||||
private function checkExtensionIsValid($ext)
|
||||
{
|
||||
// Check file extension is valid
|
||||
if (!in_array($ext, $this->validExtensions))
|
||||
{
|
||||
throw new \InvalidArgumentException("Invalid file extension `$ext`, expected "
|
||||
.implode(", ", $this->validExtensions).".");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert and existing file to newly requested extension
|
||||
* @param $ext
|
||||
* @param array $headers
|
||||
*/
|
||||
public function convert($ext, Array $headers = array())
|
||||
public function convert($ext, Array $headers = [])
|
||||
{
|
||||
$this->export($ext, $headers);
|
||||
}
|
||||
@@ -290,7 +308,7 @@ class LaravelExcelWriter {
|
||||
* @param string $ext
|
||||
* @param array $headers
|
||||
*/
|
||||
public function download($ext = 'xls', Array $headers = array())
|
||||
public function download($ext = 'xls', Array $headers = [])
|
||||
{
|
||||
$this->export($ext, $headers);
|
||||
}
|
||||
@@ -326,19 +344,19 @@ class LaravelExcelWriter {
|
||||
* @param array $headers
|
||||
* @throws LaravelExcelException
|
||||
*/
|
||||
protected function _download(Array $headers = array())
|
||||
protected function _download(Array $headers = [])
|
||||
{
|
||||
// Set the headers
|
||||
$this->_setHeaders(
|
||||
$headers,
|
||||
array(
|
||||
[
|
||||
'Content-Type' => $this->contentType,
|
||||
'Content-Disposition' => 'attachment; filename="' . $this->filename . '.' . $this->ext . '"',
|
||||
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT', // Date in the past
|
||||
'Last-Modified' => Carbon::now()->format('D, d M Y H:i:s'),
|
||||
'Cache-Control' => 'cache, must-revalidate',
|
||||
'Pragma' => 'public'
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
// Check if writer isset
|
||||
@@ -358,7 +376,7 @@ class LaravelExcelWriter {
|
||||
* @param string $ext
|
||||
* @param boolean $path
|
||||
* @param boolean $returnInfo
|
||||
* @return LaravelExcelWriter
|
||||
* @return LaravelExcelWriter|array
|
||||
*/
|
||||
public function store($ext = 'xls', $path = false, $returnInfo = false)
|
||||
{
|
||||
@@ -366,13 +384,13 @@ class LaravelExcelWriter {
|
||||
$this->_setStoragePath($path);
|
||||
|
||||
// Set the extension
|
||||
$this->ext = $ext;
|
||||
$this->ext = mb_strtolower($ext);
|
||||
|
||||
// Render the XLS
|
||||
$this->_render();
|
||||
|
||||
// Set the storage path and file
|
||||
$toStore = $this->storagePath . '/' . $this->filename . '.' . $this->ext;
|
||||
$toStore = $this->storagePath . DIRECTORY_SEPARATOR . $this->filename . '.' . $this->ext;
|
||||
|
||||
// Save the file to specified location
|
||||
$this->writer->save($toStore);
|
||||
@@ -381,13 +399,13 @@ class LaravelExcelWriter {
|
||||
if ($this->returnInfo($returnInfo))
|
||||
{
|
||||
// Send back information about the stored file
|
||||
return array(
|
||||
return [
|
||||
'full' => $toStore,
|
||||
'path' => $this->storagePath,
|
||||
'file' => $this->filename . '.' . $this->ext,
|
||||
'title' => $this->filename,
|
||||
'ext' => $this->ext
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Return itself
|
||||
@@ -401,7 +419,7 @@ class LaravelExcelWriter {
|
||||
*/
|
||||
public function returnInfo($returnInfo = false)
|
||||
{
|
||||
return $returnInfo ? $returnInfo : Config::get('excel.export.store.returnInfo', false);
|
||||
return $returnInfo ? $returnInfo : config('excel.export.store.returnInfo', false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -423,6 +441,28 @@ class LaravelExcelWriter {
|
||||
*/
|
||||
protected function _render()
|
||||
{
|
||||
// Preserve any existing active sheet index
|
||||
$activeIndex = $this->getExcel()->getActiveSheetIndex();
|
||||
|
||||
// getAllSheets() returns $this if no sheets were added to the excel file
|
||||
if ($this->getAllSheets() instanceof $this) {
|
||||
throw new LaravelExcelException('[ERROR] Aborting spreadsheet render: a minimum of 1 sheet is required.');
|
||||
}
|
||||
|
||||
//Fix borders for merged cells
|
||||
foreach($this->getAllSheets() as $sheet){
|
||||
|
||||
foreach($sheet->getMergeCells() as $cells){
|
||||
|
||||
$style = $sheet->getStyle(explode(':', $cells)[0]);
|
||||
|
||||
$sheet->duplicateStyle($style, $cells);
|
||||
}
|
||||
}
|
||||
|
||||
// Restore active sheet index.
|
||||
$this->setActiveSheetIndex($activeIndex);
|
||||
|
||||
// There should be enough sheets to continue rendering
|
||||
if ($this->excel->getSheetCount() < 0)
|
||||
throw new LaravelExcelException('[ERROR] Aborting spreadsheet render: no sheets were created.');
|
||||
@@ -438,7 +478,7 @@ class LaravelExcelWriter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view parser
|
||||
* Get the excel object
|
||||
* @return PHPExcel
|
||||
*/
|
||||
public function getExcel()
|
||||
@@ -467,6 +507,18 @@ class LaravelExcelWriter {
|
||||
{
|
||||
return $this->sheet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the active sheet index
|
||||
* @param integer $index
|
||||
* @return LaravelExcelWriter
|
||||
*/
|
||||
public function setActiveSheetIndex($index)
|
||||
{
|
||||
$this->sheet = $this->excel->setActiveSheetIndex($index);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attributes
|
||||
@@ -482,7 +534,7 @@ class LaravelExcelWriter {
|
||||
if ($this->excel->isChangeableProperty($setter))
|
||||
{
|
||||
// Set the properties
|
||||
call_user_func_array(array($this->excel->getProperties(), $setter), $params);
|
||||
call_user_func_array([$this->excel->getProperties(), $setter], $params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,6 +560,9 @@ class LaravelExcelWriter {
|
||||
*/
|
||||
protected function _setWriter()
|
||||
{
|
||||
// Check if input file extension is valid
|
||||
$this->checkExtensionIsValid($this->ext);
|
||||
|
||||
// Set pdf renderer
|
||||
if ($this->format == 'PDF')
|
||||
{
|
||||
@@ -520,10 +575,10 @@ class LaravelExcelWriter {
|
||||
// Set CSV delimiter
|
||||
if ($this->format == 'CSV')
|
||||
{
|
||||
$this->writer->setDelimiter(Config::get('excel.csv.delimiter', ','));
|
||||
$this->writer->setEnclosure(Config::get('excel.csv.enclosure', '"'));
|
||||
$this->writer->setLineEnding(Config::get('excel::csv.line_ending', "\r\n"));
|
||||
$this->writer->setUseBOM(Config::get('excel.csv.use_bom', false));
|
||||
$this->writer->setDelimiter(config('excel.csv.delimiter', ','));
|
||||
$this->writer->setEnclosure(config('excel.csv.enclosure', '"'));
|
||||
$this->writer->setLineEnding(config('excel.csv.line_ending', "\r\n"));
|
||||
$this->writer->setUseBOM(config('excel.csv.use_bom', false));
|
||||
}
|
||||
|
||||
// Set CSV delimiter
|
||||
@@ -533,10 +588,10 @@ class LaravelExcelWriter {
|
||||
}
|
||||
|
||||
// Calculation settings
|
||||
$this->writer->setPreCalculateFormulas(Config::get('excel.export.calculate', false));
|
||||
$this->writer->setPreCalculateFormulas(config('excel.export.calculate', false));
|
||||
|
||||
// Include Charts
|
||||
$this->writer->setIncludeCharts(Config::get('excel.export.includeCharts', false));
|
||||
$this->writer->setIncludeCharts(config('excel.export.includeCharts', false));
|
||||
|
||||
return $this->writer;
|
||||
}
|
||||
@@ -548,8 +603,8 @@ class LaravelExcelWriter {
|
||||
protected function setPdfRenderer()
|
||||
{
|
||||
// Get the driver name
|
||||
$driver = Config::get('excel.export.pdf.driver');
|
||||
$path = Config::get('excel.export.pdf.drivers.' . $driver . '.path');
|
||||
$driver = config('excel.export.pdf.driver');
|
||||
$path = config('excel.export.pdf.drivers.' . $driver . '.path');
|
||||
|
||||
// Disable autoloading for dompdf
|
||||
if(! defined("DOMPDF_ENABLE_AUTOLOAD")){
|
||||
@@ -566,7 +621,7 @@ class LaravelExcelWriter {
|
||||
* @param $headers
|
||||
* @throws LaravelExcelException
|
||||
*/
|
||||
protected function _setHeaders(Array $headers = array(), Array $default)
|
||||
protected function _setHeaders(Array $headers = [], Array $default)
|
||||
{
|
||||
if (headers_sent()) throw new LaravelExcelException('[ERROR]: Headers already sent');
|
||||
|
||||
@@ -587,10 +642,10 @@ class LaravelExcelWriter {
|
||||
protected function _setStoragePath($path = false)
|
||||
{
|
||||
// Get the default path
|
||||
$path = $path ? $path : Config::get('excel.export.store.path', storage_path($this->storagePath));
|
||||
$path = $path ? $path : config('excel.export.store.path', storage_path($this->storagePath));
|
||||
|
||||
// Trim of slashes, to makes sure we won't add them double
|
||||
$this->storagePath = rtrim($path, '/');
|
||||
$this->storagePath = rtrim($path, DIRECTORY_SEPARATOR);
|
||||
|
||||
// Make sure the storage path exists
|
||||
if (!$this->filesystem->exists($this->storagePath)) {
|
||||
@@ -632,11 +687,21 @@ class LaravelExcelWriter {
|
||||
elseif (method_exists($this->excel, $method))
|
||||
{
|
||||
// Call the method from the excel object with the given params
|
||||
$return = call_user_func_array(array($this->excel, $method), $params);
|
||||
$return = call_user_func_array([$this->excel, $method], $params);
|
||||
|
||||
return $return ? $return : $this;
|
||||
}
|
||||
|
||||
throw new LaravelExcelException('[ERROR] Writer method [' . $method . '] does not exist.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid file extensions.
|
||||
* @return array
|
||||
*/
|
||||
public function getValidExtensions()
|
||||
{
|
||||
return $this->validExtensions;
|
||||
}
|
||||
|
||||
}
|
||||
|
225
vendor/maatwebsite/excel/src/config/excel.php
vendored
225
vendor/maatwebsite/excel/src/config/excel.php
vendored
@@ -2,7 +2,7 @@
|
||||
|
||||
return array(
|
||||
|
||||
'cache' => array(
|
||||
'cache' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -29,24 +29,24 @@ return array(
|
||||
| Cache settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
|
||||
'memoryCacheSize' => '32MB',
|
||||
'cacheTime' => 600
|
||||
|
||||
),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Memcache settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'memcache' => array(
|
||||
'memcache' => [
|
||||
|
||||
'host' => 'localhost',
|
||||
'port' => 11211,
|
||||
|
||||
),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -55,9 +55,9 @@ return array(
|
||||
*/
|
||||
|
||||
'dir' => storage_path('cache')
|
||||
),
|
||||
],
|
||||
|
||||
'properties' => array(
|
||||
'properties' => [
|
||||
'creator' => 'Maatwebsite',
|
||||
'lastModifiedBy' => 'Maatwebsite',
|
||||
'title' => 'Spreadsheet',
|
||||
@@ -67,35 +67,35 @@ return array(
|
||||
'category' => 'Excel',
|
||||
'manager' => 'Maatwebsite',
|
||||
'company' => 'Maatwebsite',
|
||||
),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sheets settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'sheets' => array(
|
||||
'sheets' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default page setup
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'pageSetup' => array(
|
||||
'pageSetup' => [
|
||||
'orientation' => 'portrait',
|
||||
'paperSize' => '9',
|
||||
'scale' => '100',
|
||||
'fitToPage' => false,
|
||||
'fitToHeight' => true,
|
||||
'fitToWidth' => true,
|
||||
'columnsToRepeatAtLeft' => array('', ''),
|
||||
'rowsToRepeatAtTop' => array(0, 0),
|
||||
'columnsToRepeatAtLeft' => ['', ''],
|
||||
'rowsToRepeatAtTop' => [0, 0],
|
||||
'horizontalCentered' => false,
|
||||
'verticalCentered' => false,
|
||||
'printArea' => null,
|
||||
'firstPageNumber' => null,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -108,7 +108,7 @@ return array(
|
||||
|
||||
'creator' => 'Maatwebsite',
|
||||
|
||||
'csv' => array(
|
||||
'csv' => [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Delimiter
|
||||
@@ -143,9 +143,9 @@ return array(
|
||||
*/
|
||||
|
||||
'use_bom' => false
|
||||
),
|
||||
],
|
||||
|
||||
'export' => array(
|
||||
'export' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -218,7 +218,7 @@ return array(
|
||||
| Default sheet settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'sheets' => array(
|
||||
'sheets' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -254,7 +254,7 @@ return array(
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'strictNullComparison' => false
|
||||
),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -262,7 +262,7 @@ return array(
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'store' => array(
|
||||
'store' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -284,14 +284,14 @@ return array(
|
||||
*/
|
||||
'returnInfo' => false
|
||||
|
||||
),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| PDF Settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'pdf' => array(
|
||||
'pdf' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -306,48 +306,48 @@ return array(
|
||||
| PDF Driver settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'drivers' => array(
|
||||
'drivers' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| DomPDF settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'DomPDF' => array(
|
||||
'DomPDF' => [
|
||||
'path' => base_path('vendor/dompdf/dompdf/')
|
||||
),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| tcPDF settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'tcPDF' => array(
|
||||
'tcPDF' => [
|
||||
'path' => base_path('vendor/tecnick.com/tcpdf/')
|
||||
),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| mPDF settings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'mPDF' => array(
|
||||
'mPDF' => [
|
||||
'path' => base_path('vendor/mpdf/mpdf/')
|
||||
),
|
||||
)
|
||||
)
|
||||
),
|
||||
],
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
'filters' => array(
|
||||
'filters' => [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register read filters
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'registered' => array(
|
||||
'registered' => [
|
||||
'chunk' => 'Maatwebsite\Excel\Filters\ChunkReadFilter'
|
||||
),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -355,10 +355,10 @@ return array(
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'enabled' => array()
|
||||
),
|
||||
'enabled' => []
|
||||
],
|
||||
|
||||
'import' => array(
|
||||
'import' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -367,7 +367,7 @@ return array(
|
||||
|
|
||||
| The sheet has a heading (first) row which we can use as attribute names
|
||||
|
|
||||
| Options: true|false|slugged|slugged_with_count|ascii|numeric|hashed|trans|original
|
||||
| Options: true|false|slugged|slugged_with_count|ascii|numeric|hashed|hashed_with_lower|trans|original
|
||||
|
|
||||
*/
|
||||
|
||||
@@ -397,6 +397,19 @@ return array(
|
||||
|
||||
'separator' => '_',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Slug whitelisting
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you can whitelist certain characters in the slug.
|
||||
| E.g. user.last_name will not remove . and _
|
||||
| Note: only applies to 'heading' settings 'true' && 'slugged'
|
||||
|
|
||||
*/
|
||||
|
||||
'slug_whitelist' => '._',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Include Charts during import
|
||||
@@ -423,12 +436,12 @@ return array(
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'encoding' => array(
|
||||
'encoding' => [
|
||||
|
||||
'input' => 'UTF-8',
|
||||
'output' => 'UTF-8'
|
||||
|
||||
),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -474,7 +487,7 @@ return array(
|
||||
|
|
||||
*/
|
||||
|
||||
'dates' => array(
|
||||
'dates' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -498,15 +511,15 @@ return array(
|
||||
| Date columns
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'columns' => array()
|
||||
),
|
||||
'columns' => []
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Import sheets by config
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'sheets' => array(
|
||||
'sheets' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -517,16 +530,16 @@ return array(
|
||||
|
|
||||
*/
|
||||
|
||||
'test' => array(
|
||||
'test' => [
|
||||
|
||||
'firstname' => 'A2'
|
||||
|
||||
)
|
||||
]
|
||||
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
|
||||
'views' => array(
|
||||
'views' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -537,155 +550,155 @@ return array(
|
||||
|
|
||||
*/
|
||||
|
||||
'styles' => array(
|
||||
'styles' => [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Table headings
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'th' => array(
|
||||
'font' => array(
|
||||
'th' => [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 12,
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Strong tags
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'strong' => array(
|
||||
'font' => array(
|
||||
'strong' => [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 12,
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Bold tags
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'b' => array(
|
||||
'font' => array(
|
||||
'b' => [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 12,
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Italic tags
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'i' => array(
|
||||
'font' => array(
|
||||
'i' => [
|
||||
'font' => [
|
||||
'italic' => true,
|
||||
'size' => 12,
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Heading 1
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'h1' => array(
|
||||
'font' => array(
|
||||
'h1' => [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 24,
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Heading 2
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'h2' => array(
|
||||
'font' => array(
|
||||
'h2' => [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 18,
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Heading 2
|
||||
| Heading 3
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'h3' => array(
|
||||
'font' => array(
|
||||
'h3' => [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 13.5,
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Heading 4
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'h4' => array(
|
||||
'font' => array(
|
||||
'h4' => [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 12,
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Heading 5
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'h5' => array(
|
||||
'font' => array(
|
||||
'h5' => [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 10,
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Heading 6
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'h6' => array(
|
||||
'font' => array(
|
||||
'h6' => [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 7.5,
|
||||
)
|
||||
),
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Hyperlinks
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'a' => array(
|
||||
'font' => array(
|
||||
'a' => [
|
||||
'font' => [
|
||||
'underline' => true,
|
||||
'color' => array('argb' => 'FF0000FF'),
|
||||
)
|
||||
),
|
||||
'color' => ['argb' => 'FF0000FF'],
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Horizontal rules
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'hr' => array(
|
||||
'borders' => array(
|
||||
'bottom' => array(
|
||||
'hr' => [
|
||||
'borders' => [
|
||||
'bottom' => [
|
||||
'style' => 'thin',
|
||||
'color' => array('FF000000')
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
'color' => ['FF000000']
|
||||
],
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
)
|
||||
]
|
||||
|
||||
);
|
||||
|
Reference in New Issue
Block a user