Skip to content

Commit e63b71d

Browse files
committed
Update readme
1 parent 46f9a91 commit e63b71d

File tree

2 files changed

+51
-40
lines changed

2 files changed

+51
-40
lines changed

README.md

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,87 @@
1-
# Laravel Excel
2-
1+
# Laravel Excel
32
[![Latest Stable Version](https://poser.pugx.org/cyber-duck/laravel-excel/v/stable)](https://packagist.org/packages/cyber-duck/laravel-excel)
43
[![Total Downloads](https://poser.pugx.org/cyber-duck/laravel-excel/downloads)](https://packagist.org/packages/cyber-duck/laravel-excel)
54
[![License](https://poser.pugx.org/cyber-duck/laravel-excel/license)](https://raw.githubusercontent.com/Cyber-Duck/laravel-excel/master/LICENSE)
65

7-
Laravel Excel is a pachage to export and import excel files using Eloquent Collections in Laravel (5.* and 4.*).
6+
Exporting and importing Excel, CSV and OpenOffice stylesheets using Eloquent Collections and Query Builders in Laravel (5.* and 4.*).
87
It's based on [box/spout](https://github.com/box/spout).
98

10-
Author: [Simone Todaro](https://github.com/SimoTod)
11-
12-
Contributors: [Clément Blanco](https://github.com/Claymm)
13-
9+
Author: [Simone Todaro](https://github.com/SimoTod)
10+
Contributors: [Clément Blanco](https://github.com/Claymm)
1411
Made with :heart: by [Cyber-Duck Ltd](http://www.cyber-duck.co.uk)
1512

1613
[Installation](#installation)
1714
[Export Excel](#export-excel)
1815
[Import Excel](#import-excel)
1916
[Different formats](#different-formats)
2017

21-
## Installation
18+
## Installation
19+
Use composer to download the package:
2220
```
23-
$ composer require cyber-duck/laravel-excel
21+
composer require cyber-duck/laravel-excel
2422
```
2523

26-
Register the service provider in config/app.php adding *Cyberduck\LaravelExcel\ExcelServiceProvider* to the provider array.
24+
Register the service provider in `config/app.php` adding *Cyberduck\LaravelExcel\ExcelServiceProvider* to the provider array.
2725

2826
Note. If you are on Laravel 4, use *Cyberduck\LaravelExcel\ExcelLegacyServiceProvider*
2927

3028
## Export Excel
3129

3230
### Generate and download an excel file
33-
Add
31+
Add
3432
```
3533
use Exporter;
36-
```
34+
```
3735
to your controller.
3836

39-
In your controler function, create a new excel file.
37+
In your controler function, create a new excel file from an Eloquent collection.
4038
```
4139
$excel = Exporter::make('Excel');
42-
$excel->load($yourCollection);
43-
return $excel->stream($yourFileName);
44-
```
40+
$excel->load($yourCollection);
41+
return $excel->stream($yourFileName);
42+
```
4543

46-
The exporter class is fluent, then you can also write
44+
The exporter class is fluent, so you can also write
4745
```
4846
return Exporter::make('Excel')->load($yourCollection)->stream($yourFileName);
4947
```
5048

51-
### Generate and save an excel file
52-
Add
49+
The exporter class supports Query builder objects as well
50+
```
51+
$query = DB:table('table')->select('col1','col2');
52+
$excel = Exporter::make('Excel');
53+
$excel->loadQuery($query);
54+
return $excel->stream($yourFileName);
5355
```
54-
use Exporter;
55-
```
56-
to your controller.
5756

58-
In your controler function, create a new excel file.
57+
If you deal with big tables, you can set the chunk size to minimise the memory usage
5958
```
59+
$query = DB:table('table')->select('col1','col2');
6060
$excel = Exporter::make('Excel');
61-
$excel->load($yourCollection);
62-
return $excel->save($yourFileNameWithPath);
63-
```
61+
$excel->loadQuery($query);
62+
$excel->setChunk(1000);
63+
return $excel->stream($yourFileName);
64+
```
6465

65-
The exporter class is fluent, then you can also write
66+
### Generate and save an excel file
67+
To save the excel file on the server, use the save method.
6668
```
67-
return Exporter::make('Excel')->load($yourCollection)->save($yourFileNameWithPath);
69+
return $excel->save($yourFileNameWithPath);
6870
```
6971

7072
### Advanced usage
7173
By default, every element of the Collection becomes a row and every unprotected field of the Model becomes a cell.
7274
No headers row is printed.
7375

74-
To change this behaviour, create a class which extends *Cyberduck\LaravelExcel\Contract\SerialiserInterface* and implements the methods *getHeaderRow()* and *getData(Model $data)*.
76+
To change this behaviour, create a class extending *Cyberduck\LaravelExcel\Contract\SerialiserInterface*, implement the methods *getHeaderRow()* and *getData(Model $data)* and set this class on the excel object usint *setSerialiser()*.
77+
```
78+
$serialiser = new CustomSerialiser();
79+
$excel = Exporter::make('Excel');
80+
$excel->load($collection);
81+
$excel->setSerialiser($serialiser);
82+
return $excel->stream($yourFileName);
83+
```
84+
7585
*getHeaderRow()* must return an array of string where every element is a cell of the first row. To not print the header row, simply return a void array *[]*.
7686
*getData(Model $data)* must return an array of string, and every elements is a cell.
7787

@@ -105,21 +115,21 @@ class ExampleSerialiser implements SerialiserInterface
105115
```
106116

107117
## Import Excel
108-
Add
118+
Add
109119
```
110120
use Importer;
111-
```
121+
```
112122
to your controller.
113123

114124
In your controler function, import an excel file.
115125
```
116126
$excel = Importer::make('Excel');
117-
$excel->load($filepath);
118-
$collection = $excel->getCollection();
127+
$excel->load($filepath);
128+
$collection = $excel->getCollection();
119129
//dd($collection)
120-
```
130+
```
121131

122-
The importer class is fluent, then you can also write
132+
The importer class is fluent, then you can also write
123133
```
124134
return Importer::make('Excel')->getCollection($filepath)->getCollection();
125135
```
@@ -130,13 +140,13 @@ By default, every row of the first sheet of the excel file becomes an array and
130140
To import a different sheet, use *setSheet($sheet)*
131141
```
132142
$excel = Importer::make('Excel');
133-
$excel->load($filepath);
134-
$excel->setSheet($sheetNumber);
135-
$collection = $excel->getCollection();
143+
$excel->load($filepath);
144+
$excel->setSheet($sheetNumber);
145+
$collection = $excel->getCollection();
136146
//dd($collection)
137-
```
147+
```
138148

139-
To import each row in an Eloquent model, create a class which extends *Cyberduck\LaravelExcel\Contract\ParserInterface* and implements the methods *transform($row)*.
149+
To import each row in an Eloquent model, create a class extending *Cyberduck\LaravelExcel\Contract\ParserInterface* and implement the methods *transform($row)*.
140150

141151
Example
142152
```

src/Contract/ImporterInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ interface ImporterInterface
66
public function load($path);
77
public function setParser(ParserInterface $parser);
88
public function getCollection();
9+
public function setSheet($sheet);
910
}

0 commit comments

Comments
 (0)