composer-update-patch

This commit is contained in:
Manish Verma
2016-11-03 05:44:29 +05:30
parent 2dca47f5a4
commit 5d49d384a0
5118 changed files with 51603 additions and 122575 deletions

View File

@@ -1,22 +0,0 @@
# Contribution Guide
### Bug fixes
**ALL** bug fixes should be made to appropriate branch (e.g. `1.1` for 1.1.* bug fixes). Bug fixes should never be sent to the `master` branch.
### Pull Requests
Every pull request should pass the unit tests. If you include new functionality, make sure you include a test. Pull requests will be evaluated and possibly added to the next stable release.
### Feature Requests
If you have an idea for a new feature you would like to see added to Laravel Excel, you may create an issue on GitHub with `[PROPOSAL]` in the title. The feature request will then be reviewed by @Maatwebsite.
### Coding Guidelines
Laravel, and therefore Maatwebsite's Laravel Excel follows the [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) and [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md) coding standards. In addition to these standards, below is a list of other coding standards that should be followed:
- Namespace declarations should be on the same line as `<?php`.
- Class opening `{` should be on the same line as the class name.
- Function and control structure opening `{` should be on a separate line.
- Interface and Trait names are suffixed with `Interface` (`FooInterface`) and `Trait` (`FooTrait`) respectively.

View File

@@ -1,13 +0,0 @@
Please prefix your issue with one of the following: [BUG] [PROPOSAL] [QUESTION].
### Package version, Laravel version
### Expected behaviour
### Actual behaviour
#### Exception stack trace
#### Screenshot of Excel file
### Steps to reproduce the behaviour

View File

@@ -1,4 +0,0 @@
/vendor
composer.phar
composer.lock
.DS_Store

View File

@@ -1,17 +0,0 @@
language: php
php:
- 5.5
- 5.6
- 7
before_script:
- travis_retry composer self-update
- travis_retry composer install --prefer-source --no-interaction
script: phpunit
matrix:
allow_failures:
- php: hhvm
fast_finish: true

View File

@@ -49,23 +49,6 @@ Require this package in your `composer.json` and update composer. This will down
"maatwebsite/excel": "~2.1.0"
```
For Laravel 5.2 use you have to install the [laravelcollective/bus](https://laravelcollective.com/docs/5.2/bus#installation) package.
Add this to the `composer.json` and update composer:
```php
"laravelcollective/bus": "^5.2"
```
Then add the following lines to the `config/app.php`:
```php
'providers' => [
// ...
Collective\Bus\BusServiceProvider::class,
// ...
],
```
After updating composer, add the ServiceProvider to the providers array in `config/app.php`
```php

View File

@@ -1,3 +0,0 @@
@include:Loading a view|load-view
@include:Passing variables|vars
@include:Styling sheets|styling

View File

@@ -1,45 +0,0 @@
# @Blade to Excel
We can utilise the magic of Laravel's Blade engine to power our Excel export. Sharing a view, loading a view per sheet, creating a html table inside a view, basic CSS styling, ...
# Loading a view for a single sheet
We can load a view for every sheet we create with `->loadView()`.
Excel::create('New file', function($excel) {
$excel->sheet('New sheet', function($sheet) {
$sheet->loadView('folder.view');
});
});
# Using different views for different sheets
Excel::create('New file', function($excel) {
$excel->sheet('First sheet', function($sheet) {
$sheet->loadView('view_first');
});
$excel->sheet('Second sheet', function($sheet) {
$sheet->loadView('view_second');
});
});
# Sharing a view for all sheets
We can share a view for all sheets with `shareView()`.
Excel::shareView('folder.view')->create();
# Unsetting a view for a sheet
When we are using a shared view, but we don't want to use a view for the current sheet, we can use `->unsetView()`.
$sheet->unsetView();

View File

@@ -1,133 +0,0 @@
# Styling sheets
### General styling
If you want to change the general styling of your sheet (not cell or range specific), you can use the `->setStyle()` method or any of the other setters which can be found inside the export documentation.
// Font family
$sheet->setFontFamily('Comic Sans MS');
// Set font with ->setStyle()`
$sheet->setStyle(array(
'font' => array(
'name' => 'Calibri',
'size' => 12,
'bold' => true
)
));
### Styling with PHPExcel methods
It's possible to style the sheets and specific cells with help of PHPExcel methods. This package includes a lot of shortcuts (see export documentation), but also always the use of the native methods.
// Set background color for a specific cell
$sheet->getStyle('A1')->applyFromArray(array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => 'FF0000')
)
));
### Using HTML tags
Most of the HTML tags are supported.
<html>
<!-- Headings -->
<td><h1>Big title</h1></td>
<!-- Bold -->
<td><b>Bold cell</b></td>
<td><strong>Bold cell</strong></td>
<!-- Italic -->
<td><i>Italic cell</i></td>
<!-- Images -->
<td><img src="img.jpg" /></td>
</html>
> Inside the `view.php` config you can change how these tags will be interpreted by Excel by default.
### Using HTML attributes
Some of the basic styling can be done with HTML attributes.
<html>
<!-- Horizontal alignment -->
<td align="right">Big title</td>
<!-- Vertical alignment -->
<td valign="middle">Bold cell</td>
<!-- Rowspan -->
<td rowspan="3">Bold cell</td>
<!-- Colspan -->
<td colspan="6">Italic cell</td>
<!-- Width -->
<td width="100">Cell with width of 100</td>
<!-- Height -->
<td height="100">Cell with height of 100</td>
</html>
### Styling through inline-styles
It's possible to use inline styles inside your view files. Most of the general styles are supported.
<html>
<!-- Cell with black background -->
<td style="background-color: #000000;">Cell</td>
</html>
> Inside the reference guide you can find a list of supported styles.
### Styling through external CSS file
Styling can be done through an external CSS file.
External css file:
#cell {
background-color: #000000;
color: #ffffff;
}
.cell {
background-color: #000000;
color: #ffffff;
}
tr td {
background-color: #ffffff;
}
tr > td {
border-bottom: 1px solid #000000;
}
Table:
<html>
{{ HTML::style('css/table.css') }}
<!-- Cell styled with class -->
<td class="cell">Cell</td>
<!-- Cell styled with ID -->
<td id="cell">Cell</td>
</html>
> Inside the reference guide you can find a list of supported styles.
> It's advised to include `<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />` into the view to fix problems with UTF-8 encoding.

View File

@@ -1,19 +0,0 @@
# Passing variables to the view
### As parameter
We can pass variables to the view by using the second parameter inside the `loadView()` method.
$sheet->loadView('view', array('key' => 'value'));
### With with()
Alternatively you can use the `with()` method which works the same as with Laravel views.
// Using normal with()
$sheet->loadView('view')
->with('key', 'value');
// using dynamic with()
$sheet->loadView('view')
->withKey('value');

View File

@@ -1,14 +0,0 @@
PHPExcel_Style_Border::BORDER_NONE = 'none'
PHPExcel_Style_Border::BORDER_DASHDOT = 'dashDot'
PHPExcel_Style_Border::BORDER_DASHDOTDOT = 'dashDotDot'
PHPExcel_Style_Border::BORDER_DASHED = 'dashed'
PHPExcel_Style_Border::BORDER_DOTTED = 'dotted'
PHPExcel_Style_Border::BORDER_DOUBLE = 'double'
PHPExcel_Style_Border::BORDER_HAIR = 'hair'
PHPExcel_Style_Border::BORDER_MEDIUM = 'medium'
PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT = 'mediumDashDot'
PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT = 'mediumDashDotDot'
PHPExcel_Style_Border::BORDER_MEDIUMDASHED = 'mediumDashed'
PHPExcel_Style_Border::BORDER_SLANTDASHDOT = 'slantDashDot'
PHPExcel_Style_Border::BORDER_THICK = 'thick'
PHPExcel_Style_Border::BORDER_THIN = 'thin'

View File

@@ -1,2 +0,0 @@
@include:Version 1|version-1
@include:Version 2|version-2

View File

@@ -1,209 +0,0 @@
# Version 1
### 1.3.5
- PHPExcel 1.8.1 compatibility
- Clean-up ServiceProvider
- Fix short array syntax for PHP5.3
### 1.3.4
- Fix usage of sheet callback when modifying an existing file
- Modifying existing files improvements (support style overriding)
- Add text-indent support to HtmlReader
- Add simple sheet password protection
- Add support for exporting multiple pdf pages
- Add inline cell formatting to blade
### 1.3.3
- Fix issue with different start row in chunk filter
### 1.3.2
- Custom value binders
- Html reader update
### 1.3.1
- Fix short array syntax
### 1.3.0
- Additional headers with export()
- Float, integer, string, timestamps problems
- Cell content ending by zeros
- Images in html
- Font family bug
- Setting row number of row with headings
### 1.2.3
- PDF writer
- Include charts config
- Chunk filter with selected sheet
- Compatibility fix with new PHPExcel release
- setDateColumns fix
- Optional dependencies to require-dev
- Several bugfixes
### 1.2.2
- Chunk filter fixes
- Isset() CellCollection fixes
- PHP 5.3 support
- Missing border styles
- Add CSV settings (delimiter, enclosure, lineEnding) to ExcelFile objects
### 1.2.1
- Fix with() method parameters
### 1.2.0
- Filters
- Chunk filter (with chunked importer)
- ExcelFile (method) injections
- NewExcelFile (method) injections
- Edit existing worksheets
- Converting existing worksheet
- Laravel 4.* + 5.0 support
### 1.1.9
- PHP 5.3 fixes
### 1.1.8
- PHP 5.3 support
- fromArray bugfix
### 1.1.7
- Fix heading generation for export with `->fromArray()`
- Bugfix for non-Unix kernels
- Enhanced CSS parser (thanks to `tijsverkoyen/CssToInlineStyles`)
- Support for nested CSS styles
- Support for multiple css attributes per class
- Support for internal and external CSS files
- Support for inline style blocks (`<style>`)
### 1.1.6
- Provides.json fix
- DocBlock fixes
- Define Illuminate dependencies inside composer.json
- Better HTML rowspan handling views
- use new CellCollection() instead of ::make, to support upcoming Laravel version
- Workaround for long integers
- Add support to `wrap-text` in views
- Fix empty dates parsing
- Support local stylesheets in view parsing
- Push tr classes to td-children in views
- Support for dynamically appending rows to an empty (new) sheet
- Fix separator typo in config
### 1.1.5
- Select sheets by index with `Excel::selectSheetsByIndex(0,1)->load(...)`
- Separator typo fix
- Added `->setFileName()` method
- Use `->setTitle()` only for workbook title not for setting the filename anymore
- Made `setAutoSize()` chainable for other sheet methods
- Export config setting to disable pre calculation of formulas during export
- Export config setting to set the autosizing method (approx|exact)
- Auto sizing export from view fix
### 1.1.4
- Fix for importing 0 as null
- New unit tests
### 1.1.3
- Cell writer `->setBorder()` fix
### 1.1.2
- Fix for multiple imports on one pageload
- Multiple new import heading conversions (`Config: excel::import.heading: true|false|slugged|ascii|numeric|hashed|trans|original`)
### 1.1.1
- Retrieve workbook and sheet title during import (`->getTitle()`)
### 1.1.0
- `Limit()`, `skip()` and `take()` support for fetching results
- Set default page margins
- Export Eloquent models directly (`fromModel()`)
- Auto generate the first row (table heading) from the array keys
- Manipulate cells and cell ranges inside a closure
- Set cell backgrounds/fonts/values, ...
- Create/append/prepend new row/rows
- Manipulate row cells (background, fonts, ...)
- Config value default alignment on merge cells
- DocBlock updates to support better use of IDE autocomplete features
- Parse width and height inside views
- Parse images in views
- Optional to ASCII conversion of imported header columns (array indices)
- Config values for default null comparision and start cells for exports
- Changed default CSV enclosure to `"`
- Support for Laravel package installer
### 1.0.9
- Blade to Excel export fix for PHP5.3
### 1.0.8
- File format identifier enhancements
### 1.0.7
- Set workbook properties fix
- Extra units tests
### 1.0.6
- BatchReader fix
### 1.0.5
- Date parsing fix
### 1.0.4
- Fix calling $this in anonymous function to set locale and cache
### 1.0.3
- Table headings to attribute names undefined offset fix
- Composer.json enhancements
- Documentation fixes
### 1.0.2
- Cell Collection fixes
- Default autosizing bugfixes
- ->load() accepts input encoding parameter
- Documentation fixes
### 1.0.1
- Column width and row height bugfix
- Typo fixes
### 1.0.0
- New documentation
- More logical file structure (dividing into files, separating the different functionality (import / export)
- More optional config settings
- CSV Delimiter fixes
- CSV Encoding
- Import into collections (to support utilisation of ->first(), etc.)
- Better column selecting and result limiting
- Batch upload
- Import dates as Carbon objects by default
- Advanced file import through config coordinates
- Select sheets to import
- Create closure (Excel::create('file', function($excel) { } ))
- More logical syntax for creating new files, syntaxes of creating by array and creating with view should be as identical as possible
- Rewrite of sheet building for views
- Using closures to build sheets for normal sheet creation
- Better support for calling native PHPExcel methods
- Better use of setters
- Config setting to set default store behavior
- Column/row width
- Share views over all sheets + easy views switching per sheet
- External stylesheet with classes/ids parsing for views
- Colspan fix
- Th default styling
- Caching / Cell caching

View File

@@ -1,23 +0,0 @@
# Version 2
### 2.0.4
- PHPExcel 1.8.1 compatibility
- Clean-up ServiceProvider
### 2.0.3
- Fix usage of sheet callback when modifying an existing file
- Modifying existing files improvements (support style overriding)
- Add text-indent support to HtmlReader
- Add simple sheet password protection
- Add support for exporting multiple pdf pages
- Add inline cell formatting to blade
### 2.0.2
- Fix issue with different start row in chunk filter
### 2.0.1
- Custom value binders
- Html reader update
### 2.0.0
- Laravel 5 release

View File

@@ -1,16 +0,0 @@
@include:Creating a new file|simple
@include:Exporting|export
@include:NewExcelFile injections|injection
@include:Store to server|store
@include:Creating Sheets|sheets
@include:Creatings Sheets From array|array
@include:Row manipulation|rows
@include:Cell manipulation|cells
@include:Sheet styling|sheet-styling
@include:Freeze rows|freeze
@include:Auto filter|autofilter
@include:Cell sizing|sizing
@include:Auto size|autosize
@include:Column merging|merge
@include:Column formatting|format
@include:PHPExcel methods|call

View File

@@ -1,62 +0,0 @@
# Creating a sheet from an array
## Array
To create a new file from an array use `->fromArray($source, $nullValue, $startCell, $strictNullComparison, $headingGeneration)` inside the sheet closure.
Excel::create('Filename', function($excel) {
$excel->sheet('Sheetname', function($sheet) {
$sheet->fromArray(array(
array('data1', 'data2'),
array('data3', 'data4')
));
});
})->export('xls');
Alternatively you can use `->with()`.
$sheet->with(array(
array('data1', 'data2'),
array('data3', 'data4')
));
If you want to pass variables inside the closure, use `use($data)`
$data = array(
array('data1', 'data2'),
array('data3', 'data4')
);
Excel::create('Filename', function($excel) use($data) {
$excel->sheet('Sheetname', function($sheet) use($data) {
$sheet->fromArray($data);
});
})->export('xls');
### Null comparision
By default 0 is shown as an empty cell. If you want to change this behaviour, you can pass true as 4th parameter:
// Will show 0 as 0
$sheet->fromArray($data, null, 'A1', true);
>> To change the default behaviour, you can use `excel::export.sheets.strictNullComparison` config setting.
## Eloquent model
It's also possible to pass an Eloquent model and export it by using `->fromModel($model)`. The method accepts the same parameters as fromArray
## Auto heading generation
By default the export will use the keys of your array (or model attribute names) as first row (header column). To change this behaviour you can edit the default config setting (`excel::export.generate_heading_by_indices`) or pass `false` as 5th parameter:
// Won't auto generate heading columns
$sheet->fromArray($data, null, 'A1', false, false);

View File

@@ -1,9 +0,0 @@
# Auto filter
To enable the auto filter use `->setAutoFilter($range = false)`.
// Auto filter for entire sheet
$sheet->setAutoFilter();
// Set auto filter for a range
$sheet->setAutoFilter('A1:E10');

View File

@@ -1,16 +0,0 @@
# Auto size
By default the exported file be automatically auto sized. To change this behaviour you can either change the config or use the setters:
// Set auto size for sheet
$sheet->setAutoSize(true);
// Disable auto size for sheet
$sheet->setAutoSize(false);
// Disable auto size for columns
$sheet->setAutoSize(array(
'A', 'C'
));
> The default config setting can be found in: `export.php`.

View File

@@ -1,19 +0,0 @@
# Calling PHPExcel's native methods
It's possible to call all native PHPExcel methods on the `$excel` and `$sheet` objects.
### Calling Workbook methods
Example:
// Get default style for this workbook
$excel->getDefaultStyle();
### Calling worksheet methods
Example:
// Protect cells
$sheet->protectCells('A1', $password);
> Head over to PHPOffice to learn more about the native methods.

View File

@@ -1,63 +0,0 @@
# Cell manipulation
$sheet->cell('A1', function($cell) {
// manipulate the cell
});
$sheet->cells('A1:A5', function($cells) {
// manipulate the range of cells
});
### Set background
To change the background of a range of cells we can use `->setBackground($color, $type, $colorType)`
// Set black background
$cells->setBackground('#000000');
### Change fonts
// Set with font color
$cells->setFontColor('#ffffff');
// Set font family
$cells->setFontFamily('Calibri');
// Set font size
$cells->setFontSize(16);
// Set font weight to bold
$cells->setFontWeight('bold');
// Set font
$cells->setFont(array(
'family' => 'Calibri',
'size' => '16',
'bold' => true
));
### Set borders
// Set all borders (top, right, bottom, left)
$cells->setBorder('solid', 'none', 'none', 'solid');
// Set borders with array
$cells->setBorder(array(
'top' => array(
'style' => 'solid'
),
));
### Set horizontal alignment
// Set alignment to center
$cells->setAlignment('center');
### Set vertical alignment
// Set vertical alignment to middle
$cells->setValignment('center');

View File

@@ -1,34 +0,0 @@
# Exporting
To download the created file, use `->export($ext)` or `->download($ext)`.
#### Export to Excel5 (xls)
Excel::create('Filename', function($excel) {
})->export('xls');
// or
->download('xls');
#### Export to Excel2007 (xlsx)
->export('xlsx');
// or
->download('xlsx');
#### Export to CSV
->export('csv');
// or
->download('csv');
> You can set the default enclosure and delimiter inside the config
#### Export to PDF
To export files to pdf, you will have to include `"dompdf/dompdf": "~0.6.1"`, `"mpdf/mpdf": "~5.7.3"` or `"tecnick.com/tcpdf": "~6.0.0"` in your `composer.json` and change the `export.pdf.driver` config setting accordingly.
->export('pdf');

View File

@@ -1,23 +0,0 @@
# Column formatting
To tell Excel how it should interpret certain columns, you can use `->setColumnFormat($array)`.
// Format column as percentage
$sheet->setColumnFormat(array(
'C' => '0%'
));
// Format a range with e.g. leading zeros
$sheet->setColumnFormat(array(
'A2:K2' => '0000'
));
// Set multiple column formats
$sheet->setColumnFormat(array(
'B' => '0',
'D' => '0.00',
'F' => '@',
'F' => 'yyyy-mm-dd',
));
> Go to the reference guide to see a list of available formats.

View File

@@ -1,15 +0,0 @@
# Freeze rows
If you want to freeze a cell, row or column, use:
// Freeze first row
$sheet->freezeFirstRow();
// Freeze the first column
$sheet->freezeFirstColumn();
// Freeze the first row and column
$sheet->freezeFirstRowAndColumn();
// Set freeze
$sheet->setFreeze('A2');

View File

@@ -1,61 +0,0 @@
# NewExcelFile injections
Following the Laravel 5.0 philosophy with its new awesome FormRequest injections, we introduce you NewExcelFile injections.
## NewExcelFile class
This NewExcelFile is a wrapper for a new Excel file. Inside the `getFilename()` you can declare the wanted filename.
class UserListExport extends \Maatwebsite\Excel\Files\NewExcelFile {
public function getFilename()
{
return 'filename';
}
}
## Usage
You can inject these NewExcelFiles inside the __constructor or inside the method (when using Laravel 5.0), in e.g. the controller.
class ExampleController extends Controller {
public function exportUserList(UserListExport $export)
{
// work on the export
return $export->sheet('sheetName', function($sheet)
{
})->export('xls');
}
}
## Export Handlers
To decouple your Excel-export code completely from the controller, you can use the export handlers.
class ExampleController extends Controller {
public function exportUserList(UserListExport $export)
{
// Handle the export
$export->handleExport();
}
}
The `handleExport()` method will dynamically call a handler class which is your class name appended with `Handler`
class UserListExportHandler implements \Maatwebsite\Excel\Files\ExportHandler {
public function handle(UserListExport $export)
{
// work on the export
return $export->sheet('sheetName', function($sheet)
{
})->export('xls');
}
}

View File

@@ -1,19 +0,0 @@
# Column merging
### Merging cells
To merge a range of cells, use `->mergeCells($range)`.
$sheet->mergeCells('A1:E1');
### Merging columns and rows
To merge columns and rows, use `->setMergeColumn($array)`.
$sheet->setMergeColumn(array(
'columns' => array('A','B','C','D'),
'rows' => array(
array(2,3),
array(5,11),
)
));

View File

@@ -1,63 +0,0 @@
# Row manipulation
### Manipulate certain row
#### Change cell values
// Manipulate first row
$sheet->row(1, array(
'test1', 'test2'
));
// Manipulate 2nd row
$sheet->row(2, array(
'test3', 'test4'
));
#### Manipulate row cells
// Set black background
$sheet->row(1, function($row) {
// call cell manipulation methods
$row->setBackground('#000000');
});
### Append row
// Append row after row 2
$sheet->appendRow(2, array(
'appended', 'appended'
));
// Append row as very last
$sheet->appendRow(array(
'appended', 'appended'
));
### Prepend row
// Add before first row
$sheet->prependRow(1, array(
'prepended', 'prepended'
));
// Add as very first
$sheet->prependRow(array(
'prepended', 'prepended'
));
### Append multiple rows
// Append multiple rows
$sheet->rows(array(
array('test1', 'test2'),
array('test3', 'test4')
));
// Append multiple rows
$sheet->rows(array(
array('test5', 'test6'),
array('test7', 'test8')
));

View File

@@ -1,50 +0,0 @@
# Sheet styling
### General styling
If you want to change the general styling of your sheet (not cell or range specific), you can use the `->setStyle()` method.
// Set font with ->setStyle()`
$sheet->setStyle(array(
'font' => array(
'name' => 'Calibri',
'size' => 15,
'bold' => true
)
));
### Fonts
To change the font for the current sheet use `->setFont($array)`:
$sheet->setFont(array(
'family' => 'Calibri',
'size' => '15',
'bold' => true
));
#### Separate setters
// Font family
$sheet->setFontFamily('Comic Sans MS');
// Font size
$sheet->setFontSize(15);
// Font bold
$sheet->setFontBold(true);
### Borders
You can set borders for the sheet, by using:
// Sets all borders
$sheet->setAllBorders('thin');
// Set border for cells
$sheet->setBorder('A1', 'thin');
// Set border for range
$sheet->setBorder('A1:F10', 'thin');
> Go to the reference guide to see a list of available border styles

View File

@@ -1,77 +0,0 @@
# Sheets
### Creating a sheet
To create a new sheet inside our newly created file, use `->sheet('Sheetname')`.
Excel::create('Filename', function($excel) {
$excel->sheet('Sheetname', function($sheet) {
// Sheet manipulation
});
})->export('xls');
### Creating multiple sheets
You can set as many sheets as you like inside the file:
Excel::create('Filename', function($excel) {
// Our first sheet
$excel->sheet('First sheet', function($sheet) {
});
// Our second sheet
$excel->sheet('Second sheet', function($sheet) {
});
})->export('xls');
### Changing properties
There are a couple of properties we can change inside the closure. Most of them are set to the config values by default. See `app/config/packages/maatwebsite/excel/config.php`.
Excel::create('Filename', function($excel) {
$excel->sheet('Sheetname', function($sheet) {
$sheet->setOrientation('landscape');
});
})->export('xls');
> Go to the reference guide to see a list of available properties.
### Default page margin
It's possible to set the default page margin inside the config file `excel::export.sheets`.
It accepts boolean, single value or array.
To manually set the page margin you can use: `->setPageMargin()`
// Set top, right, bottom, left
$sheet->setPageMargin(array(
0.25, 0.30, 0.25, 0.30
));
// Set all margins
$sheet->setPageMargin(0.25);
### Password protecting a sheet
A sheet can be password protected with `$sheet->protect()`:
// Default protect
$sheet->protect('password');
// Advanced protect
$sheet->protect('password', function(\PHPExcel_Worksheet_Protection $protection) {
$protection->setSort(true);
});

View File

@@ -1,35 +0,0 @@
# Simple Excel Export
### Basics
A new file can be created using the `create` method with the filename as first parameter.
Excel::create('Filename');
To manipulate the creation of the file you can use the callback
Excel::create('Filename', function($excel) {
// Call writer methods here
});
### Changing properties
There are a couple of properties we can change inside the closure. Most of them are set to the config values by default. See `app/config/packages/maatwebsite/excel/config.php`.
Excel::create('Filename', function($excel) {
// Set the title
$excel->setTitle('Our new awesome title');
// Chain the setters
$excel->setCreator('Maatwebsite')
->setCompany('Maatwebsite');
// Call them separately
$excel->setDescription('A demonstration to change the file properties');
});
> Go to the reference guide to see a list of available properties.

View File

@@ -1,41 +0,0 @@
# Cell size
### Set column width
To set the column width use `->setWidth($cell, $width)`.
// Set width for a single column
$sheet->setWidth('A', 5);
// Set width for multiple cells
$sheet->setWidth(array(
'A' => 5,
'B' => 10
));
### Set row height
To set the row height use `->setHeight($row, $height)`.
// Set height for a single row
$sheet->setHeight(1, 50);
// Set height for multiple rows
$sheet->setHeight(array(
1 => 50,
2 => 25
));
### Set cell size
To set the cell size use `->setSize($cell, $width, $height)`.
// Set size for a single cell
$sheet->setSize('A1', 500, 50);
$sheet->setSize(array(
'A1' => array(
'width' => 50
'height' => 500,
)
));

View File

@@ -1,39 +0,0 @@
# Store on server
To store the created file on the server, use `->store($ext, $path = false, $returnInfo = false)` or `->save()`.
### Normal export to default storage path
By default the file will be stored inside the `app/storage/exports` folder, which has been defined in the `export.php` config file.
Excel::create('Filename', function($excel) {
// Set sheets
})->store('xls');
### Normal export to custom storage path
If you want to use a custom storage path (e.g. to separate the files per client), you can set the folder as the second parameter.
->store('xls', storage_path('excel/exports'));
### Store and export
->store('xls')->export('xls');
### Store and return storage info
If you want to return storage information, set the third paramter to true or change the config setting inside `export.php`.
->store('xls', false, true);
|Key|Explanation|
|---|-----------|
|**full**| Full path with filename
|**path**| Path without filename
|**file**| Filename
|**title**| File title
|**ext**| File extension
> Make sure your storage folder is **writable**!

View File

@@ -1,42 +0,0 @@
PHPExcel_Style_NumberFormat::FORMAT_GENERAL = 'General'
PHPExcel_Style_NumberFormat::FORMAT_TEXT = '@'
PHPExcel_Style_NumberFormat::FORMAT_NUMBER = '0'
PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00 = '0.00'
PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1 = '#,##0.00'
PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2 = '#,##0.00_-'
PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE = '0%'
PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00 = '0.00%'
PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2 = 'yyyy-mm-dd'
PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD = 'yy-mm-dd'
PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY = 'dd/mm/yy'
PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH = 'd/m/y'
PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYMINUS = 'd-m-y'
PHPExcel_Style_NumberFormat::FORMAT_DATE_DMMINUS = 'd-m'
PHPExcel_Style_NumberFormat::FORMAT_DATE_MYMINUS = 'm-y'
PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14 = 'mm-dd-yy'
PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15 = 'd-mmm-yy'
PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16 = 'd-mmm'
PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17 = 'mmm-yy'
PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22 = 'm/d/yy h:mm'
PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME = 'd/m/y h:mm'
PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME1 = 'h:mm AM/PM'
PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME2 = 'h:mm:ss AM/PM'
PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3 = 'h:mm'
PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4 = 'h:mm:ss'
PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME5 = 'mm:ss'
PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME6 = 'h:mm:ss'
PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME7 = 'i:s.S'
PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME8 = 'h:mm:ss;@'
PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH = 'yy/mm/dd;@'
PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE = '"$"#,##0.00_-'
PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD = '$#,##0_-'
PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE = '[$EUR ]#,##0.00_-'
->setColumnFormat(array(
'B' => '0',
'D' => '0.00',
'F' => '@',
'F' => 'yyyy-mm-dd',
......
)
)

View File

@@ -1,5 +0,0 @@
@include:Installation|installation
@include:Config|config
@include:Requirements|requirements
@include:Contributing|contributing
@include:License|license

View File

@@ -1,18 +0,0 @@
#Config
### Laravel 4
Laravel Excel includes several config settings for import-, export-, view- and CSV-specific settings.
Use the artisan publish command to publish the config file to your project.
php artisan config:publish maatwebsite/excel
The config files can now be found at `app/config/packages/maatwebsite/excel`
### Laravel 5
To publish the config settings in Laravel 5 use:
php artisan vendor:publish
This will add an `excel.php` config file to your config folder.

View File

@@ -1,22 +0,0 @@
# Contribution Guide
### Bug fixes
**ALL** bug fixes should be made to appropriate branch (e.g. `1.1` for 1.1.* bug fixes). Bug fixes should never be sent to the `master` branch.
### Pull Requests
Every pull request should pass the unit tests. If you include new functionality, make sure you include a test. Pull requests will be evaluated and possibly added to the next stable release.
### Feature Requests
If you have an idea for a new feature you would like to see added to Laravel Excel, you may create an issue on GitHub with `[Request]` in the title. The feature request will then be reviewed by @Maatwebsite.
### Coding Guidelines
Laravel, and therefore Maatwebsite's Laravel Excel follows the [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) and [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md) coding standards. In addition to these standards, below is a list of other coding standards that should be followed:
- Namespace declarations should be on the same line as `<?php`.
- Class opening `{` should be on the same line as the class name.
- Function and control structure opening `{` should be on a separate line.
- Interface and Trait names are suffixed with `Interface` (`FooInterface`) and `Trait` (`FooTrait`) respectively.

View File

@@ -1,23 +0,0 @@
#Installation
Require this package in your `composer.json` and update composer. This will download the package and PHPExcel of PHPOffice.
#### Laravel 4
"maatwebsite/excel": "~1.3"
#### Laravel 5
"maatwebsite/excel": "~2.1.0"
After updating composer, add the ServiceProvider to the providers array in `app/config/app.php`
'Maatwebsite\Excel\ExcelServiceProvider',
You can use the facade for shorter code. Add this to your aliasses:
'Excel' => 'Maatwebsite\Excel\Facades\Excel',
The class is binded to the ioC as `excel`
$excel = App::make('excel');

View File

@@ -1,3 +0,0 @@
#License
This package is licensed under LGPL. You are free to use it in personal and commercial projects. The code can be forked and modified, but the original copyright author should always be included!

View File

@@ -1,8 +0,0 @@
# Requirements
- PHP version >= 5.3.7
- Laravel >= 4.1
- PHPOffice PHPExcel >= 1.8.0 (included by composer.json)
- PHP extension php_zip enabled (required if you need PHPExcel to handle .xlsx .ods or .gnumeric files)
- PHP extension php_xml enabled
- PHP extension php_gd2 enabled (optional, but required for exact column width autocalculation)

View File

@@ -1,14 +0,0 @@
@include:Importing a file|basics
@include:ExcelFile injections|injection
@include:Handling results|results
@include:Selecting sheets and columns|select
@include:Dates|dates
@include:Calculation|calculation
@include:Custom formatting values|formatting
@include:Caching and cell caching|cache
@include:Chunk importing|chunk
@include:Batch import|batch
@include:Import by config|config
@include:Edit existing files|edit
@include:Converting|convert
@include:Extra|extra

View File

@@ -1,9 +0,0 @@
# Importing a file
To start importing a file, you can use `->load($filename)`. The callback is optional.
Excel::load('file.xls', function($reader) {
// reader methods
});

View File

@@ -1,43 +0,0 @@
#Batch import
### Import a folder
To import an entire folder (only xls, xlsx and csv files will be imported), set the folder as the first parameter.
Excel::batch('app/storage/uploads', function($rows, $file) {
// Explain the reader how it should interpret each row,
// for every file inside the batch
$rows->each(function($row) {
// Example: dump the firstname
dd($row->firstname);
});
});
### Import multiple files
It's also possible to provide an array of files to import.
$files = array(
'file1.xls',
'file2.xls'
);
Excel::batch($files, function($rows, $file) {
});
### Import a folder and multiple sheets
When your files contain multiple sheets, you should also loop the sheets
Excel::batch('app/storage/uploads', function($sheets, $file) {
$sheets->each(function($sheet) {
});
});

View File

@@ -1,12 +0,0 @@
# Caching and Cell caching
### Cell caching
You can enable cell caching inside the config `cache.php`. You can choose between a couple of drivers and change a couple of settings. By default the caching is **enabled** and will use **in memory** caching.
### Remembering results
If you want to remember the results you can use `->remember($minutes)`. Next time you will load the same file (if it's still inside the cache), it will return the cached results.
// Remember for 10 minutes
$results = $reader->remember(10)->get();

View File

@@ -1,11 +0,0 @@
# Calculate formulas
By default formulas inside the file are being calculated and it's result will be returned. Inside `import.php` config you can change the default behaviour by setting `calculate` to the desired preference.
If you want to enable/disable it for a single import, you can use `->calculate($boolean)`
// Enable calculation
$reader->calculate();
// Disable calculation
$reader->calculate(false);

View File

@@ -1,49 +0,0 @@
# Chunk importer
When dealing with big files, it's better to import the data in big chunks. You can enable this with `filter('chunk')`;
To import it into chunks you can use `chunk($size, $callback)` instead of the normal `get()`. The first parameter is the size of the chunk. The second parameter is a closure which will return the results.
Excel::filter('chunk')->load('file.csv')->chunk(250, function($results)
{
foreach($results as $row)
{
// do stuff
}
});
## ExcelFile class example:
When working with ExcelFile injections (in the constructor or as method injection), you can enable the chunk filter inside the ExcelFile class
class UserListImport extends \Maatwebsite\Excel\Files\ExcelFile {
public function getFile()
{
return 'file.csv';
}
public function getFilters()
{
return [
'chunk'
];
}
}
Injected ExcelFile example:
public function importUserList(UserListImport $import)
{
$import->chunk(250, function($results)
{
// do stuff
// or return true if you want to stop importing.
});
}
## Queued chunks
We automatically queue every chunk for you, if you have enabled the queue driver in your config.
If you want to by-pass the behaviour, you can pass `false` as third param of `chunk($size, $callback, $shouldQueue)`.

View File

@@ -1,15 +0,0 @@
# Import by Config
When using advanced Excel files (e.g. without any heading columns), it can be complicated to import these.
`->byConfig()` will help you handle this problem.
Inside `excel::import.sheets` config you can find an example.
Excel::load('file.xls')->byConfig('excel::import.sheets', function($sheet) {
// The firstname getter will correspond with a cell coordinate set inside the config
$firstname = $sheet->firstname;
});
> **Note:** if you are using multiple sheets. `->byConfig` will loop through all sheets. If these getters are only exist on one sheet, you can always use `->selectSheets()`.

View File

@@ -1,9 +0,0 @@
# Converting
You can convert from one filetype to another by using `->convert()`
Excel::load('file.csv', function($file) {
// modify stuff
})->convert('xls');

View File

@@ -1,45 +0,0 @@
# Dates
By default the dates will be parsed as a **[Carbon object](https://github.com/briannesbitt/Carbon)**. You can disable date formatting completly inside `import.php` by setting `dates.enabled` to `false`.
To enable/disable date formatting for a single import, use `->formatDates($boolean, $format)`
// Format the dates
$reader->formatDates(true);
// Disable date formatting
$reader->formatDates(false);
// Format dates + set date format
$reader->formatDates(true, 'Y-m-d');
### Format dates
By default the dates are **not formatted**, but returned as a Carbon object. There are a couple of options to format them.
#### Formatting results after ->get()
Inside your loop you can utilise the Carbon method `->format($dateFormat)`
$rows->each(function($row) {
$created_at = $row->created_at->format('Y-m-d');
});
#### Setting a default date format
Inside the config you can set a default date format. A Carbon object will no longer be returned.
Or you can use `->setDateFormat()`
$reader->setDateFormat('Y-m-d');
### Setting custom date columns
Cells which are not Excel formatted dates will not be parsed as a date. To force this behaviour (or to use this with CSV imports), you can set these date columns manually: `->setDateColumns()`
$reader->setDateColumns(array(
'created_at',
'deleted_at'
))->get();

View File

@@ -1,9 +0,0 @@
# Editing existing files
You can edit existing Excel files, by loading them and after modification exporting them.
Excel::load('file.csv', function($file) {
// modify stuff
})->export('csv');

View File

@@ -1,44 +0,0 @@
# Extra
### Disable using first row as collection attributes
By default we will use the first row of a file as table heading (so as attribute names for the collection).
You can change the default behaviour inside `import.php` with `import.heading`.
To disable this for a single import, use `->noHeading()`.
$reader->noHeading();
### Setting the cell name separator
By default collection attribute names will be set by looking at the first row columns. Spaces will be translated to `_`.
**E.g. Created at -> created_at**
The default behaviour can be changed inside the `import.php` config by changing `'separator'`. Or you can use `->setSeparator($separator)`.
$reader->setSeparator('-');
### Ignoring empty cells
By default empty cells will not be ignored and presented as null inside the cell collection.
To change the default behaviour, you can change `'ignoreEmpty`' inside `import.php` or use `->ignoreEmpty()`.
$reader->ignoreEmpty();
### Input encoding
Inside the `import.php` config you can change the input encoding. In most cases **UTF-8** will be the best solution. Hower if you dump your results make sure your HTML page has this exact same meta charset!
Optionally you can pass the input encoding inside the `->load()` method.
// When utilising a closure, you can pass the input encoding as third parameter.
Excel::load('filename.csv', function($reader) {
}, 'UTF-8');
// or without a closure, you can use it as second parameter.
Excel::load('filename.csv', 'UTF-8');
### CSV Settings
Inside the `csv.php` config you can change the default settings, like the `delimiter`, the `enclosure` and the `line_ending`.

View File

@@ -1,38 +0,0 @@
# Custom formatting values
By default Laravel Excel uses PHPExcel's default value binder to intelligently format a cells value when reading it. You may override this behavior by passing in your own value binder to suit your specific needs. Value binders must implement PHPExcel_Cell_IValueBinder and have a bindValue method. They may also extend PHPExcel_Cell_DefaultValueBinder to return the default behavior.
use PHPExcel_Cell;
use PHPExcel_Cell_DataType;
use PHPExcel_Cell_IValueBinder;
use PHPExcel_Cell_DefaultValueBinder;
class MyValueBinder extends PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
{
public function bindValue(PHPExcel_Cell $cell, $value = null)
{
if (is_numeric($value))
{
$cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_NUMERIC);
return true;
}
// else return default behavior
return parent::bindValue($cell, $value);
}
}
$myValueBinder = new MyValueBinder;
Excel::setValueBinder($myValueBinder)->load('file.xls', function($reader) {
// reader methods
});
Available PHPExcel_Cell_DataType's are TYPE_STRING, TYPE_FORMULA, TYPE_NUMERIC, TYPE_BOOL, TYPE_NULL, TYPE_INLINE and TYPE_ERROR
To reset the value binder back to default and/or before calling Laravel Excel after setting a custom value binder you need to call the resetValueBinder method.
Excel::resetValueBinder();

View File

@@ -1,87 +0,0 @@
# ExcelFile injections
Following the Laravel 5.0 philosophy with its new awesome FormRequest injections, we introduce you ExcelFile injections.
## ExcelFile class
This class is a wrapper for a file on your server. Inside the `getFile()` method you return the filename and it's location. Inside the `getFilters()` method you can enable filters, like the chunk filter.
class UserListImport extends \Maatwebsite\Excel\Files\ExcelFile {
public function getFile()
{
return storage_path('exports') . '/file.csv';
}
public function getFilters()
{
return [
'chunk'
];
}
}
If you want to have the `getFile()` dynamic based on user's input, you can easily do:
public function getFile()
{
// Import a user provided file
$file = Input::file('report');
$filename = $this->doSomethingLikeUpload($file);
// Return it's location
return $filename;
}
## Usage
You can inject these ExcelFiles inside the __constructor or inside the method (when using Laravel 5.0), in e.g. the controller.
class ExampleController extends Controller {
public function importUserList(UserListImport $import)
{
// get the results
$results = $import->get();
}
}
## CSV Settings
You can pass through optional CSV settings, like `$delimiter`, `$enclosure` and `$lineEnding` as protected properties of the class.
class UserListImport extends \Maatwebsite\Excel\Files\ExcelFile {
protected $delimiter = ',';
protected $enclosure = '"';
protected $lineEnding = '\r\n';
}
## Import Handlers
To decouple your Excel-import code completely from the controller, you can use the import handlers.
class ExampleController extends Controller {
public function importUserList(UserListImport $import)
{
// Handle the import
$import->handleImport();
}
}
The `handleImport()` method will dynamically call a handler class which is your class name appended with `Handler`
class UserListImportHandler implements \Maatwebsite\Excel\Files\ImportHandler {
public function handle(UserListImport $import)
{
// get the results
$results = $import->get();
}
}

View File

@@ -1,126 +0,0 @@
# Handling imported results
### Getting all sheets and rows
After you have loaded a file, you can `->get()` the results like so:
Excel::load('file.xls', function($reader) {
})->get();
or
Excel::load('file.xls', function($reader) {
// Getting all results
$results = $reader->get();
// ->all() is a wrapper for ->get() and will work the same
$results = $reader->all();
});
> The `->get()` and `->all()` methods will return a sheet or row collection, depending on the amount of sheets the file has. You can disable this feature inside the `import.php` config by setting `'force_sheets_collection'` to `true`. When set to true it will always return a sheet collection.
### Table heading as attributes
By default the first row of the excel file will be used as attributes.
// Get the firstname
$row->firstname;
> **Note**: by default these attributes will be converted to a slug. You can change the default inside the config `excel::import.heading`. Available options are: `true|false|slugged|ascii|numeric|hashed|trans|original`
> True and slugged will be converted to ASCII as well when `excel::import.to_ascii` is set to true. You can change the default separator as well inside the config.
### Collections
Sheets, rows and cells are collections, this means after doing a `->get()` you can use all default collection methods.
// E.g. group the results
$reader->get()->groupBy('firstname');
### Getting the first sheet or row
To get the first sheet or row, you can utilise `->first()`.
$reader->first();
> **Note:** depending on the config `'force_sheets_collection'` it will return the first row or sheet.
### Workbook and sheet title
It's possible to retrieve the workbook and sheet title with `->getTitle()`.
// Get workbook title
$workbookTitle = $reader->getTitle();
foreach($reader as $sheet)
{
// get sheet title
$sheetTitle = $sheet->getTitle();
}
### Limiting the results
##### Taking rows
When you only want to return the first x rows of a sheet, you can use `->take()` or `->limit()`.
// You can either use ->take()
$reader->take(10);
// Or ->limit()
$reader->limit(10);
##### Skipping rows
When you want to skip a certain amount of rows you can use `->skip()` or `->limit(false, 10)`
// Skip 10 results
$reader->skip(10);
// Skip 10 results with limit, but return all other rows
$reader->limit(false, 10);
// Skip and take
$reader->skip(10)->take(10);
// Limit with skip and take
$reader->($skip, $take);
### Result mutators
When you want to get an array instead of an object, you can use `->toArray()`.
$reader->toArray();
When you want an object, you can alternativly (instead of get() or all()) use `->toObject()`.
$reader->toObject();
### Displaying results
You can dump the results to a readable output by using `->dump()` or `->dd()`.
// Dump the results
$reader->dump();
// Dump results and die
$reader->dd();
### Iterating the results
You can iterate the results by using `->each()`.
// Loop through all sheets
$reader->each(function($sheet) {
// Loop through all rows
$sheet->each(function($row) {
});
});
> Alternatively you can also `foreach` the results.

View File

@@ -1,31 +0,0 @@
# Selecting sheets and columns
### Selecting one specific sheet
If you want to select a single sheet, you can use `->selectSheets($name)`. Only that sheet will be loaded.
Excel::selectSheets('sheet1')->load();
### Selecting multiple sheets
If you want to select multiple sheets inside your file, you can pass an array as the parameter;
Excel::selectSheets('sheet1', 'sheet2')->load();
### Selecting sheets by index
// First sheet
Excel::selectSheetsByIndex(0)->load();
// First and second sheet
Excel::selectSheetsByIndex(0, 1)->load();
### Selecting columns
If you want to select only a couple of columns, you can use `->select($columns)` or pass an array as the first parameter of `->get($columns)`.
// Select
$reader->select(array('firstname', 'lastname'))->get();
// Or
$reader->get(array('firstname', 'lastname'));
> All get methods (like all(), first(), dump(), toArray(), ...) accept an array of columns.

View File

@@ -1,8 +0,0 @@
$mergeColumn = array(
* 'columns' => array('A','B','C','D'),
* 'rows' => array(
* array(2,3),
* array(5,11),
* .....
* )
* );

View File

@@ -1,6 +0,0 @@
@include:Available file properties|file-properties
@include:Available sheet properties|sheet-properties
@include:Available CSS styles|css-styles
@include:Available border styles|borders
@include:Available column formatting|formatting
@include:Closures|closures

View File

@@ -1,18 +0,0 @@
# Available border styles
| Style name | PHPExcel class reference|
| ------------- |-----------------|
|none|PHPExcel_Style_Border::BORDER_NONE
|dashDot|PHPExcel_Style_Border::BORDER_DASHDOT
| dashDotDot|PHPExcel_Style_Border::BORDER_DASHDOTDOT
| dashed |PHPExcel_Style_Border::BORDER_DASHED
| dotted |PHPExcel_Style_Border::BORDER_DOTTED
| double |PHPExcel_Style_Border::BORDER_DOUBLE
| hair |PHPExcel_Style_Border::BORDER_HAIR
| medium |PHPExcel_Style_Border::BORDER_MEDIUM
| mediumDashDot |PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT
| mediumDashDotDot |PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT
| mediumDashed |PHPExcel_Style_Border::BORDER_MEDIUMDASHED
| slantDashDot |PHPExcel_Style_Border::BORDER_SLANTDASHDOT
| thick|PHPExcel_Style_Border::BORDER_THICK
| thin|PHPExcel_Style_Border::BORDER_THIN

View File

@@ -1,10 +0,0 @@
# Closures
| Method | Closure class |
| ------------- |-------------|
| create() | Maatwebsite\Excel\Writers\LaravelExcelWriter |
| load() | Maatwebsite\Excel\Readers\LaravelExcelReader |
| batch | Maatwebsite\Excel\Readers\Batch |
| sheet() | Maatwebsite\Excel\Classes\LaravelExcelWorksheet |
| cells() | Maatwebsite\Excel\Writers\CellWriter |
| row() | Maatwebsite\Excel\Writers\CellWriter |

View File

@@ -1,19 +0,0 @@
# Available CSS styles
Styles that can be used inside an external CSS file or as inline CSS.
| Style name | Example Value |
| ------------- |-------------|
| background(-color) | #000000 |
| color | #FFFFFF |
| font-weight | bold |
| font-style | italic |
| font-weight | bold |
| font-size | 20px |
| font-family | Open Sans |
| text-decoration | underline |
| text-align | center |
| vertical-align | middle |
| border(-*) | 1px dashed #CCC |
| width | 100(px) |
| height | 1100(px) |

View File

@@ -1,15 +0,0 @@
# Available file properties
Properties that can be set with `$excel->set{$property}()`
| Property name |
| ------------- |
|creator
|lastModifiedBy
|title
|description
|subject
|keywords
|category
|manager
|company

View File

@@ -1,37 +0,0 @@
# Available column formatting
| Format name | PHPExcel class reference|
| ------------- |-----------------|
|General|PHPExcel_Style_NumberFormat::FORMAT_GENERAL
|@|PHPExcel_Style_NumberFormat::FORMAT_TEXT
|0|PHPExcel_Style_NumberFormat::FORMAT_NUMBER
|0.00|PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00
|#,##0.00|PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1
|#,##0.00_-|PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2
|0%|PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE
|0.00%|PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00
|yyyy-mm-dd|PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2
|yy-mm-dd|PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD
|dd/mm/yy|PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY
|d/m/y|PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH
|d-m-y|PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYMINUS
|d-m|PHPExcel_Style_NumberFormat::FORMAT_DATE_DMMINUS
|m-y|PHPExcel_Style_NumberFormat::FORMAT_DATE_MYMINUS
|mm-dd-yy|PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14
|d-mmm-yy|PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15
|d-mmm|PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16
|mmm-yy|PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17
|m/d/yy h:mm|PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22
|d/m/y h:mm|PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME
|h:mm AM/PM|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME1
|h:mm:ss AM/PM|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME2
|h:mm|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3
|h:mm:ss|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4
|mm:ss|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME5
|h:mm:ss|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME6
|i:s.S|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME7
|h:mm:ss;@|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME8
|yy/mm/dd;@|PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH
|"$"#,##0.00_-|PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE
|$#,##0_-|PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD
|[$EUR ]#,##0.00_-|PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE

View File

@@ -1,18 +0,0 @@
# Available sheet properties
Properties that can be set with `$sheet->set{$property}()`
| Property name | Possible value|
| ------------- |-----------------|
|orientation| string
|paperSize| integer
|scale| integer
|fitToPage| boolean
|fitToHeight| boolean
|fitToWidth| boolean
|columnsToRepeatAtLeft| array
|rowsToRepeatAtTop| array
|horizontalCentered| boolean
|verticalCentered| boolean
|printArea| range
|firstPageNumber| integer

View File

@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
</php>
</phpunit>

View File

@@ -186,6 +186,8 @@ class ExcelServiceProvider extends ServiceProvider {
return $excel;
});
$this->app->alias('phpexcel', PHPExcel::class);
}
/**

View File

@@ -1,53 +0,0 @@
<?php
use Maatwebsite\Excel\Collections\CellCollection;
class CellCollectionTest extends TestCase {
public function __construct()
{
$this->collection = new CellCollection([
'one' => 'one',
'two' => 'two'
]);
}
public function testSetItems()
{
$this->collection->setItems([
'three' => 'three'
]);
$this->assertContains('three', $this->collection);
$this->assertCount(3, $this->collection);
}
public function testDynamicGetters()
{
$this->assertEquals('two', $this->collection->two);
}
public function testIsset()
{
$this->assertTrue(isset($this->collection->two));
$this->assertFalse(isset($this->collection->nonexisting));
}
public function testEmpty()
{
$this->assertFalse(empty($this->collection->two));
$this->assertTrue(empty($this->collection->nonexisting));
}
public function testDynamicCheck()
{
$this->assertTrue($this->collection->two ? true : false);
$this->assertFalse($this->collection->nonexisting ? true : false);
}
}

View File

@@ -1,111 +0,0 @@
<?php
use Mockery as m;
use Maatwebsite\Excel\Excel;
use Illuminate\Filesystem\Filesystem;
class ExcelTestCase extends PHPUnit_Framework_TestCase {
/**
* Mocks
* @var [type]
*/
public $phpexcel;
public $reader;
public $writer;
public $excel;
public $batch;
/**
* Setup test case
*/
public function setUp()
{
parent::setUp();
// Set the mocks
$this->setMocks();
// Init our excel class
$this->excel = new Excel($this->phpexcel, $this->reader, $this->writer);
}
/**
* Test the constructor
* @return [type] [description]
*/
public function testConstructor()
{
$this->assertInstanceOf('Maatwebsite\Excel\Excel', $this->excel);
}
/**
* Set the mocks
*/
public function setMocks()
{
$this->mockPHPExcel();
$this->mockReader();
$this->mockWriter();
$this->mockBatch();
}
/**
* Mock PHPExcel class
* @return [type] [description]
*/
public function mockPHPExcel()
{
$this->phpexcel = m::mock('Maatwebsite\Excel\Classes\PHPExcel');
$this->phpexcel->shouldReceive('getID');
$this->phpexcel->shouldReceive('disconnectWorksheets');
$this->phpexcel->shouldReceive('setDefaultProperties');
}
/**
* Mock Reader class
* @return [type] [description]
*/
public function mockReader()
{
$this->reader = m::mock('Maatwebsite\Excel\Readers\LaravelExcelReader');
$this->reader->shouldReceive('injectExcel')->with($this->phpexcel);
$this->reader->shouldReceive('load');
$this->reader->shouldReceive('setSelectedSheets');
$this->reader->shouldReceive('setSelectedSheetIndices');
$this->reader->shouldReceive('setFilters');
}
/**
* Mock Writer class
* @return [type] [description]
*/
public function mockWriter()
{
$this->writer = m::mock('Maatwebsite\Excel\Writers\LaravelExcelWriter');
$this->writer->shouldReceive('injectExcel')->with($this->phpexcel);
$this->writer->shouldReceive('setTitle');
$this->writer->shouldReceive('setFileName');
$this->writer->shouldReceive('shareView')->andReturn($this->writer);
}
/**
* Mock Writer class
* @return [type] [description]
*/
public function mockBatch()
{
$this->batch = m::mock('Maatwebsite\Excel\Readers\Batch');
$this->batch->shouldReceive('start')->andReturn('foo');
}
/**
* Teardown
* @return [type] [description]
*/
public function tearDown()
{
m::close();
}
}

View File

@@ -1,46 +0,0 @@
<?php
use Mockery as m;
class ExcelTester extends ExcelTestCase {
/**
* Test select sheets
* @return
*/
public function testSelectSheets()
{
$selected = $this->excel->selectSheets(array('sheet'));
$this->assertEquals($this->excel, $selected);
}
/**
* Test select sheets
* @return
*/
public function testSelectSheetsByIndex()
{
$selected = $this->excel->selectSheetsByIndex(array('0'));
$this->assertEquals($this->excel, $selected);
}
/**
* Test the share view
* @return
*/
public function testShareView()
{
$selected = $this->excel->shareView('filename', array('test'), array('test'));
$this->assertEquals($this->writer, $selected);
}
/**
* Test load view
* @return
*/
public function testLoadView()
{
$selected = $this->excel->loadView('filename', array('test'), array('test'));
$this->assertEquals($this->writer, $selected);
}
}

View File

@@ -1,24 +0,0 @@
<?php
include_once 'classes/CsvTestImport.php';
class CsvExcelFileTest extends TestCase {
public function testInit()
{
$importer = app('CsvTestImport');
$this->assertInstanceOf('Maatwebsite\Excel\Files\ExcelFile', $importer);
}
public function testGetResultsDirectlyWithCustomDelimiterSetAsProperty()
{
$importer = app('TestImport');
$results = $importer->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $results);
$this->assertCount(5, $results);
}
}

View File

@@ -1,70 +0,0 @@
<?php
include_once 'classes/TestImport.php';
include_once 'classes/TestImportHandler.php';
include_once 'classes/TestFile.php';
include_once 'classes/TestFileHandler.php';
class ExcelFileTest extends TestCase {
public function testInit()
{
$importer = app('TestImport');
$this->assertInstanceOf('Maatwebsite\Excel\Files\ExcelFile', $importer);
}
public function testGetFile()
{
$importer = app('TestImport');
$file = $importer->getFile();
$exploded = explode('/',$file);
$filename = end($exploded);
$this->assertEquals('test.csv', $filename);
}
public function testGetFilters()
{
$importer = app('TestImport');
$this->assertContains('chunk', $importer->getFilters());
$this->assertContains('chunk', $importer->getFileInstance()->filters['enabled']);
}
public function testLoadFile()
{
$importer = app('TestImport');
$importer->loadFile();
$this->assertInstanceOf('Maatwebsite\Excel\Readers\LaravelExcelReader', $importer->getFileInstance());
}
public function testGetResultsDirectly()
{
$importer = app('TestImport');
$results = $importer->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $results);
$this->assertCount(5, $results);
}
public function testImportHandler()
{
$importer = app('TestImport');
$results = $importer->handleImport();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $results);
$this->assertCount(5, $results);
$importer = app('TestFile');
$results = $importer->handleImport();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $results);
$this->assertCount(5, $results);
}
}

View File

@@ -1,55 +0,0 @@
<?php
include_once 'classes/TestExport.php';
include_once 'classes/TestExportHandler.php';
include_once 'classes/TestNewFile.php';
include_once 'classes/TestNewFileHandler.php';
class NewExcelFileTest extends TestCase {
public function testInit()
{
$exporter = app('TestExport');
$this->assertInstanceOf('Maatwebsite\Excel\Files\NewExcelFile', $exporter);
}
public function testGetFilename()
{
$exporter = app('TestExport');
$this->assertEquals('test-file', $exporter->getFilename());
}
public function testCreateNewFile()
{
$exporter = app('TestExport');
$exporter->createNewFile();
$this->assertInstanceOf('Maatwebsite\Excel\Writers\LaravelExcelWriter', $exporter->getFileInstance());
}
public function testDirectUsage()
{
$exporter = app('TestExport');
$exporter->setTitle('New title');
$this->assertEquals('New title', $exporter->getFileInstance()->getTitle());
}
public function testExportHandler()
{
$exporter = app('TestExport');
$result = $exporter->handleExport();
$this->assertEquals('exported', $result);
$exporter = app('TestNewFile');
$result = $exporter->handleExport();
$this->assertEquals('exported', $result);
}
}

View File

@@ -1,21 +0,0 @@
<?php
use Maatwebsite\Excel\Files\ExcelFile;
class CsvTestImport extends ExcelFile {
/**
* Custom delimiter
* @var string
*/
protected $delimiter = ';';
/**
* Get file to import
* @return string
*/
public function getFile()
{
return __DIR__ . '/../files/test-custom.csv';
}
}

View File

@@ -1,16 +0,0 @@
<?php
use Maatwebsite\Excel\Files\NewExcelFile;
class TestExport extends NewExcelFile {
/**
* Get file to import
* @return string
*/
public function getFilename()
{
return 'test-file';
}
}

View File

@@ -1,17 +0,0 @@
<?php
use Maatwebsite\Excel\Files\ExportHandler;
class TestExportHandler implements ExportHandler {
/**
* Handle
* @param $file
* @return mixed|void
*/
public function handle($file)
{
return 'exported';
}
}

View File

@@ -1,31 +0,0 @@
<?php
use Maatwebsite\Excel\Files\ExcelFile;
class TestFile extends ExcelFile {
protected $delimiter = ',';
protected $enclosure = '"';
protected $lineEnding = '\r\n';
/**
* Get file to import
* @return string
*/
public function getFile()
{
return __DIR__ . '/../files/test.csv';
}
/**
* Get filters
* @return array
*/
public function getFilters()
{
return [
'chunk'
];
}
}

View File

@@ -1,17 +0,0 @@
<?php
use Maatwebsite\Excel\Files\ImportHandler;
class TestFileHandler implements ImportHandler {
/**
* Handle
* @param $file
* @return mixed|void
*/
public function handle($file)
{
return $file->get();
}
}

View File

@@ -1,31 +0,0 @@
<?php
use Maatwebsite\Excel\Files\ExcelFile;
class TestImport extends ExcelFile {
protected $delimiter = ',';
protected $enclosure = '"';
protected $lineEnding = '\r\n';
/**
* Get file to import
* @return string
*/
public function getFile()
{
return __DIR__ . '/../files/test.csv';
}
/**
* Get filters
* @return array
*/
public function getFilters()
{
return [
'chunk'
];
}
}

View File

@@ -1,17 +0,0 @@
<?php
use Maatwebsite\Excel\Files\ImportHandler;
class TestImportHandler implements ImportHandler {
/**
* Handle
* @param $file
* @return mixed|void
*/
public function handle($file)
{
return $file->get();
}
}

View File

@@ -1,16 +0,0 @@
<?php
use Maatwebsite\Excel\Files\NewExcelFile;
class TestNewFile extends NewExcelFile {
/**
* Get file to import
* @return string
*/
public function getFilename()
{
return 'test-file';
}
}

View File

@@ -1,17 +0,0 @@
<?php
use Maatwebsite\Excel\Files\ExportHandler;
class TestNewFileHandler implements ExportHandler {
/**
* Handle
* @param $file
* @return mixed|void
*/
public function handle($file)
{
return 'exported';
}
}

View File

@@ -1,6 +0,0 @@
heading one;heading two;heading three
test;test;test
test;test;test
test;test;test
test;test;test
test;test;test
1 heading one heading two heading three
2 test test test
3 test test test
4 test test test
5 test test test
6 test test test

View File

@@ -1,6 +0,0 @@
heading one,heading two,heading three
test,test,test
test,test,test
test,test,test
test,test,test
test,test,test
1 heading one heading two heading three
2 test test test
3 test test test
4 test test test
5 test test test
6 test test test

View File

@@ -1,103 +0,0 @@
<?php
use Mockery as m;
class ChunkReadFilterTest extends TestCase
{
public function setUp()
{
parent::setUp();
$this->excel = app('excel');
}
public function testCanChunkXls()
{
$this->assertCanChunkIntoGroups(1, "sample.xls", 20);
$this->assertCanChunkIntoGroups(1, "sample.xls", 15);
$this->assertCanChunkIntoGroups(2, "sample.xls", 10);
$this->assertCanChunkIntoGroups(3, "sample.xls", 5);
$this->assertCanChunkIntoGroups(15, "sample.xls", 1);
}
public function testCanChunkXlsx()
{
$this->assertCanChunkIntoGroups(1, "sample.xlsx", 20);
$this->assertCanChunkIntoGroups(1, "sample.xlsx", 15);
$this->assertCanChunkIntoGroups(2, "sample.xlsx", 10);
$this->assertCanChunkIntoGroups(3, "sample.xlsx", 5);
$this->assertCanChunkIntoGroups(15, "sample.xlsx", 1);
}
public function testCanChunkCsv()
{
$this->assertCanChunkIntoGroups(1, "sample.csv", 20);
$this->assertCanChunkIntoGroups(1, "sample.csv", 15);
$this->assertCanChunkIntoGroups(2, "sample.csv", 10);
$this->assertCanChunkIntoGroups(3, "sample.csv", 5);
$this->assertCanChunkIntoGroups(15, "sample.csv", 1);
}
public function testCanChunkMultipleSheets()
{
file_put_contents(__DIR__ . '/log.txt', '');
file_put_contents(__DIR__ . '/rounds.txt', '');
// test with small chunks
$chunk_size = 2;
$expected = "1,3,5,7,9,11,13,15,17,19,1,3,5,7,9,11,13,15,17,19";
$expected_chunks = 10;
// Sheet2 has more rows than sheet 1
$this->excel->filter('chunk')
->selectSheets('Sheet2')
->load(__DIR__ . "/files/multi.xls")
->chunk($chunk_size, function ($results) {
foreach ($results as $row) {
$output[] = (int)$row->header;
}
$previous = file_get_contents(__DIR__ . '/log.txt');
$previous = !empty($previous) ? $previous . ',' : $previous;
$rounds = file_get_contents(__DIR__ . '/rounds.txt');
file_put_contents(__DIR__ . '/log.txt', $previous . implode(',', $output));
file_put_contents(__DIR__ . '/rounds.txt', $rounds . '+');
}, false);
$output = file_get_contents(__DIR__ . '/log.txt');
$rounds = strlen(file_get_contents(__DIR__ . '/rounds.txt'));
$this->assertEquals($expected, $output, "Chunked ($chunk_size) value not equal with source data.");
$this->assertEquals($expected_chunks, $rounds,
"Expecting total chunks is $expected_chunks when chunk with size $chunk_size");
}
private function assertCanChunkIntoGroups($expected_chunks, $file, $chunk_size)
{
file_put_contents(__DIR__ . '/log.txt', '');
file_put_contents(__DIR__ . '/rounds.txt', '');
$this->excel->filter('chunk')->load(__DIR__ . "/files/{$file}")->chunk($chunk_size, function ($results) {
foreach ($results as $row) {
$output[] = (int)$row->header;
}
$previous = file_get_contents(__DIR__ . '/log.txt');
$previous = !empty($previous) ? $previous . ',' : $previous;
$rounds = file_get_contents(__DIR__ . '/rounds.txt');
file_put_contents(__DIR__ . '/log.txt', $previous . implode(',', $output));
file_put_contents(__DIR__ . '/rounds.txt', $rounds . '+');
}, false);
$output = file_get_contents(__DIR__ . '/log.txt');
$rounds = strlen(file_get_contents(__DIR__ . '/rounds.txt'));
$expected = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15";
$this->assertEquals($expected, $output, "Chunked ($chunk_size) value not equal with source data.");
$this->assertEquals($expected_chunks, $rounds,
"Expecting total chunks is $expected_chunks when chunk with size $chunk_size");
}
}

View File

@@ -1,79 +0,0 @@
<?php
use Mockery as m;
class RegisterFilterTestCase extends TestCase {
public function setUp()
{
parent::setUp();
$this->excel = app('excel');
}
public function testRegisterThroughConfig()
{
$registered = Config::get('excel.filters.registered');
$filters = $this->excel->getFilters('registered');
$this->assertEquals($registered, $filters);
}
public function testOnlyRegister()
{
$toRegister = array(
'chunk' => 'ChunkFilter'
);
$excel = $this->excel->registerFilters($toRegister);
$filters = $this->excel->getFilters('registered');
$this->assertEquals($toRegister, $filters);
}
public function testRegisterAndEnabled()
{
$toRegister = array(
'registered' => array(
'chunk' => 'ChunkFilter'
),
'enabled' => array(
'chunk'
)
);
$excel = $this->excel->registerFilters($toRegister);
$filters = $this->excel->getFilters();
$this->assertEquals($toRegister, $filters);
}
public function testEnableOneFilter()
{
$excel = $this->excel->filter('chunk');
$filters = $this->excel->getFilters('enabled');
$this->assertContains('chunk', $filters);
}
public function testEnableMultipleFilter()
{
$excel = $this->excel->filter(array('chunk', 'range'));
$filters = $this->excel->getFilters('enabled');
$this->assertContains('chunk', $filters);
$this->assertContains('range', $filters);
}
public function testEnableFilterAndOverruleFilterClass()
{
$excel = $this->excel->filter('chunk', 'ChunkFilter');
$registered = $this->excel->getFilters('registered');
$this->assertEquals(array('chunk' => 'ChunkFilter'), $registered);
$enabled = $this->excel->getFilters('enabled');
$this->assertContains('chunk', $enabled);
}
}

View File

@@ -1,16 +0,0 @@
HEADER
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1 HEADER
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15

View File

@@ -1 +0,0 @@
1,3,5,7,9,11,13,15,17,19,1,3,5,7,9,11,13,15,17,19

View File

@@ -1 +0,0 @@
++++++++++

View File

@@ -1,100 +0,0 @@
<?php
use Mockery as m;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use Maatwebsite\Excel\Classes;
class ChineseXlsReaderTest extends TestCase {
/**
* Test csv file
* @var [type]
*/
protected $xls;
/**
* Loaded csv file
* @var [type]
*/
protected $loadedXls;
/**
* Setup
*/
public function setUp()
{
parent::setUp();
// Disable to ascii
Config::set('excel.import.to_ascii', false);
// Set excel class
$this->excel = App::make('phpexcel');
// Set writer class
$this->reader = App::make('excel.reader');
$this->reader->injectExcel($this->excel);
// Load csv file
$this->loadChineseXls();
}
/**
* Test loading a csv file
* @return [type] [description]
*/
public function testloadChineseXls()
{
$this->assertEquals($this->reader, $this->loadedXls);
$this->assertInstanceOf('PHPExcel', $this->reader->getExcel());
}
/**
* Test get
* @return [type] [description]
*/
public function testGet()
{
$got = $this->loadedXls->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $got);
$this->assertCount(2, $got);
}
/**
* Test toArray
* @return [type] [description]
*/
public function testToArray()
{
$array = $this->loadedXls->toArray();
$this->assertEquals(array(
array(
'商品編號' => 'L01A01SY047',
'商品名稱' => 'LED T8燈管',
'實際數量' => 1,
),
array(
'商品編號' => 'L01A01SY046',
'商品名稱' => 'LED T8燈管',
'實際數量' => 1,
)
), $array);
}
/**
* Load a csv file
* @return [type] [description]
*/
protected function loadChineseXls()
{
// Set test csv file
$this->xls = __DIR__ . '/files/' . 'chinese.xls';
// Loaded csv
$this->loadedXls = $this->reader->load($this->xls);
}
}

View File

@@ -1,51 +0,0 @@
<?php
require_once('traits/ImportTrait.php');
require_once('traits/SingleImportTestingTrait.php');
use Mockery as m;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use Maatwebsite\Excel\Classes;
class CsvReaderTest extends TestCase {
/**
* Import trait
*/
use ImportTrait, SingleImportTestingTrait;
/**
* Filename
* @var string
*/
protected $fileName = 'files/test.csv';
public function testSeparator()
{
$this->assertEquals('_', $this->loadedFile->getSeparator());
}
public function testSetSeparator()
{
$set = $this->loadedFile->setSeparator('-');
$this->assertEquals('-', $set->getSeparator());
}
public function testSetDelimiter()
{
$this->loadedFile->setDelimiter(';');
$this->reload();
$this->assertEquals(';', $this->loadedFile->getDelimiter());
}
public function testSetEnclosure()
{
$this->loadedFile->setEnclosure('d');
$this->reload();
$this->assertEquals('d', $this->loadedFile->getEnclosure());
}
}

View File

@@ -1,106 +0,0 @@
<?php
class CustomValuBinderTest extends TestCase {
/**
* Setup
*/
public function setUp()
{
parent::setUp();
// Set excel class
$this->excel = App::make('phpexcel');
// Set writer class
$this->reader = App::make('excel.reader');
$this->reader->injectExcel($this->excel);
$this->reader->noHeading(true);
// Set value binder
$binder = new StubValueBinder();
$this->reader->setValueBinder($binder);
// Load csv file
$this->loadFile();
}
/**
* Tear down
*/
public function tearDown()
{
// Necessary to reset the value binder back to default so that future test classes are unaffected.
$this->reader->resetValueBinder();
}
public function testDefaultGet()
{
$got = $this->loadedFile->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $got);
$this->assertCount(5, $got);
}
public function testNumeric()
{
$got = $this->loadedFile->toArray();
$this->assertTrue(is_string($got[0][0]));
$this->assertEquals('00123', $got[0][0]);
}
public function testRealNull()
{
$got = $this->loadedFile->toArray();
$this->assertTrue(is_null($got[1][0]));
$this->assertEquals('', $got[1][0]);
}
public function testStringNull()
{
$got = $this->loadedFile->toArray();
$this->assertTrue(is_string($got[2][0]));
$this->assertEquals('null', $got[2][0]);
}
public function testEquation()
{
$got = $this->loadedFile->toArray();
$this->assertTrue(is_string($got[3][0]));
$this->assertEquals('=1+2', $got[3][0]);
}
public function testBoolean()
{
$got = $this->loadedFile->toArray();
$this->assertTrue(is_string($got[4][0]));
$this->assertEquals('true', $got[4][0]);
}
/**
* Load a csv file
* @return [type] [description]
*/
protected function loadFile()
{
// Set test csv file
$file = __DIR__ . '/files/' . 'customBinder.csv';
// Loaded csv
$this->loadedFile = $this->reader->load($file);
}
}
class StubValueBinder extends PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
{
public function bindValue(PHPExcel_Cell $cell, $value = null)
{
$cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
return true;
}
}

View File

@@ -1,111 +0,0 @@
<?php
require_once('traits/ImportTrait.php');
use Mockery as m;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use Maatwebsite\Excel\Classes;
class MultipleSheetsXlsReaderTest extends TestCase {
/**
* Import trait
*/
use ImportTrait;
/**
* Filename
* @var string
*/
protected $fileName = 'files/multiple.xls';
/**
* Test get
* @return [type] [description]
*/
public function testGet()
{
$got = $this->loadedFile->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\SheetCollection', $got);
$this->assertCount(2, $got);
}
/**
* Test get
* @return [type] [description]
*/
public function testGetAndGetFirstSheetName()
{
$got = $this->loadedFile->get();
// get first sheet
$sheet = $got->first();
// assert sheet title
$this->assertEquals('Sheet1', $sheet->getTitle());
// 5 rows
$this->assertCount(5, $sheet);
}
public function testSelectSheet()
{
$this->reader->setSelectedSheets('Sheet2');
$this->reload();
$sheet = $this->loadedFile->get();
$this->assertEquals('Sheet2', $sheet->getTitle());
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $sheet);
$this->assertCount(5, $sheet);
}
public function testSelectSheetByIndex()
{
$this->reader->setSelectedSheetIndices(array(1));
$this->reload();
$sheet = $this->loadedFile->get();
$this->assertEquals('Sheet2', $sheet->getTitle());
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $sheet);
$this->assertCount(5, $sheet);
}
public function testSelectMultipleSheets()
{
$this->reader->setSelectedSheets(array('Sheet1', 'Sheet2'));
$this->reload();
$got = $this->loadedFile->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\SheetCollection', $got);
$this->assertCount(2, $got);
// get first sheet
$sheet = $got->first();
// assert sheet title
$this->assertEquals('Sheet1', $sheet->getTitle());
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $sheet);
$this->assertCount(5, $sheet);
}
public function testSelectMultipleSheetsByIndex()
{
$this->reader->setSelectedSheetIndices(array(0,1));
$this->reload();
$got = $this->loadedFile->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\SheetCollection', $got);
$this->assertCount(2, $got);
// get first sheet
$sheet = $got->first();
// assert sheet title
$this->assertEquals('Sheet1', $sheet->getTitle());
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $sheet);
$this->assertCount(5, $sheet);
}
}

View File

@@ -1,33 +0,0 @@
<?php
use Mockery as m;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use Maatwebsite\Excel\Classes;
class ReaderTest extends TestCase {
/**
* Setup
*/
public function setUp()
{
parent::setUp();
// Set excel class
$this->excel = App::make('phpexcel');
// Set writer class
$this->reader = App::make('excel.reader');
$this->reader->injectExcel($this->excel);
}
/**
* Test the excel injection
* @return [type] [description]
*/
public function testExcelInjection()
{
$this->assertEquals($this->excel, $this->reader->getExcel());
}
}

View File

@@ -1,23 +0,0 @@
<?php
require_once('traits/ImportTrait.php');
require_once('traits/SingleImportTestingTrait.php');
use Mockery as m;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use Maatwebsite\Excel\Classes;
class XlsReaderTest extends TestCase {
/**
* Import trait
*/
use ImportTrait, SingleImportTestingTrait;
/**
* Filename
* @var string
*/
protected $fileName = 'files/test.xls';
}

View File

@@ -1,23 +0,0 @@
<?php
require_once('traits/ImportTrait.php');
require_once('traits/SingleImportTestingTrait.php');
use Mockery as m;
use Maatwebsite\Excel\Readers\LaravelExcelReader;
use Maatwebsite\Excel\Classes;
class XlsxReaderTest extends TestCase {
/**
* Import trait
*/
use ImportTrait, SingleImportTestingTrait;
/**
* Filename
* @var string
*/
protected $fileName = 'files/test.xlsx';
}

View File

@@ -1,74 +0,0 @@
<?php
require_once('traits/ImportTrait.php');
require_once('traits/SingleImportTestingTrait.php');
use Mockery as m;
class ZerosHandlingReaderTest extends TestCase {
/**
* Traits
*/
use ImportTrait;
/**
* Filename
* @var string
*/
protected $fileName = 'files/zeros.xls';
/**
* @var bool
*/
protected $noHeadings = false;
public function testDefaultGet()
{
$got = $this->loadedFile->get();
$this->assertInstanceOf('Maatwebsite\Excel\Collections\RowCollection', $got);
$this->assertCount(6, $got);
}
//
//public function testStringsAppendedPrependedWithZeros()
//{
// $got = $this->loadedFile->toArray();
//
// $this->assertContains('TEST000', $got[3]);
// $this->assertContains('000TEST', $got[4]);
//}
//
//
//public function testStringZeros()
//{
// $got = $this->loadedFile->toArray();
//
// $this->assertContains('000', $got[0]);
//}
public function testMoney()
{
$got = $this->loadedFile->toArray();
$this->assertContains((double) 0, $got[1]);
}
public function testEmptyCellHandling()
{
$got = $this->loadedFile->toArray();
$this->assertContains(null, $got[2]);
}
public function testNormalZeros()
{
$got = $this->loadedFile->toArray();
$this->assertContains((double) 0, $got[5]);
}
}

View File

@@ -1,5 +0,0 @@
00123
null
=1+2
true
1 00123
2 null
3 =1+2
4 true

View File

@@ -1,6 +0,0 @@
heading one,heading two,heading three
test,test,test
test,test,test
test,test,test
test,test,test
test,test,test
1 heading one heading two heading three
2 test test test
3 test test test
4 test test test
5 test test test
6 test test test

Some files were not shown because too many files have changed in this diff Show More