Skip to content

Commit

Permalink
Laravel 5
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbrouwers committed Jan 30, 2015
1 parent c23b46b commit 4c9e5d3
Show file tree
Hide file tree
Showing 19 changed files with 737 additions and 767 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
## Laravel Excel v1.3.0
## Laravel Excel v2.0.0 for Laravel 5

[<img src="http://www.maatwebsite.nl/img/excel_banner.jpg"/>](http://www.maatwebsite.nl/laravel-excel/docs)

Laravel Excel brings the power of PHPOffice's PHPExcel to Laravel 4 and 5 with a touch of the Laravel Magic. It includes features like: importing Excel and CSV to collections, exporting models, array's and views to Excel, importing batches of files and importing a file by a config file.
Laravel Excel brings the power of PHPOffice's PHPExcel to Laravel 5 with a touch of the Laravel Magic. It includes features like: importing Excel and CSV to collections, exporting models, array's and views to Excel, importing batches of files and importing a file by a config file.

- Import into Laravel **Collections**
- Export **Blade views** to Excel and CSV with optional CSS styling
- **Batch** imports
- A lot of optional **config settings**
- Easy **cell caching**
- Chunked importer
- ExcelFile method injections (Laravel ~5.0)
- ExcelFile method injections
- Editing existing Excel files
- **Advanced import** by config files
- and many more...
Expand Down Expand Up @@ -41,7 +41,7 @@ Excel::create('Laravel Excel', function($excel) {
Require this package in your `composer.json` and update composer. This will download the package and PHPExcel of PHPOffice.

```php
"maatwebsite/excel": "~1.3.0"
"maatwebsite/excel": "~2.0.0"
```

After updating composer, add the ServiceProvider to the providers array in `app/config/app.php`
Expand All @@ -68,7 +68,7 @@ The complete documentation can be found at: [http://www.maatwebsite.nl/laravel-e

# Contributing

**ALL** bug fixes should be made to appropriate branch (e.g. `1.3` for 1.3.* bug fixes). Bug fixes should never be sent to the `master` branch.
**ALL** bug fixes should be made to appropriate branch (e.g. `2.0` for 2.0.* bug fixes). Bug fixes should never be sent to the `master` branch.

More about contributing can be found at: [http://www.maatwebsite.nl/laravel-excel/docs/getting-started#contributing](http://www.maatwebsite.nl/laravel-excel/docs/getting-started#contributing)

Expand Down
2 changes: 1 addition & 1 deletion src/Maatwebsite/Excel/Classes/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Cache {
* The name of the config file
* @var string
*/
private $configName = 'excel::cache';
private $configName = 'excel.cache';

/**
* Cache constructor
Expand Down
16 changes: 8 additions & 8 deletions src/Maatwebsite/Excel/Classes/LaravelExcelWorksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ public function setDefaultPageSetup()
list($setter, $set) = $this->_setSetter($setup);

// get the value
$value = Config::get('excel::sheets.pageSetup.' . $setup, null);
$value = Config::get('excel.sheets.pageSetup.' . $setup, null);

// Set the page setup value
if (!is_null($value))
call_user_func_array(array($pageSetup, $setter), array($value));
}

// Set default page margins
$this->setPageMargin(Config::get('excel::export.sheets.page_margin', false));
$this->setPageMargin(Config::get('excel.export.sheets.page_margin', false));
}

/**
Expand Down Expand Up @@ -638,7 +638,7 @@ protected function generateHeadingByIndices()
if (!$this->autoGenerateHeading)
return false;

return Config::get('excel::export.generate_heading_by_indices', false);
return Config::get('excel.export.generate_heading_by_indices', false);
}

/**
Expand Down Expand Up @@ -921,7 +921,7 @@ public function getAutosize()
if (isset($this->autoSize))
return $this->autoSize;

return Config::get('excel::export.autosize', true);
return Config::get('excel.export.autosize', true);
}

/**
Expand Down Expand Up @@ -1064,7 +1064,7 @@ public function mergeCells($pRange = 'A1:A1', $alignment = false)
// 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::get('excel.export.merged_cell_alignment', 'left');
$cell->setAlignment($aligment);
});

Expand Down Expand Up @@ -1118,7 +1118,7 @@ protected function rowToRange($rowNumber)
*/
protected function getDefaultNullValue()
{
return Config::get('excel::export.sheets.nullValue', null);
return Config::get('excel.export.sheets.nullValue', null);
}

/**
Expand All @@ -1127,7 +1127,7 @@ protected function getDefaultNullValue()
*/
protected function getDefaultStartCell()
{
return Config::get('excel::export.sheets.startCell', 'A1');
return Config::get('excel.export.sheets.startCell', 'A1');
}


Expand All @@ -1137,7 +1137,7 @@ protected function getDefaultStartCell()
*/
protected function getDefaultStrictNullComparison()
{
return Config::get('excel::export.sheets.strictNullComparison', false);
return Config::get('excel.export.sheets.strictNullComparison', false);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Maatwebsite/Excel/Classes/PHPExcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function setDefaultProperties($custom)
$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::get('excel.properties.' . $prop, null);

// set the property
call_user_func_array(array($properties, $method), array($value));
Expand Down
9 changes: 5 additions & 4 deletions src/Maatwebsite/Excel/ExcelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class ExcelServiceProvider extends ServiceProvider {

public function boot()
{
// Boot the package
$this->package('maatwebsite/excel');
$this->publishes([
__DIR__ . '/../../config/excel.php' => config_path('courier.php'),
]);

// Set the autosizing settings
$this->setAutoSizingSettings();
Expand Down Expand Up @@ -214,7 +215,7 @@ public function setLocale()
*/
public function setAutoSizingSettings()
{
$method = Config::get('excel::export.autosize-method', PHPExcel_Shared_Font::AUTOSIZE_METHOD_APPROX);
$method = Config::get('excel.export.autosize-method', PHPExcel_Shared_Font::AUTOSIZE_METHOD_APPROX);
PHPExcel_Shared_Font::setAutoSizeMethod($method);
}

Expand All @@ -224,7 +225,7 @@ public function setAutoSizingSettings()
*/
public function registerFilters()
{
$this->app['excel']->registerFilters(Config::get('excel::filters', array()));
$this->app['excel']->registerFilters(Config::get('excel.filters', array()));
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Maatwebsite/Excel/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ abstract class File {
*/
protected $file;


/**
* @param Application $app
* @param Excel $excel
Expand Down
10 changes: 5 additions & 5 deletions src/Maatwebsite/Excel/Parsers/ExcelParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ 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 = Config::get('excel.import.startRow', 1);

// Reset
$this->reset();
Expand Down Expand Up @@ -163,7 +163,7 @@ public function parseFile($columns = array())
protected function parseAsMultiple()
{
return ($this->excel->getSheetCount() > 1 && count($this->reader->getSelectedSheetIndices()) !== 1)
|| Config::get('excel::import.force_sheets_collection', false);
|| Config::get('excel.import.force_sheets_collection', false);
}

/**
Expand Down Expand Up @@ -212,7 +212,7 @@ protected function getIndices()
protected function getIndex($cell)
{
// Get heading type
$config = Config::get('excel::import.heading', true);
$config = Config::get('excel.import.heading', true);
$config = $config === true ? 'slugged' : $config;

// Get value
Expand All @@ -221,7 +221,7 @@ protected function getIndex($cell)
switch ($config)
{
case 'slugged':
return $this->getSluggedIndex($value, Config::get('excel::import.to_ascii', true));
return $this->getSluggedIndex($value, Config::get('excel.import.to_ascii', true));
break;

case 'ascii':
Expand Down Expand Up @@ -472,7 +472,7 @@ protected function getCalculatedValue()
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::get('excel.import.encoding', array('UTF-8', 'UTF-8')));

// If they are the same, return the value
if ( $input == $output )
Expand Down
2 changes: 1 addition & 1 deletion src/Maatwebsite/Excel/Readers/ConfigReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ConfigReader {
* @param string $config
* @param callback $callback
*/
public function __construct(PHPExcel $excel, $config = 'excel::import', $callback = null)
public function __construct(PHPExcel $excel, $config = 'excel.import', $callback = null)
{
// Set excel object
$this->excel = $excel;
Expand Down
9 changes: 6 additions & 3 deletions src/Maatwebsite/Excel/Readers/HtmlReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* LaravelExcel HTML reader
*
* @category Laravel Excel
* @version 1.0.0
* @version 2.0.0
* @package maatwebsite/excel
* @copyright Copyright (c) 2013 - 2014 Maatwebsite (http://www.maatwebsite.nl)
* @copyright Original Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
Expand All @@ -38,10 +38,13 @@ class Html extends PHPExcel_Reader_HTML {
*/
protected $styles = array();

protected $_dataArray = [];
protected $_nestedColumn = ['A'];

/**
* @var int
*/
private $_tableLevel = 0;
protected $_tableLevel = 0;

/**
* Input encoding
Expand Down Expand Up @@ -123,7 +126,7 @@ public function load($pFilename, $isString = false, $obj = false)
*/
protected function setStyleFormats()
{
$this->_formats = Config::get('excel::views.styles', array());
$this->_formats = Config::get('excel.views.styles', array());
}

/**
Expand Down
24 changes: 12 additions & 12 deletions src/Maatwebsite/Excel/Readers/LaravelExcelReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ public function hasHeading()
{
if (!$this->noHeading)
{
$config = Config::get('excel::import.heading', true);
$config = Config::get('excel.import.heading', true);

return $config !== false && $config !== 'numeric';
}
Expand All @@ -804,7 +804,7 @@ public function getSeparator()
if ($this->separator)
return $this->separator;

return Config::get('excel::import.separator', Config::get('excel::import.seperator', '_'));
return Config::get('excel.import.separator', Config::get('excel.import.seperator', '_'));
}

/**
Expand Down Expand Up @@ -1031,7 +1031,7 @@ protected function _setInputEncoding($encoding = false)
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::get('excel.import.encoding.input', 'UTF-8');
$this->reader->setInputEncoding($encoding);
}

Expand All @@ -1049,38 +1049,38 @@ protected function _setReaderDefaults()
{
// If no delimiter was given, take from config
if(!$this->delimiter)
$this->reader->setDelimiter(Config::get('excel::csv.delimiter', ','));
$this->reader->setDelimiter(Config::get('excel.csv.delimiter', ','));
else
$this->reader->setDelimiter($this->delimiter);

if(!$this->enclosure)
$this->reader->setEnclosure(Config::get('excel::csv.enclosure', '"'));
$this->reader->setEnclosure(Config::get('excel.csv.enclosure', '"'));
else
$this->reader->setEnclosure($this->enclosure);

if(!$this->lineEnding)
$this->reader->setLineEnding(Config::get('excel::csv.line_ending', "\r\n"));
$this->reader->setLineEnding(Config::get('excel.csv.line_ending', "\r\n"));
else
$this->reader->setLineEnding($this->lineEnding);
}

// Set default calculate
$this->calculate = Config::get('excel::import.calculate', true);
$this->calculate = Config::get('excel.import.calculate', true);

// Set default for ignoring empty cells
$this->ignoreEmpty = Config::get('excel::import.ignoreEmpty', true);
$this->ignoreEmpty = Config::get('excel.import.ignoreEmpty', true);

// Set default date format
$this->dateFormat = Config::get('excel::import.dates.format', 'Y-m-d');
$this->dateFormat = Config::get('excel.import.dates.format', 'Y-m-d');

// Date formatting disabled/enabled
$this->formatDates = Config::get('excel::import.dates.enabled', true);
$this->formatDates = Config::get('excel.import.dates.enabled', true);

// Set default date columns
$this->dateColumns = Config::get('excel::import.dates.columns', array());
$this->dateColumns = Config::get('excel.import.dates.columns', array());

// Set default include charts
$this->reader->setIncludeCharts(Config::get('excel::import.includeCharts', false));
$this->reader->setIncludeCharts(Config::get('excel.import.includeCharts', false));
}

/**
Expand Down
20 changes: 10 additions & 10 deletions src/Maatwebsite/Excel/Writers/LaravelExcelWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function sheet($title, $callback = null)

// 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::get('excel.export.autosize', false));

// Parse the sheet
$this->sheet->parsed();
Expand Down Expand Up @@ -362,7 +362,7 @@ public function store($ext = 'xls', $path = false, $returnInfo = false)
*/
public function returnInfo($returnInfo = false)
{
return $returnInfo ? $returnInfo : Config::get('excel::export.store.returnInfo', false);
return $returnInfo ? $returnInfo : Config::get('excel.export.store.returnInfo', false);
}

/**
Expand Down Expand Up @@ -479,16 +479,16 @@ protected function _setWriter()
// 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->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"));
}

// Calculation settings
$this->writer->setPreCalculateFormulas(Config::get('excel::export.calculate', false));
$this->writer->setPreCalculateFormulas(Config::get('excel.export.calculate', false));

// Include Charts
$this->writer->setIncludeCharts(Config::get('excel::export.includeCharts', false));
$this->writer->setIncludeCharts(Config::get('excel.export.includeCharts', false));

return $this->writer;
}
Expand All @@ -500,8 +500,8 @@ protected function _setWriter()
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::get('excel.export.pdf.driver');
$path = Config::get('excel.export.pdf.drivers.' . $driver . '.path');

// Disable autoloading for dompdf
define("DOMPDF_ENABLE_AUTOLOAD", false);
Expand Down Expand Up @@ -537,7 +537,7 @@ protected function _setHeaders(Array $headers = array(), Array $default)
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::get('excel.export.store.path', storage_path($this->storagePath));

// Trim of slashes, to makes sure we won't add them double
$this->storagePath = rtrim($path, '/');
Expand Down
Loading

0 comments on commit 4c9e5d3

Please sign in to comment.