├── .gitignore
├── .vuepress
├── 2.1.js
├── 3.0.js
├── 3.1.js
├── 4.x.js
├── config.js
├── csv
│ └── 1.0.js
├── nova
│ └── 1.x.js
├── public
│ ├── android-chrome-192x192.png
│ ├── android-chrome-512x512.png
│ ├── apple-touch-icon.png
│ ├── assets
│ │ └── img
│ │ │ └── logo-small.png
│ ├── favicon-16x16.png
│ ├── favicon-32x32.png
│ ├── favicon.ico
│ ├── icon.png
│ ├── manifest.json
│ ├── mstile-150x150.png
│ └── safari-pinned-tab.svg
├── styles
│ ├── index.styl
│ └── palette.styl
└── theme
│ ├── LICENSE
│ ├── components
│ ├── AlgoliaSearchBox.vue
│ ├── DropdownLink.vue
│ ├── DropdownTransition.vue
│ ├── Home.vue
│ ├── NavLink.vue
│ ├── NavLinks.vue
│ ├── Navbar.vue
│ ├── Page.vue
│ ├── Sidebar.vue
│ ├── SidebarButton.vue
│ ├── SidebarGroup.vue
│ └── SidebarLink.vue
│ ├── global-components
│ └── Badge.vue
│ ├── index.js
│ ├── layouts
│ ├── 404.vue
│ └── Layout.vue
│ ├── noopModule.js
│ ├── styles
│ ├── arrow.styl
│ ├── code.styl
│ ├── custom-blocks.styl
│ ├── mobile.styl
│ ├── theme.styl
│ ├── toc.styl
│ └── wrapper.styl
│ └── util
│ └── index.js
├── 2.1
├── README.md
├── blade
│ ├── load-view.md
│ ├── styling.md
│ └── vars.md
├── changelog
│ ├── version-1.md
│ └── version-2.md
├── export
│ ├── README.md
│ ├── array.md
│ ├── autofilter.md
│ ├── autosize.md
│ ├── call.md
│ ├── cells.md
│ ├── export.md
│ ├── format.md
│ ├── freeze.md
│ ├── injection.md
│ ├── merge.md
│ ├── rows.md
│ ├── sheet-styling.md
│ ├── sheets.md
│ ├── sizing.md
│ └── store.md
├── getting-started
│ ├── README.md
│ ├── config.md
│ ├── contributing.md
│ ├── license.md
│ └── requirements.md
├── import
│ ├── README.md
│ ├── batch.md
│ ├── cache.md
│ ├── calculation.md
│ ├── chunk.md
│ ├── config.md
│ ├── convert.md
│ ├── dates.md
│ ├── edit.md
│ ├── extra.md
│ ├── formatting.md
│ ├── injection.md
│ ├── results.md
│ └── select.md
└── reference-guide
│ ├── borders.md
│ ├── closures.md
│ ├── css-styles.md
│ ├── file-properties.md
│ ├── formatting.md
│ └── sheet-properties.md
├── 3.0
├── README.md
├── exports
│ ├── README.md
│ ├── collection.md
│ ├── column-formatting.md
│ ├── concerns.md
│ ├── export-formats.md
│ ├── exportables.md
│ ├── extending.md
│ ├── from-query.md
│ ├── from-view.md
│ ├── mapping.md
│ ├── multiple-sheets.md
│ ├── queued.md
│ ├── store.md
│ └── testing.md
└── getting-started
│ ├── README.md
│ ├── contributing.md
│ ├── installation.md
│ ├── license.md
│ ├── support.md
│ └── upgrade.md
├── 3.1
├── README.md
├── architecture
│ ├── README.md
│ ├── concerns.md
│ └── objects.md
├── exports
│ ├── README.md
│ ├── charts.md
│ ├── collection.md
│ ├── column-formatting.md
│ ├── concerns.md
│ ├── drawings.md
│ ├── export-formats.md
│ ├── exportables.md
│ ├── extending.md
│ ├── from-generator.md
│ ├── from-query.md
│ ├── from-view.md
│ ├── mapping.md
│ ├── multiple-sheets.md
│ ├── queued.md
│ ├── settings.md
│ ├── store.md
│ └── testing.md
├── getting-started
│ ├── README.md
│ ├── contributing.md
│ ├── installation.md
│ ├── license.md
│ ├── support.md
│ └── upgrade.md
└── imports
│ ├── README.md
│ ├── basics.md
│ ├── batch-inserts.md
│ ├── chunk-reading.md
│ ├── collection.md
│ ├── concerns.md
│ ├── custom-csv-settings.md
│ ├── custom-formatting-values.md
│ ├── extending.md
│ ├── heading-row.md
│ ├── import-formats.md
│ ├── importables.md
│ ├── mapped-cells.md
│ ├── model.md
│ ├── multiple-sheets.md
│ ├── progress-bar.md
│ ├── queued.md
│ ├── start-row.md
│ ├── testing.md
│ └── validation.md
├── 4.x
├── README.md
├── architecture
│ ├── README.md
│ ├── concerns.md
│ └── objects.md
├── exports
│ ├── README.md
│ ├── advanced.md
│ ├── columns.md
│ ├── concern-overview.md
│ ├── data.md
│ ├── exporting.md
│ ├── performance.md
│ ├── presentation.md
│ ├── settings.md
│ └── testing.md
├── getting-started
│ ├── README.md
│ ├── contributing.md
│ ├── installation.md
│ ├── license.md
│ ├── support.md
│ └── upgrade.md
└── imports
│ ├── README.md
│ ├── basics.md
│ ├── batch-inserts.md
│ ├── chunk-reading.md
│ ├── collection.md
│ ├── concerns.md
│ ├── custom-csv-settings.md
│ ├── custom-formatting-values.md
│ ├── extending.md
│ ├── heading-row.md
│ ├── import-formats.md
│ ├── importables.md
│ ├── mapped-cells.md
│ ├── model.md
│ ├── multiple-sheets.md
│ ├── progress-bar.md
│ ├── queued.md
│ ├── testing.md
│ └── validation.md
├── README.md
├── csv
├── 1.0
│ ├── README.md
│ ├── exports
│ │ ├── README.md
│ │ ├── collection.md
│ │ ├── concerns.md
│ │ ├── configuration.md
│ │ ├── exportables.md
│ │ ├── from-query.md
│ │ ├── heading-row.md
│ │ ├── mapping.md
│ │ ├── queued.md
│ │ └── store.md
│ └── getting-started
│ │ ├── README.md
│ │ ├── contributing.md
│ │ ├── installation.md
│ │ ├── license.md
│ │ └── support.md
└── README.md
├── nova
├── 1.0
│ └── README.md
├── 1.1
│ └── README.md
├── 1.x
│ ├── README.md
│ ├── exports
│ │ ├── README.md
│ │ ├── customizations.md
│ │ ├── download.md
│ │ ├── interactions.md
│ │ ├── queued.md
│ │ └── store.md
│ └── getting-started
│ │ ├── README.md
│ │ ├── contributing.md
│ │ ├── installation.md
│ │ ├── license.md
│ │ └── support.md
└── README.md
├── package-lock.json
├── package.json
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | /node_modules
2 | /.vuepress/dist
3 | .DS_Store
4 | .idea
--------------------------------------------------------------------------------
/.vuepress/2.1.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | {
3 | title: 'Getting Started',
4 | collapsable: false,
5 | children: prefix('getting-started', [
6 | '',
7 | 'config',
8 | 'requirements',
9 | 'contributing',
10 | 'license'
11 | ]),
12 | },
13 | {
14 | title: 'Imports',
15 | collapsable: false,
16 | children: prefix('import', [
17 | '',
18 | 'injection',
19 | 'results',
20 | 'select',
21 | 'dates',
22 | 'calculation',
23 | 'formatting',
24 | 'cache',
25 | 'chunk',
26 | 'batch',
27 | 'config',
28 | 'edit',
29 | 'convert',
30 | 'extra'
31 | ]),
32 | },
33 | {
34 | title: 'Exports',
35 | collapsable: false,
36 | children: prefix('export', [
37 | '',
38 | 'export',
39 | 'injection',
40 | 'store',
41 | 'sheets',
42 | 'array',
43 | 'rows',
44 | 'cells',
45 | 'sheet-styling',
46 | 'freeze',
47 | 'autofilter',
48 | 'sizing',
49 | 'autosize',
50 | 'merge',
51 | 'format',
52 | 'call'
53 | ]),
54 | },
55 | {
56 | title: 'Blade to Excel',
57 | collapsable: false,
58 | children: prefix('blade', [
59 | 'load-view',
60 | 'vars',
61 | 'styling',
62 | ]),
63 | },
64 | {
65 | title: 'Reference Guide',
66 | collapsable: false,
67 | children: prefix('reference-guide', [
68 | 'file-properties',
69 | 'sheet-properties',
70 | 'css-styles',
71 | 'borders',
72 | 'formatting',
73 | 'closures'
74 | ]),
75 | }
76 | ];
77 |
78 | function prefix(prefix, children) {
79 | return children.map(child => `${prefix}/${child}`)
80 | }
81 |
--------------------------------------------------------------------------------
/.vuepress/3.0.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | {
3 | title: 'Getting Started',
4 | collapsable: false,
5 | children: prefix('getting-started', [
6 | '',
7 | 'license',
8 | 'installation',
9 | 'upgrade',
10 | 'contributing',
11 | 'support'
12 | ]),
13 | },
14 | {
15 | title: 'Exports',
16 | collapsable: false,
17 | children: prefix('exports', [
18 | '',
19 | 'collection',
20 | 'store',
21 | 'export-formats',
22 | 'exportables',
23 | 'from-query',
24 | 'from-view',
25 | 'queued',
26 | 'multiple-sheets',
27 | 'mapping',
28 | 'column-formatting',
29 | 'concerns',
30 | 'extending',
31 | 'testing'
32 | ]),
33 | },
34 | ];
35 |
36 | function prefix(prefix, children) {
37 | return children.map(child => `${prefix}/${child}`)
38 | }
39 |
--------------------------------------------------------------------------------
/.vuepress/3.1.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | {
3 | title: 'Getting Started',
4 | collapsable: true,
5 | children: prefix('getting-started', [
6 | '',
7 | 'license',
8 | 'installation',
9 | 'upgrade',
10 | 'contributing',
11 | 'support',
12 | ]),
13 | },
14 | {
15 | title: 'Architecture Concepts',
16 | collapsable: true,
17 | children: prefix('architecture', [
18 | '',
19 | 'objects',
20 | 'concerns',
21 | ]),
22 | },
23 | {
24 | title: 'Exports',
25 | collapsable: true,
26 | children: prefix('exports', [
27 | '',
28 | 'collection',
29 | 'store',
30 | 'export-formats',
31 | 'exportables',
32 | 'from-query',
33 | 'from-view',
34 | 'from-generator',
35 | 'queued',
36 | 'multiple-sheets',
37 | 'mapping',
38 | 'column-formatting',
39 | 'settings',
40 | 'drawings',
41 | 'concerns',
42 | 'extending',
43 | 'testing',
44 | ]),
45 | },
46 | {
47 | title: 'Imports',
48 | collapsable: true,
49 | children: prefix('imports', [
50 | '',
51 | 'basics',
52 | 'collection',
53 | 'model',
54 | 'importables',
55 | 'import-formats',
56 | 'multiple-sheets',
57 | 'heading-row',
58 | 'batch-inserts',
59 | 'chunk-reading',
60 | 'queued',
61 | 'validation',
62 | 'mapped-cells',
63 | 'custom-csv-settings',
64 | 'start-row',
65 | 'progress-bar',
66 | 'concerns',
67 | 'extending',
68 | 'testing',
69 | ]),
70 | },
71 | ];
72 |
73 | function prefix(prefix, children) {
74 | return children.map(child => `${prefix}/${child}`)
75 | }
76 |
--------------------------------------------------------------------------------
/.vuepress/4.x.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | {
3 | title: 'Getting Started',
4 | collapsable: true,
5 | children: prefix('getting-started', [
6 | '',
7 | 'license',
8 | 'installation',
9 | 'upgrade',
10 | 'contributing',
11 | 'support',
12 | ]),
13 | },
14 | {
15 | title: 'Architecture Concepts',
16 | collapsable: true,
17 | children: prefix('architecture', [
18 | '',
19 | 'objects',
20 | 'concerns',
21 | ]),
22 | },
23 | {
24 | title: 'Exports',
25 | collapsable: true,
26 | children: prefix('exports', [
27 | '',
28 | 'exporting',
29 | 'data',
30 | 'columns',
31 | 'presentation',
32 | 'performance',
33 | 'settings',
34 | 'advanced',
35 | 'concern-overview',
36 | 'testing'
37 | ]),
38 | },
39 | {
40 | title: 'Imports',
41 | collapsable: true,
42 | children: prefix('imports', [
43 | '',
44 | 'basics',
45 | 'collection',
46 | 'model',
47 | 'importables',
48 | 'import-formats',
49 | 'multiple-sheets',
50 | 'heading-row',
51 | 'batch-inserts',
52 | 'chunk-reading',
53 | 'queued',
54 | 'validation',
55 | 'mapped-cells',
56 | 'custom-csv-settings',
57 | 'progress-bar',
58 | 'concerns',
59 | 'extending',
60 | 'testing',
61 | ]),
62 | },
63 | ];
64 |
65 | function prefix(prefix, children) {
66 | return children.map(child => `${prefix}/${child}`)
67 | }
68 |
--------------------------------------------------------------------------------
/.vuepress/csv/1.0.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | {
3 | title: 'Getting Started',
4 | collapsable: false,
5 | children: prefix('getting-started', [
6 | '',
7 | 'license',
8 | 'installation',
9 | 'contributing',
10 | 'support',
11 | ]),
12 | },
13 | {
14 | title: 'Exports',
15 | collapsable: false,
16 | children: prefix('exports', [
17 | '',
18 | 'collection',
19 | 'store',
20 | 'exportables',
21 | 'from-query',
22 | 'queued',
23 | 'mapping',
24 | 'heading-row',
25 | 'configuration',
26 | 'concerns',
27 | ]),
28 | },
29 | ];
30 |
31 | function prefix(prefix, children) {
32 | return children.map(child => `${prefix}/${child}`)
33 | }
34 |
--------------------------------------------------------------------------------
/.vuepress/nova/1.x.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | {
3 | title: 'Getting Started',
4 | collapsable: false,
5 | children: prefix('getting-started', [
6 | '',
7 | 'license',
8 | 'installation',
9 | 'contributing',
10 | 'support',
11 | ]),
12 | },
13 | {
14 | title: 'Exports',
15 | collapsable: false,
16 | children: prefix('exports', [
17 | '',
18 | 'download',
19 | 'store',
20 | 'queued',
21 | 'customizations',
22 | 'interactions'
23 | ]),
24 | },
25 | ];
26 |
27 | function prefix(prefix, children) {
28 | return children.map(child => `${prefix}/${child}`)
29 | }
30 |
--------------------------------------------------------------------------------
/.vuepress/public/android-chrome-192x192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SpartnerNL/laravel-excel-docs/857f2ed0b7dd2a386a343c72069313dfa2b48a39/.vuepress/public/android-chrome-192x192.png
--------------------------------------------------------------------------------
/.vuepress/public/android-chrome-512x512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SpartnerNL/laravel-excel-docs/857f2ed0b7dd2a386a343c72069313dfa2b48a39/.vuepress/public/android-chrome-512x512.png
--------------------------------------------------------------------------------
/.vuepress/public/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SpartnerNL/laravel-excel-docs/857f2ed0b7dd2a386a343c72069313dfa2b48a39/.vuepress/public/apple-touch-icon.png
--------------------------------------------------------------------------------
/.vuepress/public/assets/img/logo-small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SpartnerNL/laravel-excel-docs/857f2ed0b7dd2a386a343c72069313dfa2b48a39/.vuepress/public/assets/img/logo-small.png
--------------------------------------------------------------------------------
/.vuepress/public/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SpartnerNL/laravel-excel-docs/857f2ed0b7dd2a386a343c72069313dfa2b48a39/.vuepress/public/favicon-16x16.png
--------------------------------------------------------------------------------
/.vuepress/public/favicon-32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SpartnerNL/laravel-excel-docs/857f2ed0b7dd2a386a343c72069313dfa2b48a39/.vuepress/public/favicon-32x32.png
--------------------------------------------------------------------------------
/.vuepress/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SpartnerNL/laravel-excel-docs/857f2ed0b7dd2a386a343c72069313dfa2b48a39/.vuepress/public/favicon.ico
--------------------------------------------------------------------------------
/.vuepress/public/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SpartnerNL/laravel-excel-docs/857f2ed0b7dd2a386a343c72069313dfa2b48a39/.vuepress/public/icon.png
--------------------------------------------------------------------------------
/.vuepress/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Laravel Excel",
3 | "short_name": "Laravel Excel",
4 | "theme_color": "#3e446b",
5 | "background_color": "#3e446b",
6 | "display": "standalone",
7 | "start_url": "/3.1/getting-started/",
8 | "icons": [
9 | {
10 | "src": "/android-chrome-192x192.png",
11 | "sizes": "192x192",
12 | "type": "image/png"
13 | },
14 | {
15 | "src": "/android-chrome-512x512.png",
16 | "sizes": "512x512",
17 | "type": "image/png"
18 | }
19 | ]
20 | }
--------------------------------------------------------------------------------
/.vuepress/public/mstile-150x150.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SpartnerNL/laravel-excel-docs/857f2ed0b7dd2a386a343c72069313dfa2b48a39/.vuepress/public/mstile-150x150.png
--------------------------------------------------------------------------------
/.vuepress/styles/palette.styl:
--------------------------------------------------------------------------------
1 | $accentColor = #f5a823
2 | $MQMobile = 992px
3 | $codeBgColor = #282828
4 | $navbarHeight=4rem
5 | $nprogressColor = #f5a823
6 | $sidebarWidth=15rem
7 |
--------------------------------------------------------------------------------
/.vuepress/theme/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2018-present, Yuxi (Evan) You
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.vuepress/theme/components/DropdownTransition.vue:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
28 |
29 |
34 |
--------------------------------------------------------------------------------
/.vuepress/theme/components/NavLink.vue:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
23 |
53 |
--------------------------------------------------------------------------------
/.vuepress/theme/components/Sidebar.vue:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
80 |
81 |
112 |
--------------------------------------------------------------------------------
/.vuepress/theme/components/SidebarButton.vue:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
28 |
--------------------------------------------------------------------------------
/.vuepress/theme/components/SidebarGroup.vue:
--------------------------------------------------------------------------------
1 |
2 |
31 |
32 |
33 |
43 |
44 |
78 |
--------------------------------------------------------------------------------
/.vuepress/theme/global-components/Badge.vue:
--------------------------------------------------------------------------------
1 |
22 |
23 |
45 |
--------------------------------------------------------------------------------
/.vuepress/theme/index.js:
--------------------------------------------------------------------------------
1 | const path = require('path')
2 |
3 | // Theme API.
4 | module.exports = (options, ctx) => ({
5 | alias() {
6 | const {themeConfig, siteConfig} = ctx
7 | // resolve algolia
8 | const isAlgoliaSearch = (
9 | themeConfig.algolia ||
10 | Object.keys(siteConfig.locales && themeConfig.locales || {})
11 | .some(base => themeConfig.locales[base].algolia)
12 | )
13 | return {
14 | '@AlgoliaSearchBox': isAlgoliaSearch
15 | ? path.resolve(__dirname, 'components/AlgoliaSearchBox.vue')
16 | : path.resolve(__dirname, 'noopModule.js')
17 | }
18 | },
19 |
20 | plugins: [
21 | ['@vuepress/active-header-links', options.activeHeaderLinks],
22 | '@vuepress/search',
23 | '@vuepress/plugin-nprogress',
24 | ['container', {
25 | type: 'tip',
26 | defaultTitle: {
27 | '/zh/': '提示'
28 | }
29 | }],
30 | ['container', {
31 | type: 'warning',
32 | defaultTitle: {
33 | '/zh/': '注意'
34 | }
35 | }],
36 | ['container', {
37 | type: 'danger',
38 | defaultTitle: {
39 | '/zh/': '警告'
40 | }
41 | }],
42 | ]
43 | })
44 |
--------------------------------------------------------------------------------
/.vuepress/theme/layouts/404.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
404
5 |
{{ getMsg() }}
6 |
Take me home.
7 |
8 |
9 |
10 |
11 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.vuepress/theme/noopModule.js:
--------------------------------------------------------------------------------
1 | export default {}
2 |
--------------------------------------------------------------------------------
/.vuepress/theme/styles/arrow.styl:
--------------------------------------------------------------------------------
1 | @require './config'
2 |
3 | .arrow
4 | display inline-block
5 | width 0
6 | height 0
7 | &.up
8 | border-left 4px solid transparent
9 | border-right 4px solid transparent
10 | border-bottom 6px solid $arrowBgColor
11 | &.down
12 | border-left 4px solid transparent
13 | border-right 4px solid transparent
14 | border-top 6px solid $arrowBgColor
15 | &.right
16 | border-top 4px solid transparent
17 | border-bottom 4px solid transparent
18 | border-left 6px solid $arrowBgColor
19 | &.left
20 | border-top 4px solid transparent
21 | border-bottom 4px solid transparent
22 | border-right 6px solid $arrowBgColor
23 |
--------------------------------------------------------------------------------
/.vuepress/theme/styles/custom-blocks.styl:
--------------------------------------------------------------------------------
1 | .custom-block
2 | .custom-block-title
3 | font-weight 700
4 | margin-bottom -0.4rem
5 | &.tip, &.warning, &.danger
6 | padding .1rem 1.5rem
7 | border-left-width .5rem
8 | border-left-style solid
9 | margin 1rem 0
10 | &.tip
11 | background-color #f3f5f7
12 | border-color #1c78e6
13 | &.warning
14 | background-color rgba(255,229,100,.3)
15 | border-color darken(#ffe564, 35%)
16 | color darken(#ffe564, 70%)
17 | .custom-block-title
18 | color darken(#ffe564, 50%)
19 | a
20 | color $textColor
21 | &.danger
22 | background-color #ffe6e6
23 | border-color darken(red, 20%)
24 | color darken(red, 70%)
25 | .custom-block-title
26 | color darken(red, 40%)
27 | a
28 | color $textColor
29 |
30 | pre.vue-container
31 | border-left-width: .5rem;
32 | border-left-style: solid;
33 | border-color: $accentColor;
34 | border-radius: 0px;
35 | & > code
36 | font-size: 14px !important;
37 | & > p
38 | margin: -5px 0 -20px 0;
39 | code
40 | background-color: $accentColor !important;
41 | border none
42 | padding: 3px 5px;
43 | border-radius: 3px;
44 | color #000
45 | em
46 | color #adadad
47 | font-weight light
48 |
49 | .language-text.line-numbers-mode, .language-.line-numbers-mode, .language-shell.line-numbers-mode
50 | .line-numbers-wrapper
51 | display none
52 | &::after
53 | display none
54 | pre
55 | padding-left 2rem !important
56 |
57 | .language-shell.line-numbers-mode
58 | pre::before
59 | color #808080
60 | margin-right 10px
61 | content "$"
62 |
63 | .inline-step
64 | background $accentColor
65 | color: white;
66 | border-radius 100%
67 | width 1.6rem
68 | height 1.6rem
69 | font-weight 700
70 | font-size 14px
71 | display inline-flex
72 | align-items center
73 | justify-content center
74 | margin-right 5px
75 |
76 | .with-steps .content__default
77 | position relative
78 |
79 | .step
80 | background $accentColor
81 | color: white;
82 | border-radius 100%
83 | font-size 15px
84 | width 1.5rem
85 | height 1.5rem
86 | display inline-flex
87 | align-items center
88 | justify-content center
89 | position absolute
90 | right 0
91 | margin-right 32px
92 | margin-top 6px
93 |
--------------------------------------------------------------------------------
/.vuepress/theme/styles/mobile.styl:
--------------------------------------------------------------------------------
1 | @require './config'
2 |
3 | $mobileSidebarWidth = $sidebarWidth * 0.82
4 |
5 | // narrow desktop / iPad
6 | @media (max-width: $MQNarrow)
7 | .sidebar
8 | font-size 15px
9 | width $mobileSidebarWidth
10 | .page
11 | padding-left $mobileSidebarWidth
12 |
13 | // wide mobile
14 | @media (max-width: $MQMobile)
15 | .sidebar
16 | top 0
17 | padding-top $navbarHeight
18 | transform translateX(-100%)
19 | transition transform .2s ease
20 | .page
21 | padding-left 0
22 | .theme-container
23 | &.sidebar-open
24 | .sidebar
25 | transform translateX(0)
26 | &.no-navbar
27 | .sidebar
28 | padding-top: 0
29 |
30 | // narrow mobile
31 | @media (max-width: $MQMobileNarrow)
32 | h1
33 | font-size 1.9rem
34 | .content__default
35 | div[class*="language-"]
36 | margin 0.85rem -1.5rem
37 | border-radius 0
38 |
--------------------------------------------------------------------------------
/.vuepress/theme/styles/toc.styl:
--------------------------------------------------------------------------------
1 | .table-of-contents
2 | .badge
3 | vertical-align middle
4 |
--------------------------------------------------------------------------------
/.vuepress/theme/styles/wrapper.styl:
--------------------------------------------------------------------------------
1 | $wrapper
2 | max-width $contentWidth
3 | margin 0 auto
4 | padding 1.5rem 1.75em
5 | @media (max-width: $MQNarrow)
6 | padding 2rem
7 | @media (max-width: $MQMobileNarrow)
8 | padding 1.5rem
9 |
10 |
--------------------------------------------------------------------------------
/2.1/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/2.1/blade/load-view.md:
--------------------------------------------------------------------------------
1 | # @Blade to Excel
2 |
3 | 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, ...
4 |
5 | # Loading a view for a single sheet
6 |
7 | We can load a view for every sheet we create with `->loadView()`.
8 |
9 | Excel::create('New file', function($excel) {
10 |
11 | $excel->sheet('New sheet', function($sheet) {
12 |
13 | $sheet->loadView('folder.view');
14 |
15 | });
16 |
17 | });
18 |
19 | # Using different views for different sheets
20 |
21 | Excel::create('New file', function($excel) {
22 |
23 | $excel->sheet('First sheet', function($sheet) {
24 |
25 | $sheet->loadView('view_first');
26 | });
27 |
28 | $excel->sheet('Second sheet', function($sheet) {
29 |
30 | $sheet->loadView('view_second');
31 | });
32 |
33 | });
34 |
35 | # Sharing a view for all sheets
36 |
37 | We can share a view for all sheets with `shareView()`.
38 |
39 | Excel::shareView('folder.view')->create();
40 |
41 | # Unsetting a view for a sheet
42 |
43 | When we are using a shared view, but we don't want to use a view for the current sheet, we can use `->unsetView()`.
44 |
45 | $sheet->unsetView();
--------------------------------------------------------------------------------
/2.1/blade/vars.md:
--------------------------------------------------------------------------------
1 | # Passing variables to the view
2 |
3 | ### As parameter
4 |
5 | We can pass variables to the view by using the second parameter inside the `loadView()` method.
6 |
7 | $sheet->loadView('view', array('key' => 'value'));
8 |
9 | ### With with()
10 |
11 | Alternatively you can use the `with()` method which works the same as with Laravel views.
12 |
13 | // Using normal with()
14 | $sheet->loadView('view')
15 | ->with('key', 'value');
16 |
17 | // using dynamic with()
18 | $sheet->loadView('view')
19 | ->withKey('value');
--------------------------------------------------------------------------------
/2.1/changelog/version-2.md:
--------------------------------------------------------------------------------
1 | # Version 2
2 |
3 | ### 2.0.4
4 | - PHPExcel 1.8.1 compatibility
5 | - Clean-up ServiceProvider
6 |
7 | ### 2.0.3
8 | - Fix usage of sheet callback when modifying an existing file
9 | - Modifying existing files improvements (support style overriding)
10 | - Add text-indent support to HtmlReader
11 | - Add simple sheet password protection
12 | - Add support for exporting multiple pdf pages
13 | - Add inline cell formatting to Blade
14 |
15 | ### 2.0.2
16 | - Fix issue with different start row in chunk filter
17 |
18 | ### 2.0.1
19 | - Custom value binders
20 | - Html reader update
21 |
22 | ### 2.0.0
23 | - Laravel 5 release
24 |
--------------------------------------------------------------------------------
/2.1/export/README.md:
--------------------------------------------------------------------------------
1 | # Simple Excel Export
2 |
3 | ### Basics
4 |
5 | A new file can be created using the `create` method with the filename as first parameter.
6 |
7 | Excel::create('Filename');
8 |
9 | To manipulate the creation of the file you can use the callback with `LaravelExcelWriter` parameter
10 |
11 | Excel::create('Filename', function($excel) {
12 |
13 | // Call writer methods here
14 |
15 | });
16 |
17 | ### Changing properties
18 |
19 | 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`.
20 |
21 | Excel::create('Filename', function($excel) {
22 |
23 | // Set the title
24 | $excel->setTitle('Our new awesome title');
25 |
26 | // Chain the setters
27 | $excel->setCreator('Maatwebsite')
28 | ->setCompany('Maatwebsite');
29 |
30 | // Call them separately
31 | $excel->setDescription('A demonstration to change the file properties');
32 |
33 | });
34 |
35 | > Go to the reference guide to see a list of available properties.
36 |
--------------------------------------------------------------------------------
/2.1/export/array.md:
--------------------------------------------------------------------------------
1 | # Creating a sheet from an array
2 |
3 | ## Array
4 |
5 | To create a new file from an array use `->fromArray($source, $nullValue, $startCell, $strictNullComparison, $headingGeneration)` inside the sheet closure.
6 |
7 | Excel::create('Filename', function($excel) {
8 |
9 | $excel->sheet('Sheetname', function($sheet) {
10 |
11 | $sheet->fromArray(array(
12 | array('data1', 'data2'),
13 | array('data3', 'data4')
14 | ));
15 |
16 | });
17 |
18 | })->export('xls');
19 |
20 | Alternatively you can use `->with()`.
21 |
22 | $sheet->with(array(
23 | array('data1', 'data2'),
24 | array('data3', 'data4')
25 | ));
26 |
27 | If you want to pass variables inside the closure, use `use($data)`
28 |
29 | $data = array(
30 | array('data1', 'data2'),
31 | array('data3', 'data4')
32 | );
33 |
34 | Excel::create('Filename', function($excel) use($data) {
35 |
36 | $excel->sheet('Sheetname', function($sheet) use($data) {
37 |
38 | $sheet->fromArray($data);
39 |
40 | });
41 |
42 | })->export('xls');
43 |
44 | ### Null comparision
45 |
46 | By default 0 is shown as an empty cell. If you want to change this behaviour, you can pass true as 4th parameter:
47 |
48 | // Will show 0 as 0
49 | $sheet->fromArray($data, null, 'A1', true);
50 |
51 | > To change the default behaviour, you can use `excel::export.sheets.strictNullComparison` config setting.
52 |
53 | ## Eloquent model
54 |
55 | It's also possible to pass an Eloquent model and export it by using `->fromModel($model)`. The method accepts the same parameters as fromArray
56 |
57 | ## Auto heading generation
58 |
59 | 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:
60 |
61 | // Won't auto generate heading columns
62 | $sheet->fromArray($data, null, 'A1', false, false);
--------------------------------------------------------------------------------
/2.1/export/autofilter.md:
--------------------------------------------------------------------------------
1 | # Auto filter
2 |
3 | To enable the auto filter use `->setAutoFilter($range = false)`.
4 |
5 | // Auto filter for entire sheet
6 | $sheet->setAutoFilter();
7 |
8 | // Set auto filter for a range
9 | $sheet->setAutoFilter('A1:E10');
--------------------------------------------------------------------------------
/2.1/export/autosize.md:
--------------------------------------------------------------------------------
1 | # Auto size
2 |
3 | By default the exported file be automatically auto sized. To change this behaviour you can either change the config or use the setters:
4 |
5 | // Set auto size for sheet
6 | $sheet->setAutoSize(true);
7 |
8 | // Disable auto size for sheet
9 | $sheet->setAutoSize(false);
10 |
11 | // Disable auto size for columns
12 | $sheet->setAutoSize(array(
13 | 'A', 'C'
14 | ));
15 |
16 | > The default config setting can be found in: `export.php`.
--------------------------------------------------------------------------------
/2.1/export/call.md:
--------------------------------------------------------------------------------
1 | # Calling PHPExcel's native methods
2 |
3 | It's possible to call all native PHPExcel methods on the `$excel` and `$sheet` objects.
4 |
5 | ### Calling Workbook methods
6 |
7 | Example:
8 |
9 | // Get default style for this workbook
10 | $excel->getDefaultStyle();
11 |
12 | ### Calling worksheet methods
13 |
14 | Example:
15 |
16 | // Protect cells
17 | $sheet->protectCells('A1', $password);
18 |
19 | > Head over to PHPOffice to learn more about the native methods.
--------------------------------------------------------------------------------
/2.1/export/cells.md:
--------------------------------------------------------------------------------
1 | # Cell manipulation
2 |
3 | $sheet->cell('A1', function($cell) {
4 |
5 | // manipulate the cell
6 | $cell->setValue('data1');
7 |
8 | });
9 |
10 | $sheet->cells('A1:A5', function($cells) {
11 |
12 | // manipulate the range of cells
13 |
14 | });
15 |
16 | ### Set background
17 |
18 | To change the background of a range of cells we can use `->setBackground($color, $type, $colorType)`
19 |
20 | // Set black background
21 | $cells->setBackground('#000000');
22 |
23 | ### Change fonts
24 |
25 | // Set with font color
26 | $cells->setFontColor('#ffffff');
27 |
28 | // Set font family
29 | $cells->setFontFamily('Calibri');
30 |
31 | // Set font size
32 | $cells->setFontSize(16);
33 |
34 | // Set font weight to bold
35 | $cells->setFontWeight('bold');
36 |
37 | // Set font
38 | $cells->setFont(array(
39 | 'family' => 'Calibri',
40 | 'size' => '16',
41 | 'bold' => true
42 | ));
43 |
44 | ### Set borders
45 |
46 | // Set all borders (top, right, bottom, left)
47 | $cells->setBorder('solid', 'none', 'none', 'solid');
48 |
49 | // Set borders with array
50 | $cells->setBorder(array(
51 | 'top' => array(
52 | 'style' => 'solid'
53 | ),
54 | ));
55 |
56 | ### Set horizontal alignment
57 |
58 | // Set alignment to center
59 | $cells->setAlignment('center');
60 |
61 | ### Set vertical alignment
62 |
63 | // Set vertical alignment to middle
64 | $cells->setValignment('center');
65 |
--------------------------------------------------------------------------------
/2.1/export/export.md:
--------------------------------------------------------------------------------
1 | # Exporting
2 |
3 | To download the created file, use `->export($ext)` or `->download($ext)`.
4 |
5 | #### Export to Excel5 (xls)
6 |
7 | Excel::create('Filename', function($excel) {
8 |
9 | })->export('xls');
10 |
11 | // or
12 | ->download('xls');
13 |
14 | #### Export to Excel2007 (xlsx)
15 |
16 | ->export('xlsx');
17 |
18 | // or
19 | ->download('xlsx');
20 |
21 | #### Export to CSV
22 |
23 | ->export('csv');
24 |
25 | // or
26 | ->download('csv');
27 |
28 | > You can set the default enclosure and delimiter inside the config
29 |
30 | #### Export to PDF
31 |
32 | To export files to pdf, you will have to include `"dompdf/dompdf": "~0.6.1"`, `"mpdf/mpdf": "~6.1"` or `"tecnick.com/tcpdf": "~6.0.0"` in your `composer.json` and change the `export.pdf.driver` config setting accordingly.
33 |
34 | ->export('pdf');
35 |
--------------------------------------------------------------------------------
/2.1/export/format.md:
--------------------------------------------------------------------------------
1 | # Column formatting
2 |
3 | To tell Excel how it should interpret certain columns, you can use `->setColumnFormat($array)`.
4 |
5 | // Format column as percentage
6 | $sheet->setColumnFormat(array(
7 | 'C' => '0%'
8 | ));
9 |
10 | // Format a range with e.g. leading zeros
11 | $sheet->setColumnFormat(array(
12 | 'A2:K2' => '0000'
13 | ));
14 |
15 | // Set multiple column formats
16 | $sheet->setColumnFormat(array(
17 | 'B' => '0',
18 | 'D' => '0.00',
19 | 'F' => '@',
20 | 'F' => 'yyyy-mm-dd',
21 | ));
22 |
23 | > Go to the reference guide to see a list of available formats.
24 |
--------------------------------------------------------------------------------
/2.1/export/freeze.md:
--------------------------------------------------------------------------------
1 | # Freeze rows
2 |
3 | If you want to freeze a cell, row or column, use:
4 |
5 | // Freeze first row
6 | $sheet->freezeFirstRow();
7 |
8 | // Freeze the first column
9 | $sheet->freezeFirstColumn();
10 |
11 | // Freeze the first row and column
12 | $sheet->freezeFirstRowAndColumn();
13 |
14 | // Set freeze
15 | $sheet->setFreeze('A2');
--------------------------------------------------------------------------------
/2.1/export/injection.md:
--------------------------------------------------------------------------------
1 | # NewExcelFile injections
2 |
3 | Following the Laravel 5.0 philosophy with its new awesome FormRequest injections, we introduce you NewExcelFile injections.
4 |
5 | ## NewExcelFile class
6 |
7 | This NewExcelFile is a wrapper for a new Excel file. Inside the `getFilename()` you can declare the wanted filename.
8 |
9 | class UserListExport extends \Maatwebsite\Excel\Files\NewExcelFile {
10 |
11 | public function getFilename()
12 | {
13 | return 'filename';
14 | }
15 | }
16 |
17 | ## Usage
18 |
19 | You can inject these NewExcelFiles inside the __constructor or inside the method (when using Laravel 5.0), in e.g. the controller.
20 |
21 | class ExampleController extends Controller {
22 |
23 | public function exportUserList(UserListExport $export)
24 | {
25 | // work on the export
26 | return $export->sheet('sheetName', function($sheet)
27 | {
28 |
29 | })->export('xls');
30 | }
31 |
32 | }
33 |
34 | ## Export Handlers
35 |
36 | To decouple your Excel-export code completely from the controller, you can use the export handlers.
37 |
38 | class ExampleController extends Controller {
39 |
40 | public function exportUserList(UserListExport $export)
41 | {
42 | // Handle the export
43 | $export->handleExport();
44 | }
45 |
46 | }
47 |
48 | The `handleExport()` method will dynamically call a handler class which is your class name appended with `Handler`
49 |
50 | class UserListExportHandler implements \Maatwebsite\Excel\Files\ExportHandler {
51 |
52 | public function handle(UserListExport $export)
53 | {
54 | // work on the export
55 | return $export->sheet('sheetName', function($sheet)
56 | {
57 |
58 | })->export('xls');
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/2.1/export/merge.md:
--------------------------------------------------------------------------------
1 | # Column merging
2 |
3 | ### Merging cells
4 |
5 | To merge a range of cells, use `->mergeCells($range)`.
6 |
7 | $sheet->mergeCells('A1:E1');
8 |
9 | ### Merging columns and rows
10 |
11 | To merge columns and rows, use `->setMergeColumn($array)`.
12 |
13 | $sheet->setMergeColumn(array(
14 | 'columns' => array('A','B','C','D'),
15 | 'rows' => array(
16 | array(2,3),
17 | array(5,11),
18 | )
19 | ));
--------------------------------------------------------------------------------
/2.1/export/rows.md:
--------------------------------------------------------------------------------
1 | # Row manipulation
2 |
3 | ### Manipulate certain row
4 |
5 | #### Change cell values
6 |
7 | // Manipulate first row
8 | $sheet->row(1, array(
9 | 'test1', 'test2'
10 | ));
11 |
12 | // Manipulate 2nd row
13 | $sheet->row(2, array(
14 | 'test3', 'test4'
15 | ));
16 |
17 | #### Manipulate row cells
18 |
19 | // Set black background
20 | $sheet->row(1, function($row) {
21 |
22 | // call cell manipulation methods
23 | $row->setBackground('#000000');
24 |
25 | });
26 |
27 | ### Append row
28 |
29 | // Append row after row 2
30 | $sheet->appendRow(2, array(
31 | 'appended', 'appended'
32 | ));
33 |
34 | // Append row as very last
35 | $sheet->appendRow(array(
36 | 'appended', 'appended'
37 | ));
38 |
39 | ### Prepend row
40 |
41 | // Add before first row
42 | $sheet->prependRow(1, array(
43 | 'prepended', 'prepended'
44 | ));
45 |
46 | // Add as very first
47 | $sheet->prependRow(array(
48 | 'prepended', 'prepended'
49 | ));
50 |
51 | ### Append multiple rows
52 |
53 | // Append multiple rows
54 | $sheet->rows(array(
55 | array('test1', 'test2'),
56 | array('test3', 'test4')
57 | ));
58 |
59 | // Append multiple rows
60 | $sheet->rows(array(
61 | array('test5', 'test6'),
62 | array('test7', 'test8')
63 | ));
--------------------------------------------------------------------------------
/2.1/export/sheet-styling.md:
--------------------------------------------------------------------------------
1 | # Sheet styling
2 |
3 | ### General styling
4 |
5 | If you want to change the general styling of your sheet (not cell or range specific), you can use the `->setStyle()` method.
6 |
7 | // Set font with ->setStyle()`
8 | $sheet->setStyle(array(
9 | 'font' => array(
10 | 'name' => 'Calibri',
11 | 'size' => 15,
12 | 'bold' => true
13 | )
14 | ));
15 |
16 | ### Fonts
17 |
18 | To change the font for the current sheet use `->setFont($array)`:
19 |
20 | $sheet->setFont(array(
21 | 'family' => 'Calibri',
22 | 'size' => '15',
23 | 'bold' => true
24 | ));
25 |
26 | #### Separate setters
27 |
28 | // Font family
29 | $sheet->setFontFamily('Comic Sans MS');
30 |
31 | // Font size
32 | $sheet->setFontSize(15);
33 |
34 | // Font bold
35 | $sheet->setFontBold(true);
36 |
37 | ### Borders
38 |
39 | You can set borders for the sheet, by using:
40 |
41 | // Sets all borders
42 | $sheet->setAllBorders('thin');
43 |
44 | // Set border for cells
45 | $sheet->setBorder('A1', 'thin');
46 |
47 | // Set border for range
48 | $sheet->setBorder('A1:F10', 'thin');
49 |
50 | > Go to the reference guide to see a list of available border styles
--------------------------------------------------------------------------------
/2.1/export/sheets.md:
--------------------------------------------------------------------------------
1 | # Sheets
2 |
3 | ### Creating a sheet
4 |
5 | To create a new sheet inside our newly created file, use `->sheet('Sheetname')` with callback of `LaravelExcelWorksheet` type parameter.
6 |
7 | Excel::create('Filename', function($excel) {
8 |
9 | $excel->sheet('Sheetname', function($sheet) {
10 |
11 | // Sheet manipulation
12 |
13 | });
14 |
15 | })->export('xls');
16 |
17 |
18 | ### Creating multiple sheets
19 |
20 | You can set as many sheets as you like inside the file:
21 |
22 | Excel::create('Filename', function($excel) {
23 |
24 | // Our first sheet
25 | $excel->sheet('First sheet', function($sheet) {
26 |
27 | });
28 |
29 | // Our second sheet
30 | $excel->sheet('Second sheet', function($sheet) {
31 |
32 | });
33 |
34 | })->export('xls');
35 |
36 | ### Changing properties
37 |
38 | 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`.
39 |
40 | Excel::create('Filename', function($excel) {
41 |
42 | $excel->sheet('Sheetname', function($sheet) {
43 |
44 | $sheet->setOrientation('landscape');
45 |
46 | });
47 |
48 | })->export('xls');
49 |
50 | > Go to the reference guide to see a list of available properties.
51 |
52 | ### Default page margin
53 |
54 | It's possible to set the default page margin inside the config file `excel::export.sheets`.
55 | It accepts boolean, single value or array.
56 |
57 | To manually set the page margin you can use: `->setPageMargin()`
58 |
59 | // Set top, right, bottom, left
60 | $sheet->setPageMargin(array(
61 | 0.25, 0.30, 0.25, 0.30
62 | ));
63 |
64 | // Set all margins
65 | $sheet->setPageMargin(0.25);
66 |
67 | ### Password protecting a sheet
68 |
69 | A sheet can be password protected with `$sheet->protect()`:
70 |
71 | // Default protect
72 | $sheet->protect('password');
73 |
74 | // Advanced protect
75 | $sheet->protect('password', function(\PHPExcel_Worksheet_Protection $protection) {
76 | $protection->setSort(true);
77 | });
78 |
--------------------------------------------------------------------------------
/2.1/export/sizing.md:
--------------------------------------------------------------------------------
1 | # Cell size
2 |
3 | ### Set column width
4 |
5 | To set the column width use `->setWidth($cell, $width)`.
6 |
7 | // Set width for a single column
8 | $sheet->setWidth('A', 5);
9 |
10 | // Set width for multiple cells
11 | $sheet->setWidth(array(
12 | 'A' => 5,
13 | 'B' => 10
14 | ));
15 |
16 | ### Set row height
17 |
18 | To set the row height use `->setHeight($row, $height)`.
19 |
20 | // Set height for a single row
21 | $sheet->setHeight(1, 50);
22 |
23 | // Set height for multiple rows
24 | $sheet->setHeight(array(
25 | 1 => 50,
26 | 2 => 25
27 | ));
28 |
29 | ### Set cell size
30 |
31 | To set the cell size use `->setSize($cell, $width, $height)`.
32 |
33 | // Set size for a single cell
34 | $sheet->setSize('A1', 500, 50);
35 |
36 | $sheet->setSize(array(
37 | 'A1' => array(
38 | 'width' => 50,
39 | 'height' => 500
40 | )
41 | ));
42 |
--------------------------------------------------------------------------------
/2.1/export/store.md:
--------------------------------------------------------------------------------
1 | # Store on server
2 |
3 | To store the created file on the server, use `->store($ext, $path = false, $returnInfo = false)` or `->save()`.
4 |
5 | ### Normal export to default storage path
6 |
7 | By default the file will be stored inside the `storage/exports` folder, which has been defined in the `export.php` config file.
8 |
9 | Excel::create('Filename', function($excel) {
10 |
11 | // Set sheets
12 |
13 | })->store('xls');
14 |
15 | ### Normal export to custom storage path
16 |
17 | 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.
18 |
19 | ->store('xls', storage_path('excel/exports'));
20 |
21 | ### Store and export
22 |
23 | ->store('xls')->export('xls');
24 |
25 | ### Store and return storage info
26 |
27 | If you want to return storage information, set the third paramter to true or change the config setting inside `export.php`.
28 |
29 | ->store('xls', false, true);
30 |
31 | |Key|Explanation|
32 | |---|-----------|
33 | |**full**| Full path with filename
34 | |**path**| Path without filename
35 | |**file**| Filename
36 | |**title**| File title
37 | |**ext**| File extension
38 |
39 | > Make sure your storage folder is **writable**!
40 |
--------------------------------------------------------------------------------
/2.1/getting-started/README.md:
--------------------------------------------------------------------------------
1 | # Installation
2 |
3 | Require this package in your `composer.json` and update composer. This will download the package and PHPExcel of PHPOffice.
4 |
5 | #### Laravel 4
6 |
7 | "maatwebsite/excel": "~1.3"
8 |
9 | #### Laravel 5
10 |
11 | "maatwebsite/excel": "~2.1.0"
12 |
13 | After updating composer, add the ServiceProvider to the providers array in `app/config/app.php`
14 |
15 | Maatwebsite\Excel\ExcelServiceProvider::class,
16 |
17 | You can use the facade for shorter code. Add this to your aliasses:
18 |
19 | 'Excel' => Maatwebsite\Excel\Facades\Excel::class,
20 |
21 | The class is binded to the ioC as `excel`
22 |
23 | $excel = App::make('excel');
24 |
--------------------------------------------------------------------------------
/2.1/getting-started/config.md:
--------------------------------------------------------------------------------
1 | # Config
2 |
3 | ### Laravel 4
4 |
5 | Laravel Excel includes several config settings for import-, export-, view- and CSV-specific settings.
6 | Use the artisan publish command to publish the config file to your project.
7 |
8 | php artisan config:publish maatwebsite/excel
9 |
10 | The config files can now be found at `app/config/packages/maatwebsite/excel`
11 |
12 | ### Laravel 5
13 |
14 | To publish the config settings in Laravel 5 use:
15 |
16 | php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider"
17 |
18 | This will add an `excel.php` config file to your config folder.
19 |
--------------------------------------------------------------------------------
/2.1/getting-started/contributing.md:
--------------------------------------------------------------------------------
1 | # Contribution Guide
2 |
3 | ### Bug fixes
4 |
5 | **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.
6 |
7 | ### Pull Requests
8 |
9 | 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.
10 |
11 | ### Feature Requests
12 |
13 | 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.
14 |
15 | ### Coding Guidelines
16 |
17 | 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:
18 |
19 | - Namespace declarations should be on the same line as `= 5.3.7
4 | - Laravel >= 4.1
5 | - PHPOffice PHPExcel >= 1.8.0 (included by composer.json)
6 | - PHP extension php_zip enabled (required if you need PHPExcel to handle .xlsx .ods or .gnumeric files)
7 | - PHP extension php_xml enabled
8 | - PHP extension php_gd2 enabled (optional, but required for exact column width autocalculation)
--------------------------------------------------------------------------------
/2.1/import/README.md:
--------------------------------------------------------------------------------
1 | # Importing a file
2 |
3 | To start importing a file, you can use `->load($filename)`. The callback is optional.
4 |
5 | Excel::load('file.xls', function($reader) {
6 |
7 | // reader methods
8 |
9 | });
10 |
--------------------------------------------------------------------------------
/2.1/import/batch.md:
--------------------------------------------------------------------------------
1 | # Batch import
2 |
3 | ### Import a folder
4 |
5 | To import an entire folder (only XLS, XLSX and CSV files will be imported), set the folder as the first parameter.
6 |
7 | Excel::batch('app/storage/uploads', function($rows, $file) {
8 |
9 | // Explain the reader how it should interpret each row,
10 | // for every file inside the batch
11 | $rows->each(function($row) {
12 |
13 | // Example: dump the firstname
14 | dd($row->firstname);
15 |
16 | });
17 |
18 | });
19 |
20 | ### Import multiple files
21 |
22 | It's also possible to provide an array of files to import.
23 |
24 | $files = array(
25 | 'file1.xls',
26 | 'file2.xls'
27 | );
28 |
29 | Excel::batch($files, function($rows, $file) {
30 |
31 | });
32 |
33 | ### Import a folder and multiple sheets
34 |
35 | When your files contain multiple sheets, you should also loop the sheets
36 |
37 | Excel::batch('app/storage/uploads', function($sheets, $file) {
38 |
39 | $sheets->each(function($sheet) {
40 |
41 | });
42 |
43 | });
--------------------------------------------------------------------------------
/2.1/import/cache.md:
--------------------------------------------------------------------------------
1 | # Caching and Cell caching
2 |
3 | ### Cell caching
4 |
5 | You can enable cell caching inside the config `excel.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.
6 |
7 | ### Remembering results
8 |
9 | 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.
10 |
11 | // Remember for 10 minutes
12 | $results = $reader->remember(10)->get();
--------------------------------------------------------------------------------
/2.1/import/calculation.md:
--------------------------------------------------------------------------------
1 | # Calculate formulas
2 |
3 | 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.
4 |
5 | If you want to enable/disable it for a single import, you can use `->calculate($boolean)`
6 |
7 | // Enable calculation
8 | $reader->calculate();
9 |
10 | // Disable calculation
11 | $reader->calculate(false);
12 |
--------------------------------------------------------------------------------
/2.1/import/chunk.md:
--------------------------------------------------------------------------------
1 | # Chunk importer
2 |
3 | When dealing with big files, it's better to import the data in big chunks. You can enable this with `filter('chunk')`;
4 | 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.
5 |
6 | Excel::filter('chunk')->load('file.csv')->chunk(250, function($results)
7 | {
8 | foreach($results as $row)
9 | {
10 | // do stuff
11 | }
12 | });
13 |
14 | ## ExcelFile class example:
15 |
16 | When working with ExcelFile injections (in the constructor or as method injection), you can enable the chunk filter inside the ExcelFile class
17 |
18 | class UserListImport extends \Maatwebsite\Excel\Files\ExcelFile {
19 |
20 | public function getFile()
21 | {
22 | return 'file.csv';
23 | }
24 |
25 | public function getFilters()
26 | {
27 | return [
28 | 'chunk'
29 | ];
30 | }
31 |
32 | }
33 |
34 | Injected ExcelFile example:
35 |
36 | public function importUserList(UserListImport $import)
37 | {
38 | $import->chunk(250, function($results)
39 | {
40 | // do stuff
41 | // or return true if you want to stop importing.
42 | });
43 | }
44 |
45 | ## Queued chunks
46 |
47 | We automatically queue every chunk for you, if you have enabled the queue driver in your config.
48 |
49 | If you want to by-pass the behaviour, you can pass `false` as the third parameter of `chunk($size, $callback, $shouldQueue)`.
50 |
51 | A non-default job queue may be specified by passing its name as the third parameter of `chunk($size, $callback, $shouldQueue)`.
52 |
--------------------------------------------------------------------------------
/2.1/import/config.md:
--------------------------------------------------------------------------------
1 | # Import by Config
2 |
3 | When using advanced Excel files (e.g. without any heading columns), it can be complicated to import these.
4 | `->byConfig()` will help you handle this problem.
5 |
6 | Inside `excel::import.sheets` config you can find an example.
7 |
8 | Excel::load('file.xls')->byConfig('excel::import.sheets', function($sheet) {
9 |
10 | // The firstname getter will correspond with a cell coordinate set inside the config
11 | $firstname = $sheet->firstname;
12 |
13 | });
14 |
15 | > **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()`.
--------------------------------------------------------------------------------
/2.1/import/convert.md:
--------------------------------------------------------------------------------
1 | # Converting
2 |
3 | You can convert from one filetype to another by using `->convert()`
4 |
5 | Excel::load('file.csv', function($file) {
6 |
7 | // modify stuff
8 |
9 | })->convert('xls');
--------------------------------------------------------------------------------
/2.1/import/dates.md:
--------------------------------------------------------------------------------
1 | # Dates
2 |
3 | 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`.
4 |
5 | To enable/disable date formatting for a single import, use `->formatDates($boolean, $format)`
6 |
7 | // Format the dates
8 | $reader->formatDates(true);
9 |
10 | // Disable date formatting
11 | $reader->formatDates(false);
12 |
13 | // Format dates + set date format
14 | $reader->formatDates(true, 'Y-m-d');
15 |
16 | ### Format dates
17 |
18 | By default the dates are **not formatted**, but returned as a Carbon object. There are a couple of options to format them.
19 |
20 | #### Formatting results after ->get()
21 |
22 | Inside your loop you can utilise the Carbon method `->format($dateFormat)`
23 |
24 | $rows->each(function($row) {
25 |
26 | $created_at = $row->created_at->format('Y-m-d');
27 |
28 | });
29 |
30 | #### Setting a default date format
31 |
32 | Inside the config you can set a default date format. A Carbon object will no longer be returned.
33 |
34 | Or you can use `->setDateFormat()`
35 |
36 | $reader->setDateFormat('Y-m-d');
37 |
38 | ### Setting custom date columns
39 |
40 | 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()`
41 |
42 | $reader->setDateColumns(array(
43 | 'created_at',
44 | 'deleted_at'
45 | ))->get();
46 |
--------------------------------------------------------------------------------
/2.1/import/edit.md:
--------------------------------------------------------------------------------
1 | # Editing existing files
2 |
3 | You can edit existing Excel files, by loading them and after modification exporting them.
4 |
5 | Excel::load('file.csv', function($file) {
6 |
7 | // modify stuff
8 |
9 | })->export('csv');
10 |
--------------------------------------------------------------------------------
/2.1/import/extra.md:
--------------------------------------------------------------------------------
1 | # Extra
2 |
3 | ### Disable using first row as collection attributes
4 |
5 | By default we will use the first row of a file as table heading (so as attribute names for the collection).
6 | You can change the default behaviour inside `import.php` with `import.heading`.
7 |
8 | To disable this for a single import, use `->noHeading()`.
9 |
10 | $reader->noHeading();
11 |
12 | ### Setting the cell name separator
13 | By default collection attribute names will be set by looking at the first row columns. Spaces will be translated to `_`.
14 |
15 | **E.g. Created at -> created_at**
16 |
17 | The default behaviour can be changed inside the `import.php` config by changing `'separator'`. Or you can use `->setSeparator($separator)`.
18 |
19 | $reader->setSeparator('-');
20 |
21 | ### Ignoring empty cells
22 | By default empty cells will not be ignored and presented as null inside the cell collection.
23 |
24 | To change the default behaviour, you can change `'ignoreEmpty`' inside `import.php` or use `->ignoreEmpty()`.
25 |
26 | $reader->ignoreEmpty();
27 |
28 | ### Input encoding
29 |
30 | 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!
31 |
32 | Optionally you can pass the input encoding inside the `->load()` method.
33 |
34 | // When utilising a closure, you can pass the input encoding as third parameter.
35 | Excel::load('filename.csv', function($reader) {
36 |
37 | }, 'UTF-8');
38 |
39 | // or without a closure, you can use it as second parameter.
40 | Excel::load('filename.csv', 'UTF-8');
41 |
42 | ### CSV Settings
43 |
44 | Inside the `csv.php` config you can change the default settings, like the `delimiter`, the `enclosure` and the `line_ending`.
45 |
--------------------------------------------------------------------------------
/2.1/import/formatting.md:
--------------------------------------------------------------------------------
1 | # Custom formatting values
2 |
3 | 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.
4 |
5 | use PHPExcel_Cell;
6 | use PHPExcel_Cell_DataType;
7 | use PHPExcel_Cell_IValueBinder;
8 | use PHPExcel_Cell_DefaultValueBinder;
9 |
10 | class MyValueBinder extends PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
11 | {
12 | public function bindValue(PHPExcel_Cell $cell, $value = null)
13 | {
14 | if (is_numeric($value))
15 | {
16 | $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_NUMERIC);
17 |
18 | return true;
19 | }
20 |
21 | // else return default behavior
22 | return parent::bindValue($cell, $value);
23 | }
24 | }
25 |
26 | $myValueBinder = new MyValueBinder;
27 |
28 | $reader = Excel::setValueBinder($myValueBinder)->load('file.xls');
29 | // Reader methods
30 |
31 | Available PHPExcel_Cell_DataType's are TYPE_STRING, TYPE_FORMULA, TYPE_NUMERIC, TYPE_BOOL, TYPE_NULL, TYPE_INLINE and TYPE_ERROR
32 |
33 | 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.
34 |
35 | Excel::resetValueBinder();
--------------------------------------------------------------------------------
/2.1/import/injection.md:
--------------------------------------------------------------------------------
1 | # ExcelFile injections
2 |
3 | Following the Laravel 5.0 philosophy with its new awesome FormRequest injections, we introduce you ExcelFile injections.
4 |
5 | ## ExcelFile class
6 |
7 | 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.
8 |
9 | class UserListImport extends \Maatwebsite\Excel\Files\ExcelFile {
10 |
11 | public function getFile()
12 | {
13 | return storage_path('exports') . '/file.csv';
14 | }
15 |
16 | public function getFilters()
17 | {
18 | return [
19 | 'chunk'
20 | ];
21 | }
22 |
23 | }
24 |
25 | If you want to have the `getFile()` dynamic based on user's input, you can easily do:
26 |
27 | public function getFile()
28 | {
29 | // Import a user provided file
30 | $file = Input::file('report');
31 | $filename = $this->doSomethingLikeUpload($file);
32 |
33 | // Return it's location
34 | return $filename;
35 | }
36 |
37 | ## Usage
38 |
39 | You can inject these ExcelFiles inside the __constructor or inside the method (when using Laravel 5.0), in e.g. the controller.
40 |
41 | class ExampleController extends Controller {
42 |
43 | public function importUserList(UserListImport $import)
44 | {
45 | // get the results
46 | $results = $import->get();
47 | }
48 |
49 | }
50 |
51 | ## CSV Settings
52 |
53 | You can pass through optional CSV settings, like `$delimiter`, `$enclosure` and `$lineEnding` as protected properties of the class.
54 |
55 | class UserListImport extends \Maatwebsite\Excel\Files\ExcelFile {
56 |
57 | protected $delimiter = ',';
58 | protected $enclosure = '"';
59 | protected $lineEnding = '\r\n';
60 |
61 | }
62 |
63 | ## Import Handlers
64 |
65 | To decouple your Excel-import code completely from the controller, you can use the import handlers.
66 |
67 | class ExampleController extends Controller {
68 |
69 | public function importUserList(UserListImport $import)
70 | {
71 | // Handle the import
72 | $import->handleImport();
73 | }
74 |
75 | }
76 |
77 | The `handleImport()` method will dynamically call a handler class which is your class name appended with `Handler`
78 |
79 | class UserListImportHandler implements \Maatwebsite\Excel\Files\ImportHandler {
80 |
81 | public function handle(UserListImport $import)
82 | {
83 | // get the results
84 | $results = $import->get();
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/2.1/import/select.md:
--------------------------------------------------------------------------------
1 | # Selecting sheets and columns
2 |
3 | ### Selecting one specific sheet
4 | If you want to select a single sheet, you can use `->selectSheets($name)`. Only that sheet will be loaded.
5 |
6 | Excel::selectSheets('sheet1')->load();
7 |
8 | ### Selecting multiple sheets
9 | If you want to select multiple sheets inside your file, you can pass an array as the parameter;
10 |
11 | Excel::selectSheets('sheet1', 'sheet2')->load();
12 |
13 | ### Selecting sheets by index
14 |
15 | // First sheet
16 | Excel::selectSheetsByIndex(0)->load();
17 |
18 | // First and second sheet
19 | Excel::selectSheetsByIndex(0, 1)->load();
20 |
21 | ### Selecting columns
22 |
23 | 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)`.
24 |
25 | // Select
26 | $reader->select(array('firstname', 'lastname'))->get();
27 |
28 | // Or
29 | $reader->get(array('firstname', 'lastname'));
30 |
31 | > All get methods (like all(), first(), dump(), toArray(), ...) accept an array of columns.
32 |
--------------------------------------------------------------------------------
/2.1/reference-guide/borders.md:
--------------------------------------------------------------------------------
1 | # Available border styles
2 |
3 | | Style name | PHPExcel class reference|
4 | | ------------- |-----------------|
5 | |none|PHPExcel_Style_Border::BORDER_NONE
6 | |dashDot|PHPExcel_Style_Border::BORDER_DASHDOT
7 | | dashDotDot|PHPExcel_Style_Border::BORDER_DASHDOTDOT
8 | | dashed |PHPExcel_Style_Border::BORDER_DASHED
9 | | dotted |PHPExcel_Style_Border::BORDER_DOTTED
10 | | double |PHPExcel_Style_Border::BORDER_DOUBLE
11 | | hair |PHPExcel_Style_Border::BORDER_HAIR
12 | | medium |PHPExcel_Style_Border::BORDER_MEDIUM
13 | | mediumDashDot |PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT
14 | | mediumDashDotDot |PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT
15 | | mediumDashed |PHPExcel_Style_Border::BORDER_MEDIUMDASHED
16 | | slantDashDot |PHPExcel_Style_Border::BORDER_SLANTDASHDOT
17 | | thick|PHPExcel_Style_Border::BORDER_THICK
18 | | thin|PHPExcel_Style_Border::BORDER_THIN
--------------------------------------------------------------------------------
/2.1/reference-guide/closures.md:
--------------------------------------------------------------------------------
1 | # Closures
2 |
3 | | Method | Closure class |
4 | | ------------- |-------------|
5 | | create() | Maatwebsite\Excel\Writers\LaravelExcelWriter |
6 | | load() | Maatwebsite\Excel\Readers\LaravelExcelReader |
7 | | batch | Maatwebsite\Excel\Readers\Batch |
8 | | sheet() | Maatwebsite\Excel\Classes\LaravelExcelWorksheet |
9 | | cells() | Maatwebsite\Excel\Writers\CellWriter |
10 | | row() | Maatwebsite\Excel\Writers\CellWriter |
--------------------------------------------------------------------------------
/2.1/reference-guide/css-styles.md:
--------------------------------------------------------------------------------
1 | # Available CSS styles
2 |
3 | Styles that can be used inside an external CSS file or as inline CSS.
4 |
5 | | Style name | Example Value |
6 | | ------------- |-------------|
7 | | background(-color) | #000000 |
8 | | color | #FFFFFF |
9 | | font-weight | bold |
10 | | font-style | italic |
11 | | font-weight | bold |
12 | | font-size | 20px |
13 | | font-family | Open Sans |
14 | | text-decoration | underline |
15 | | text-align | center |
16 | | vertical-align | middle |
17 | | border(-*) | 1px dashed #CCC |
18 | | width | 100(px) |
19 | | height | 1100(px) |
--------------------------------------------------------------------------------
/2.1/reference-guide/file-properties.md:
--------------------------------------------------------------------------------
1 | # Available file properties
2 |
3 | Properties that can be set with `$excel->set{$property}()`
4 |
5 | | Property name |
6 | | ------------- |
7 | |creator
8 | |lastModifiedBy
9 | |title
10 | |description
11 | |subject
12 | |keywords
13 | |category
14 | |manager
15 | |company
--------------------------------------------------------------------------------
/2.1/reference-guide/formatting.md:
--------------------------------------------------------------------------------
1 | # Available column formatting
2 |
3 | | Format name | PHPExcel class reference|
4 | | ------------- |-----------------|
5 | |General|PHPExcel_Style_NumberFormat::FORMAT_GENERAL
6 | |@|PHPExcel_Style_NumberFormat::FORMAT_TEXT
7 | |0|PHPExcel_Style_NumberFormat::FORMAT_NUMBER
8 | |0.00|PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00
9 | |#,##0.00|PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1
10 | |#,##0.00_-|PHPExcel_Style_NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2
11 | |0%|PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE
12 | |0.00%|PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00
13 | |yyyy-mm-dd|PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2
14 | |yy-mm-dd|PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD
15 | |dd/mm/yy|PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY
16 | |d/m/y|PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH
17 | |d-m-y|PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYMINUS
18 | |d-m|PHPExcel_Style_NumberFormat::FORMAT_DATE_DMMINUS
19 | |m-y|PHPExcel_Style_NumberFormat::FORMAT_DATE_MYMINUS
20 | |mm-dd-yy|PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14
21 | |d-mmm-yy|PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15
22 | |d-mmm|PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16
23 | |mmm-yy|PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17
24 | |m/d/yy h:mm|PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22
25 | |d/m/y h:mm|PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME
26 | |h:mm AM/PM|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME1
27 | |h:mm:ss AM/PM|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME2
28 | |h:mm|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3
29 | |h:mm:ss|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4
30 | |mm:ss|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME5
31 | |h:mm:ss|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME6
32 | |i:s.S|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME7
33 | |h:mm:ss;@|PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME8
34 | |yy/mm/dd;@|PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH
35 | |"$"#,##0.00_-|PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE
36 | |$#,##0_-|PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD
37 | |[$EUR ]#,##0.00_-|PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE
--------------------------------------------------------------------------------
/2.1/reference-guide/sheet-properties.md:
--------------------------------------------------------------------------------
1 | # Available sheet properties
2 |
3 | Properties that can be set with `$sheet->set{$property}()`
4 |
5 | | Property name | Possible value|
6 | | ------------- |-----------------|
7 | |orientation| string
8 | |paperSize| integer
9 | |scale| integer
10 | |fitToPage| boolean/int *
11 | |fitToHeight| boolean/int *
12 | |fitToWidth| boolean/int *
13 | |columnsToRepeatAtLeft| array
14 | |rowsToRepeatAtTop| array
15 | |horizontalCentered| boolean
16 | |verticalCentered| boolean
17 | |printArea| range
18 | |firstPageNumber| integer
19 |
20 | * See [PHPExcel's Page Setup: Scaling options](https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/markdown/Overview/08-Recipes.md#page-setup-scaling-options) for more information
21 |
--------------------------------------------------------------------------------
/3.0/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/3.0/exports/README.md:
--------------------------------------------------------------------------------
1 | ## :rocket: 5 minute quick start
2 |
3 | :muscle: Create an export class in `app/Exports`
4 |
5 | You may do this by using the `make:export` command.
6 |
7 | ```
8 | php artisan make:export UsersExport --model=User
9 | ```
10 |
11 | If you prefer to create the export manually, you can create the following in `app/Exports`:
12 |
13 | ```php
14 | invoice_number,
20 | Date::dateTimeToExcel($invoice->created_at),
21 | $invoice->total
22 | ];
23 | }
24 |
25 | /**
26 | * @return array
27 | */
28 | public function columnFormats(): array
29 | {
30 | return [
31 | 'B' => NumberFormat::FORMAT_DATE_DDMMYYYY,
32 | 'C' => NumberFormat::FORMAT_CURRENCY_EUR_INTEGER,
33 | ];
34 | }
35 | }
36 | ```
37 |
38 | ### Dates
39 |
40 | When working with dates, it's recommended to use `\PhpOffice\PhpSpreadsheet\Shared\Date::dateTimeToExcel()` in your mapping
41 | to ensure correct parsing of dates.
42 |
43 | ### Auto size
44 |
45 | If you want Laravel Excel to perform an automatic width calculation, use the following code.
46 |
47 | ```php
48 | namespace App\Exports;
49 |
50 | use Maatwebsite\Excel\Concerns\ShouldAutoSize;
51 |
52 | class InvoicesExport implements ShouldAutoSize
53 | {
54 | ...
55 | }
56 | ```
57 |
--------------------------------------------------------------------------------
/3.0/exports/concerns.md:
--------------------------------------------------------------------------------
1 | # Export concerns
2 |
3 | | Interface | Explanation |
4 | |---- |----|
5 | |`Maatwebsite\Excel\Concerns\FromCollection`| Use a Laravel Collection to populate the export. |
6 | |`Maatwebsite\Excel\Concerns\FromQuery`| Use an Eloquent query to populate the export. |
7 | |`Maatwebsite\Excel\Concerns\FromView`| Use a (Blade) view to populate the export. |
8 | |`Maatwebsite\Excel\Concerns\WithTitle`| Set the Workbook or Worksheet title. |
9 | |`Maatwebsite\Excel\Concerns\WithHeadings`| Prepend a heading row. |
10 | |`Maatwebsite\Excel\Concerns\WithMapping`| Format the row before it's written to the file. |
11 | |`Maatwebsite\Excel\Concerns\WithColumnFormatting`| Format certain columns. |
12 | |`Maatwebsite\Excel\Concerns\WithMultipleSheets`| Enable multi-sheet support. Each sheet can have its own concerns (except this one). |
13 | |`Maatwebsite\Excel\Concerns\ShouldAutoSize`| Auto-size the columns in the worksheet. |
14 | |`Maatwebsite\Excel\Concerns\WithStrictNullComparison`| Uses strict comparisions when testing cells for null value. |
15 | |`Maatwebsite\Excel\Concerns\WithEvents`| Register events to hook into the PhpSpreadsheet process. |
16 | |`Maatwebsite\Excel\Concerns\WithCustomQuerySize`| Allows Exportables that implement the FromQuery concern, to provide their own custom query size. |
17 | |`Maatwebsite\Excel\Concerns\WithCustomCsvSettings`| Allows to run custom Csv settings for this specific exportable. |
18 | |`Maatwebsite\Excel\Concerns\WithCharts`| Allows to run one or multiple PhpSpreadsheet Chart instances. |
19 | |`Maatwebsite\Excel\Concerns\WithDrawings`| Allows to run one or multiple PhpSpreadsheet (Base)Drawing instances. |
20 | |`Maatwebsite\Excel\Concerns\WithCustomStartCell`| Allows to specify a custom start cell. Do note that this is only supported for FromCollection exports. |
21 |
22 | ### Traits
23 |
24 | | Trait | Explanation |
25 | |---- |----|
26 | |`Maatwebsite\Excel\Concerns\Exportable` | Add download/store abilities right on the export class itself.
27 | |`Maatwebsite\Excel\Concerns\RegistersEventListeners` | Auto-register the available event listeners. |
28 |
--------------------------------------------------------------------------------
/3.0/exports/export-formats.md:
--------------------------------------------------------------------------------
1 | # Export formats
2 |
3 | By default the export format is determined by the extension of the file, however if you want
4 | to explicitly configured this, you can pass through the export format as 2nd parameter.
5 |
6 | ## XLSX
7 |
8 | ```php
9 | (new InvoicesExport)->download('invoices.xlsx', \Maatwebsite\Excel\Excel::XLSX);
10 | ```
11 |
12 | ## CSV
13 |
14 | ```php
15 | (new InvoicesExport)->download('invoices.csv', \Maatwebsite\Excel\Excel::CSV);
16 | ```
17 |
18 | ## TSV
19 |
20 | ```php
21 | (new InvoicesExport)->download('invoices.tsv', \Maatwebsite\Excel\Excel::TSV);
22 | ```
23 |
24 | ## ODS
25 |
26 | ```php
27 | (new InvoicesExport)->download('invoices.ods', \Maatwebsite\Excel\Excel::ODS);
28 | ```
29 |
30 | ## XLS
31 |
32 | ```php
33 | (new InvoicesExport)->download('invoices.xls', \Maatwebsite\Excel\Excel::XLS);
34 | ```
35 |
36 | ## SLK
37 |
38 | ```php
39 | (new InvoicesExport)->download('invoices.slk', \Maatwebsite\Excel\Excel::SLK);
40 | ```
41 |
42 | ## XML
43 |
44 | ```php
45 | (new InvoicesExport)->download('invoices.xml', \Maatwebsite\Excel\Excel::XML);
46 | ```
47 |
48 | ## GNUMERIC
49 |
50 | ```php
51 | (new InvoicesExport)->download('invoices.gnumeric', \Maatwebsite\Excel\Excel::GNUMERIC);
52 | ```
53 |
54 | ## HTML
55 |
56 | ```php
57 | (new InvoicesExport)->download('invoices.html', \Maatwebsite\Excel\Excel::HTML);
58 | ```
59 |
60 | ## MPDF
61 |
62 | ```php
63 | (new InvoicesExport)->download('invoices.pdf', \Maatwebsite\Excel\Excel::MPDF);
64 | ```
65 |
66 | ## DOMPDF
67 |
68 | ```php
69 | (new InvoicesExport)->download('invoices.pdf', \Maatwebsite\Excel\Excel::DOMPDF);
70 | ```
71 |
72 | ## TCPDF
73 |
74 | ```php
75 | (new InvoicesExport)->download('invoices.pdf', \Maatwebsite\Excel\Excel::TCPDF);
76 | ```
77 |
--------------------------------------------------------------------------------
/3.0/exports/exportables.md:
--------------------------------------------------------------------------------
1 | # Exportables
2 |
3 | In the previous example, we used the `Excel::download` facade to start an export.
4 |
5 | Laravel Excel also provides a `Maatwebsite\Excel\Concerns\Exportable` trait, to make export classes exportable.
6 |
7 | ```php
8 | namespace App\Exports;
9 |
10 | use Maatwebsite\Excel\Concerns\FromCollection;
11 | use Maatwebsite\Excel\Concerns\Exportable;
12 |
13 | class InvoicesExport implements FromCollection
14 | {
15 | use Exportable;
16 |
17 | public function collection()
18 | {
19 | return Invoice::all();
20 | }
21 | }
22 | ```
23 |
24 | We can now download the export without the need for the facade:
25 |
26 | ```php
27 | return (new InvoicesExport)->download('invoices.xlsx');
28 | ```
29 |
30 | Or store it on a disk:
31 |
32 | ```php
33 | return (new InvoicesExport)->store('invoices.xlsx', 's3');
34 | ```
35 |
36 | ### Responsable
37 |
38 | The previous example can be made even shorter when adding Laravel's `Responsable` interface to the export class:
39 |
40 | ```php
41 | namespace App\Exports;
42 |
43 | use Illuminate\Contracts\Support\Responsable;
44 | use Maatwebsite\Excel\Concerns\FromCollection;
45 | use Maatwebsite\Excel\Concerns\Exportable;
46 |
47 | class InvoicesExport implements FromCollection, Responsable
48 | {
49 | use Exportable;
50 |
51 | /**
52 | * It's required to define the fileName within
53 | * the export class when making use of Responsable.
54 | */
55 | private $fileName = 'invoices.xlsx';
56 |
57 | public function collection()
58 | {
59 | return Invoice::all();
60 | }
61 | }
62 | ```
63 |
64 | You can now easily return the export class, without the need of calling `->download()`.
65 |
66 | ```php
67 | return new InvoicesExport();
68 | ```
69 |
--------------------------------------------------------------------------------
/3.0/exports/from-query.md:
--------------------------------------------------------------------------------
1 | # From Query
2 |
3 | In the previous example, we did the query inside the export class.
4 | While this is a good solution for small exports,
5 | for bigger exports this will come at a hefty performance price.
6 |
7 | By using the `FromQuery` concern, we can prepare a query for an export. Behind the scenes this query is executed in chunks.
8 |
9 | In the `InvoicesExport` class, add the `FromQuery` concern, and return a query. Be sure to not `->get()` the results!
10 |
11 | ```php
12 | namespace App\Exports;
13 |
14 | use Maatwebsite\Excel\Concerns\FromQuery;
15 | use Maatwebsite\Excel\Concerns\Exportable;
16 |
17 | class InvoicesExport implements FromQuery
18 | {
19 | use Exportable;
20 |
21 | public function query()
22 | {
23 | return Invoice::query();
24 | }
25 | }
26 | ```
27 |
28 | We can still download the export in the same way:
29 |
30 | ```php
31 | return (new InvoicesExport)->download('invoices.xlsx');
32 | ```
33 |
34 | ### Customizing the query
35 |
36 | It's easy to pass custom parameters to the query,
37 | by simply passing them as dependencies to the export class.
38 |
39 | #### As constructor param
40 |
41 | ```php
42 | namespace App\Exports;
43 |
44 | use Maatwebsite\Excel\Concerns\FromQuery;
45 | use Maatwebsite\Excel\Concerns\Exportable;
46 |
47 | class InvoicesExport implements FromQuery
48 | {
49 | use Exportable;
50 |
51 | public function __construct(int $year)
52 | {
53 | $this->year = $year;
54 | }
55 |
56 | public function query()
57 | {
58 | return Invoice::query()->whereYear('created_at', $this->year);
59 | }
60 | }
61 | ```
62 |
63 | The year can now be passed as dependency to the export class:
64 |
65 | ```php
66 | return (new InvoicesExport(2018))->download('invoices.xlsx');
67 | ```
68 |
69 | #### As setter
70 |
71 | ```php
72 | namespace App\Exports;
73 |
74 | use Maatwebsite\Excel\Concerns\FromQuery;
75 | use Maatwebsite\Excel\Concerns\Exportable;
76 |
77 | class InvoicesExport implements FromQuery
78 | {
79 | use Exportable;
80 |
81 | public function forYear(int $year)
82 | {
83 | $this->year = $year;
84 |
85 | return $this;
86 | }
87 |
88 | public function query()
89 | {
90 | return Invoice::query()->whereYear('created_at', $this->year);
91 | }
92 | }
93 | ```
94 |
95 | We can adjust the year by using the `forYear` method:
96 |
97 | ```php
98 | return (new InvoicesExport)->forYear(2018)->download('invoices.xlsx');
99 | ```
100 |
--------------------------------------------------------------------------------
/3.0/exports/from-view.md:
--------------------------------------------------------------------------------
1 | # From View
2 |
3 | Exports can be created from a Blade view, by using the `FromView` concern.
4 |
5 | ```php
6 | namespace App\Exports;
7 |
8 | use Illuminate\Contracts\View\View;
9 | use Maatwebsite\Excel\Concerns\FromView;
10 |
11 | class InvoicesExport implements FromView
12 | {
13 | public function view(): View
14 | {
15 | return view('exports.invoices', [
16 | 'invoices' => Invoice::all()
17 | ]);
18 | }
19 | }
20 | ```
21 |
22 | It will convert an HTML table into an Excel spreadsheet. For example; `users.blade.php`:
23 |
24 | ```
25 |
26 |
27 |
28 | Name |
29 | Email |
30 |
31 |
32 |
33 | @foreach($users as $user)
34 |
35 | {{ $user->name }} |
36 | {{ $user->email }} |
37 |
38 | @endforeach
39 |
40 |
41 | ```
42 |
--------------------------------------------------------------------------------
/3.0/exports/mapping.md:
--------------------------------------------------------------------------------
1 | # Mapping data
2 |
3 | ### Mapping rows
4 |
5 | By adding `WithMapping` you map the data that needs to be added as row. This way you have control over the actual source for each column.
6 | In case of using the Eloquent query builder:
7 |
8 | ```php
9 |
10 | use Maatwebsite\Excel\Concerns\FromQuery;
11 | use Maatwebsite\Excel\Concerns\WithMapping;
12 |
13 | class InvoicesExport implements FromQuery, WithMapping
14 |
15 | /**
16 | * @var Invoice $invoice
17 | */
18 | public function map($invoice): array
19 | {
20 | return [
21 | $invoice->invoice_number,
22 | Date::dateTimeToExcel($invoice->created_at),
23 | ];
24 | }
25 | }
26 | ```
27 |
28 | ### Adding a heading row
29 |
30 | A heading row can easily be added by adding the `WithHeadings` concern. The heading row will be added
31 | as very first row of the sheet.
32 |
33 | ```php
34 |
35 | use Maatwebsite\Excel\Concerns\FromQuery;
36 | use Maatwebsite\Excel\Concerns\WithHeadings;
37 |
38 | class InvoicesExport implements FromQuery, WithHeadings
39 |
40 | public function headings(): array
41 | {
42 | return [
43 | '#',
44 | 'Date',
45 | ];
46 | }
47 | }
48 | ```
49 |
--------------------------------------------------------------------------------
/3.0/exports/multiple-sheets.md:
--------------------------------------------------------------------------------
1 | # Multiple Sheets
2 |
3 | To allow the export to have multiple sheets, the `WithMultipleSheets` concern should be used.
4 | The `sheets()` method expects an array of sheet export objects to be returned.
5 |
6 | ```php
7 | namespace App\Exports;
8 |
9 | use Maatwebsite\Excel\Concerns\Exportable;
10 | use Maatwebsite\Excel\Concerns\WithMultipleSheets;
11 |
12 | class InvoicesExport implements WithMultipleSheets
13 | {
14 | use Exportable;
15 |
16 | protected $year;
17 |
18 | public function __construct(int $year)
19 | {
20 | $this->year = $year;
21 | }
22 |
23 | /**
24 | * @return array
25 | */
26 | public function sheets(): array
27 | {
28 | $sheets = [];
29 |
30 | for ($month = 1; $month <= 12; $month++) {
31 | $sheets[] = new InvoicesPerMonthSheet($this->year, $month);
32 | }
33 |
34 | return $sheets;
35 | }
36 | }
37 | ```
38 |
39 | The `InvoicesPerMonthSheet` can implement concerns like `FromQuery`, `FromCollection`, ...
40 |
41 | ```php
42 | namespace App\Exports;
43 |
44 | use Maatwebsite\Excel\Concerns\FromQuery;
45 | use Maatwebsite\Excel\Concerns\WithTitle;
46 |
47 | class InvoicesPerMonthSheet implements FromQuery, WithTitle
48 | {
49 | private $month;
50 | private $year;
51 |
52 | public function __construct(int $year, int $month)
53 | {
54 | $this->month = $month;
55 | $this->year = $year;
56 | }
57 |
58 | /**
59 | * @return Builder
60 | */
61 | public function query()
62 | {
63 | return Invoice
64 | ::query()
65 | ->whereYear('created_at', $this->year)
66 | ->whereMonth('created_at', $this->month);
67 | }
68 |
69 | /**
70 | * @return string
71 | */
72 | public function title(): string
73 | {
74 | return 'Month ' . $this->month;
75 | }
76 | }
77 | ```
78 |
79 | This will now download an xlsx of all invoices in 2018, with 12 worksheets representing each month of the year.
80 |
81 | ```php
82 | public function download()
83 | {
84 | return (new InvoicesExport(2018))->download('invoices.xlsx');
85 | }
86 | ```
87 |
--------------------------------------------------------------------------------
/3.0/exports/store.md:
--------------------------------------------------------------------------------
1 | # Storing exports on disk
2 |
3 | Exports can easily be stored on any [filesystem](https://laravel.com/docs/5.6/filesystem) that Laravel supports.
4 |
5 | ```php
6 | public function storeExcel()
7 | {
8 | // Store on default disk
9 | Excel::store(new InvoicesExport(2018), 'invoices.xlsx');
10 |
11 | // Store on a different disk (e.g. s3)
12 | Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3');
13 |
14 | // Store on a different disk with a defined writer type.
15 | Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3', Excel::XLSX);
16 | }
17 | ```
--------------------------------------------------------------------------------
/3.0/exports/testing.md:
--------------------------------------------------------------------------------
1 | # Testing
2 |
3 | The Excel facade can be used to swap the exporter to a fake.
4 |
5 | ### Testing downloads
6 |
7 | ```php
8 | /**
9 | * @test
10 | */
11 | public function user_can_download_invoices_export()
12 | {
13 | Excel::fake();
14 |
15 | $this->actingAs($this->givenUser())
16 | ->get('/invoices/download/xlsx');
17 |
18 | Excel::assertDownloaded('filename.xlsx', function(InvoicesExport $export) {
19 | // Assert that the correct export is downloaded.
20 | return $export->collection()->contains('#2018-01');
21 | });
22 | }
23 | ```
24 |
25 | ### Testing storing exports
26 |
27 | ```php
28 | /**
29 | * @test
30 | */
31 | public function user_can_store_invoices_export()
32 | {
33 | Excel::fake();
34 |
35 | $this->actingAs($this->givenUser())
36 | ->get('/invoices/store/xlsx');
37 |
38 | Excel::assertStored('filename.xlsx', 'diskName');
39 |
40 | Excel::assertStored('filename.xlsx', 'diskName', function(InvoicesExport $export) {
41 | return true;
42 | });
43 |
44 | // When passing the callback as 2nd param, the disk will be the default disk.
45 | Excel::assertStored('filename.xlsx', function(InvoicesExport $export) {
46 | return true;
47 | });
48 | }
49 | ```
50 |
51 | ### Testing queuing exports
52 |
53 | ```php
54 | /**
55 | * @test
56 | */
57 | public function user_can_queue_invoices_export()
58 | {
59 | Excel::fake();
60 |
61 | $this->actingAs($this->givenUser())
62 | ->get('/invoices/queue/xlsx');
63 |
64 | Excel::assertQueued('filename.xlsx', 'diskName');
65 |
66 | Excel::assertQueued('filename.xlsx', 'diskName', function(InvoicesExport $export) {
67 | return true;
68 | });
69 |
70 | // When passing the callback as 2nd param, the disk will be the default disk.
71 | Excel::assertQueued('filename.xlsx', function(InvoicesExport $export) {
72 | return true;
73 | });
74 | }
75 | ```
--------------------------------------------------------------------------------
/3.0/getting-started/README.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | :rocket: Laravel Excel is intended at being Laravel-flavoured PhpSpreadsheet: a simple, but elegant wrapper around PhpSpreadsheet with the goal of simplifying
4 | exports.
5 |
6 | :fire: [PhpSpreadsheet](https://phpspreadsheet.readthedocs.io/) is a library written in pure PHP and providing a set of classes that allow you to read from and to write to different spreadsheet file formats, like Excel and LibreOffice Calc.
7 |
8 | Laravel Excel features:
9 |
10 | * Easily export collections to Excel
11 | * Export queries with automatic chunking for better performance
12 | * Queue exports for better performance
13 | * Easily export Blade views to Excel
--------------------------------------------------------------------------------
/3.0/getting-started/contributing.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | [[toc]]
4 |
5 | Please read and understand the contribution guide before creating an issue or pull request.
6 |
7 | ## Important Links
8 |
9 | - [Docs](https://laravel-excel.maatwebsite.nl)
10 | - [Issue tracker](https://github.com/SpartnerNL/Laravel-Excel/issues)
11 | - [Support](/3.0/getting-started/support.html)
12 |
13 | ## Etiquette
14 |
15 | This project is an open source project, and as such, the maintainers use their free time to build and maintain it.
16 | The code is freely available and can be used, forked and modified.
17 |
18 | Please be considerate towards maintainers when raising issues or presenting pull requests.
19 |
20 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
21 | quality to benefit the project. Many developers have different skill sets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
22 |
23 | ## Viability
24 |
25 | When requesting or submitting new features, first consider whether it might be useful to others. Open
26 | source projects are used by many developers, who may have entirely different needs to your own. Think about
27 | whether or not your feature is likely to be used by other users of the project.
28 |
29 | ## How to submit changes?
30 |
31 | - Check the codebase to ensure that your feature doesn't already exist.
32 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
33 | - Use the [pull request template](https://github.com/SpartnerNL/Laravel-Excel/blob/3.0/.github/PULL_REQUEST_TEMPLATE.md).
34 |
35 | ## How to report a bug?
36 |
37 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
38 | - Check to make sure your bug report isn't already present within the project.
39 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
40 | - Check the pull requests tab to ensure that the feature isn't already in progress.
41 | - Use the [issue template](https://github.com/SpartnerNL/Laravel-Excel/blob/3.0/.github/ISSUE_TEMPLATE.md).
42 |
43 | ## Requirements
44 |
45 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)**. - Style will get automatically fixed by StyleCI.
46 | - **Add tests backing up your change!** - You can run the test by running `vendor/bin/phpunit`
47 | - **Document any change in behaviour** - Documentation is located in the [https://github.com/SpartnerNL/laravel-excel-docs](https://github.com/SpartnerNL/laravel-excel-docs)
48 | - **One feature per Pull Request**
49 | - **Add meaningful commit messages**
50 |
--------------------------------------------------------------------------------
/3.0/getting-started/license.md:
--------------------------------------------------------------------------------
1 | # License
2 |
3 | Our software is open source and licensed under the [MIT license](https://choosealicense.com/licenses/mit/). According to the [postcardware](https://en.wikipedia.org/wiki/Postcardware) concept, if you use the software for your project(s) we would appreciate to receive a postcard of your hometown. Please send it to:
4 |
5 | **Maatwebsite**
6 | Florijnruwe 111-2
7 | 6218 CA Maastricht
8 | The Netherlands
9 |
10 | You are free to use the software as you like. The code can be forked and modified, but the original copyright author should always be included!
11 |
12 | ::: warning Support
13 | We hold no liability and will provide support on a best effort basis. For more information about support please see [support](https://laravel-excel.maatwebsite.nl/docs/3.0/getting-started/support).
14 | :::
15 |
16 | :rocket: If you use the software commercially and need support urgently, we can offer this on a commercial basis. Please contact or phone +31 (0)10 744 9312.
17 |
--------------------------------------------------------------------------------
/3.0/getting-started/support.md:
--------------------------------------------------------------------------------
1 | # Support
2 |
3 | [[toc]]
4 |
5 | Our software is free and open source, meaning that the use of our software is optional. We hold no liability and there is no obligation to support. We will provide support on a best effort basis.
6 |
7 | If you use the software commercially and need elaborate support or need it urgently, we can offer this on a commercial basis. Please contact or via phone +31 (0)10 744 9312.
8 |
9 | ## Supported Versions
10 |
11 | Versions will be supported for a limited amount of time.
12 |
13 | | Version | Laravel Version | Php Version | Support |
14 | |---- |----|----|----|
15 | | 2.1 | <=5.6 | <=7.0 | EOL since 15-05-2018 |
16 | | 3.0 | ^5.5 | ^7.0 | New features |
17 |
18 | ::: warning PHP version support
19 | Support for PHP versions will only be maintained for a period of six months beyond the end-of-life of that PHP version.
20 | :::
21 |
22 |
23 | ## Requesting support
24 | Before you request support, please check the following:
25 | * Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
26 | * Check to make sure your support request isn't already present within the project.
27 | * Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
28 | * Use the [issue template](https://github.com/SpartnerNL/Laravel-Excel/blob/3.0/.github/ISSUE_TEMPLATE.md).
29 |
30 | Filling out the template is required. Issues that do not include enough information might not be picked up. Please write in English (or Dutch).
31 |
32 | Please prefix your issue with one of the following: [BUG] [PROPOSAL] [QUESTION].
33 |
34 | And please be considerate towards maintainers when raising issues.
35 |
--------------------------------------------------------------------------------
/3.0/getting-started/upgrade.md:
--------------------------------------------------------------------------------
1 | # Upgrade Guide
2 |
3 | [[toc]]
4 |
5 | ## Upgrading to 3.0 from 2.1
6 |
7 | Version 3.0 is not backwards compatible with 2.*. It's not possible to provide a step-by-step migration guide as it's a complete paradigm shift.
8 |
9 | __New dependencies__
10 |
11 | 3.0 introduces some new dependencies.
12 |
13 | * Requires PHP 7.0 or higher.
14 | * Requires Laravel 5.5 (or higher).
15 | * Requires PhpSpreadsheet instead of PHPExcel.
16 |
17 | __Deprecations__
18 |
19 | ALL Laravel Excel 2.* methods are deprecated and will not be able to use in 3.0 .
20 |
21 | - Excel::load() is removed and will not be re-added until 3.1
22 | - Excel::create() is removed and replaced by Excel::download/Excel::store($yourExport)
23 | - 3.0 provides no convenience methods for styling, you are encouraged to use PhpSpreadsheets native methods.
24 |
--------------------------------------------------------------------------------
/3.1/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/3.1/architecture/concerns.md:
--------------------------------------------------------------------------------
1 | # Concerns
2 |
3 | [[toc]]
4 |
5 | Most of the export/import configuration is done by using **Concerns**.
6 |
7 | ## Contracts
8 |
9 | Concerns are basically just simple interfaces. Implementing them will make the object adhere to a
10 | certain contract. This contract can request specific methods that e.g. data can be passed through.
11 |
12 | For instance, the `FromCollection` requests the Export object to implement a `collection` method, that needs to return a `Collection` instance.
13 |
14 | ```php
15 | namespace App\Exports;
16 |
17 | use App\User;
18 | use Maatwebsite\Excel\Concerns\FromCollection;
19 |
20 | class UsersExport implements FromCollection
21 | {
22 | public function collection()
23 | {
24 | return User::all();
25 | }
26 | }
27 | ```
28 |
29 | ## Pointer interface
30 |
31 | In other cases it might not ask for any methods to be implemented, but merely functions as a pointer interface.
32 |
33 | For instance, the `ShouldAutoSize` concern doesn't pass on any specific information, but does tell the Export process that the columns need to be automatically sized.
34 |
35 | ```php
36 | namespace App\Exports;
37 |
38 | use App\User;
39 | use Maatwebsite\Excel\Concerns\ShouldAutoSize;
40 |
41 | class UsersExport implements ShouldAutoSize
42 | {
43 |
44 | }
45 | ```
46 |
--------------------------------------------------------------------------------
/3.1/exports/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # :rocket: 5 minute quick start
6 |
7 | [[toc]]
8 |
9 | :muscle: Create an export class in `app/Exports`
10 |
11 | You may do this by using the `make:export` command.
12 |
13 | ```
14 | php artisan make:export UsersExport --model=User
15 | ```
16 |
17 | The file can be found in `app/Exports`:
18 |
19 | ::: vue
20 | .
21 | ├── app
22 | │ ├── `Exports`
23 | │ │ ├── UsersExport.php
24 | │
25 | └── composer.json
26 | :::
27 |
28 | If you prefer to create the export manually, you can create the following in `app/Exports`:
29 |
30 | ```php
31 | 'text/csv',
25 | ]);
26 | ```
27 |
28 | :::tip Laravel CSV
29 | You may have a look at our [Laravel CSV](/csv/1.0/getting-started/) package as well.
30 | :::
31 |
32 | ## TSV
33 |
34 | ```php
35 | return Excel::download(new InvoicesExport, 'invoices.tsv', \Maatwebsite\Excel\Excel::TSV);
36 | ```
37 |
38 | ## ODS
39 |
40 | ```php
41 | return Excel::download(new InvoicesExport, 'invoices.ods', \Maatwebsite\Excel\Excel::ODS);
42 | ```
43 |
44 | ## XLS
45 |
46 | ```php
47 | return Excel::download(new InvoicesExport, 'invoices.xls', \Maatwebsite\Excel\Excel::XLS);
48 | ```
49 |
50 | ## HTML
51 |
52 | ```php
53 | return Excel::download(new InvoicesExport, 'invoices.html', \Maatwebsite\Excel\Excel::HTML);
54 | ```
55 |
56 | ::: warning Exporting to PDF
57 | If you'd like to export to PDF, you must now install a PDF rendering library yourself. Please refer to the [PhpSpreadsheet Documentation](https://phpspreadsheet.readthedocs.io/en/latest/topics/reading-and-writing-to-file/#pdf) for more information.
58 | :::
59 |
60 | ## MPDF
61 |
62 | ```php
63 | return Excel::download(new InvoicesExport, 'invoices.pdf', \Maatwebsite\Excel\Excel::MPDF);
64 | ```
65 |
66 | ## DOMPDF
67 |
68 | ```php
69 | return Excel::download(new InvoicesExport, 'invoices.pdf', \Maatwebsite\Excel\Excel::DOMPDF);
70 | ```
71 |
72 | ## TCPDF
73 |
74 | ```php
75 | return Excel::download(new InvoicesExport, 'invoices.pdf', \Maatwebsite\Excel\Excel::TCPDF);
76 | ```
77 |
--------------------------------------------------------------------------------
/3.1/exports/exportables.md:
--------------------------------------------------------------------------------
1 | # Exportables
2 |
3 | [[toc]]
4 |
5 | In the previous example, we used the `Excel::download` facade to start an export.
6 |
7 | Laravel Excel also provides a `Maatwebsite\Excel\Concerns\Exportable` trait, to make export classes exportable.
8 |
9 | ```php
10 | namespace App\Exports;
11 |
12 | use App\Invoice;
13 | use Maatwebsite\Excel\Concerns\FromCollection;
14 | use Maatwebsite\Excel\Concerns\Exportable;
15 |
16 | class InvoicesExport implements FromCollection
17 | {
18 | use Exportable;
19 |
20 | public function collection()
21 | {
22 | return Invoice::all();
23 | }
24 | }
25 | ```
26 |
27 | We can now download the export without the need for the facade:
28 |
29 | ```php
30 | return (new InvoicesExport)->download('invoices.xlsx');
31 | ```
32 |
33 | You can also pass the Writer Type and optional headers to the download method:
34 |
35 | ```php
36 | return (new InvoicesExport)->download('invoices.csv', Excel::CSV, ['Content-Type' => 'text/csv']);
37 | ```
38 |
39 | Or store it on a disk:
40 |
41 | ```php
42 | return (new InvoicesExport)->store('invoices.xlsx', 's3');
43 | ```
44 |
45 | You can also pass options to the disk if you like:
46 |
47 | ```php
48 | return (new InvoicesExport)->store('invoices.xlsx', 's3', null, 'private');
49 | ```
50 |
51 | ## Responsable
52 |
53 | The previous (download) example can be made even shorter when adding Laravel's `Responsable` interface to the export class:
54 |
55 | ```php
56 | namespace App\Exports;
57 |
58 | use App\Invoice;
59 | use Maatwebsite\Excel\Excel;
60 | use Illuminate\Contracts\Support\Responsable;
61 | use Maatwebsite\Excel\Concerns\FromCollection;
62 | use Maatwebsite\Excel\Concerns\Exportable;
63 |
64 | class InvoicesExport implements FromCollection, Responsable
65 | {
66 | use Exportable;
67 |
68 | /**
69 | * It's required to define the fileName within
70 | * the export class when making use of Responsable.
71 | */
72 | private $fileName = 'invoices.xlsx';
73 |
74 | /**
75 | * Optional Writer Type
76 | */
77 | private $writerType = Excel::XLSX;
78 |
79 | /**
80 | * Optional headers
81 | */
82 | private $headers = [
83 | 'Content-Type' => 'text/csv',
84 | ];
85 |
86 | public function collection()
87 | {
88 | return Invoice::all();
89 | }
90 | }
91 | ```
92 |
93 | You can now easily return the export class, without the need of calling `->download()`.
94 |
95 | ```php
96 | return new InvoicesExport();
97 | ```
98 |
--------------------------------------------------------------------------------
/3.1/exports/from-generator.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # From Generator
6 |
7 | Exports can be created from a PHP [generator](https://www.php.net/manual/en/class.generator.php) class, by using the `FromGenerator` concern.
8 |
9 | A generator allows you to write code that uses foreach to iterate over a set of data without needing to build an array in memory.
10 |
11 | ```php
12 | namespace App\Exports;
13 |
14 | use Generator;
15 | use Maatwebsite\Excel\Concerns\Exportable;
16 | use Maatwebsite\Excel\Concerns\FromGenerator;
17 |
18 | class DataExport implements FromGenerator
19 | {
20 | use Exportable;
21 |
22 | public function generator(): Generator
23 | {
24 | for ($i = 1; $i <= 100; $i++) {
25 | yield [$i, $i+1, $i+2];
26 | }
27 | }
28 | }
29 | ```
30 |
31 | You can download the export in your controller:
32 |
33 | ```php
34 | public function export()
35 | {
36 | return (new DataExport)->download('data.xlsx');
37 | }
38 | ```
39 |
--------------------------------------------------------------------------------
/3.1/exports/from-view.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # From View
6 |
7 | Exports can be created from a Blade view, by using the `FromView` concern.
8 |
9 | ```php
10 | namespace App\Exports;
11 |
12 | use App\Invoice;
13 | use Illuminate\Contracts\View\View;
14 | use Maatwebsite\Excel\Concerns\FromView;
15 |
16 | class InvoicesExport implements FromView
17 | {
18 | public function view(): View
19 | {
20 | return view('exports.invoices', [
21 | 'invoices' => Invoice::all()
22 | ]);
23 | }
24 | }
25 | ```
26 |
27 | It will convert an HTML table into an Excel spreadsheet. For example; `invoices.blade.php`:
28 |
29 | ```html
30 |
31 |
32 |
33 | Name |
34 | Email |
35 |
36 |
37 |
38 | @foreach($invoices as $invoice)
39 |
40 | {{ $invoice->name }} |
41 | {{ $invoice->email }} |
42 |
43 | @endforeach
44 |
45 |
46 | ```
47 |
48 | Attribute in tag html support:
49 |
50 | |Attributes|Description
51 | |-----------|-------------
52 | |bgcolor| set background color to cell ``
53 | |colspan| merge column cell
54 | |rowspan| merge row cell
55 | |width| set width to cell
56 | |height| set height to cell
57 | |data-format| set format `PhpOffice\PhpSpreadsheet\Style::NumberFormat`
58 | |data-type| set type `PhpOffice\PhpSpreadsheet\Cell`
59 | |align| set text align to cell
60 | |valign| set vertical align to cell
61 | |style| set style to cell
62 |
63 | Style inline support
64 | - background
65 | - background-color
66 | - color
67 | - border|border-top|border-bottom|border-left|border-right
68 | - font-size|font-weight|font-sytle|font-family
69 | - text-decoration: underline|line-through
70 | - text-align
71 | - vertical-align
72 | - with|height
73 | - word-wrap
74 | - text-indent
75 |
76 | You can download the export in your controller:
77 |
78 | ```php
79 | public function export()
80 | {
81 | return Excel::download(new InvoicesExport, 'invoices.xlsx');
82 | }
83 | ```
84 |
--------------------------------------------------------------------------------
/3.1/exports/multiple-sheets.md:
--------------------------------------------------------------------------------
1 | # Multiple Sheets
2 |
3 | [[toc]]
4 |
5 | To allow the export to have multiple sheets, the `WithMultipleSheets` concern should be used.
6 | The `sheets()` method expects an array of sheet export objects to be returned.
7 |
8 | ```php
9 | namespace App\Exports;
10 |
11 | use Maatwebsite\Excel\Concerns\Exportable;
12 | use Maatwebsite\Excel\Concerns\WithMultipleSheets;
13 |
14 | class InvoicesExport implements WithMultipleSheets
15 | {
16 | use Exportable;
17 |
18 | protected $year;
19 |
20 | public function __construct(int $year)
21 | {
22 | $this->year = $year;
23 | }
24 |
25 | /**
26 | * @return array
27 | */
28 | public function sheets(): array
29 | {
30 | $sheets = [];
31 |
32 | for ($month = 1; $month <= 12; $month++) {
33 | $sheets[] = new InvoicesPerMonthSheet($this->year, $month);
34 | }
35 |
36 | return $sheets;
37 | }
38 | }
39 | ```
40 |
41 | ## Sheet classes
42 |
43 | The `InvoicesPerMonthSheet` can implement concerns like `FromQuery`, `FromCollection`, `FromView`, ...
44 |
45 | _Note: The WithTitle concern is needed in order to name each sheet using the `title()` method_
46 | ```php
47 | namespace App\Exports\Sheets;
48 |
49 | use Maatwebsite\Excel\Concerns\FromQuery;
50 | use Maatwebsite\Excel\Concerns\WithTitle;
51 |
52 | class InvoicesPerMonthSheet implements FromQuery, WithTitle
53 | {
54 | private $month;
55 | private $year;
56 |
57 | public function __construct(int $year, int $month)
58 | {
59 | $this->month = $month;
60 | $this->year = $year;
61 | }
62 |
63 | /**
64 | * @return Builder
65 | */
66 | public function query()
67 | {
68 | return Invoice
69 | ::query()
70 | ->whereYear('created_at', $this->year)
71 | ->whereMonth('created_at', $this->month);
72 | }
73 |
74 | /**
75 | * @return string
76 | */
77 | public function title(): string
78 | {
79 | return 'Month ' . $this->month;
80 | }
81 | }
82 | ```
83 |
84 | The code below can be implemented in any class in order to download an xlsx of all invoices from the current year, with 12 worksheets representing each month of the year.
85 |
86 | ```php
87 | public function downloadInvoices()
88 | {
89 | return (new InvoicesExport(2018))->download('invoices.xlsx');
90 | }
91 | ```
92 |
--------------------------------------------------------------------------------
/3.1/exports/store.md:
--------------------------------------------------------------------------------
1 | # Storing exports on disk
2 |
3 | [[toc]]
4 |
5 | Exports can easily be stored on any [filesystem](https://laravel.com/docs/master/filesystem) that Laravel supports.
6 |
7 |
8 | ## Default disk
9 |
10 | ```php
11 | public function storeExcel()
12 | {
13 | // Store on default disk
14 | Excel::store(new InvoicesExport(2018), 'invoices.xlsx');
15 | }
16 | ```
17 |
18 | ## Custom disks
19 |
20 | ```php
21 | public function storeExcel()
22 | {
23 | // Store on a different disk (e.g. s3)
24 | Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3');
25 |
26 | // Store on a different disk with a defined writer type.
27 | Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3', Excel::XLSX);
28 | }
29 | ```
30 |
31 | ## Disk options
32 |
33 | If you want to pass some options to the disk, pass them to Excel::store() as the fifth parameter.
34 |
35 | ```php
36 | public function storeExcel()
37 | {
38 | Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3', null, [
39 | 'visibility' => 'private',
40 | ]);
41 | }
42 | ```
43 |
44 | Laravel has a shortcut for private files:
45 |
46 | ```php
47 | public function storeExcel()
48 | {
49 | Excel::store(new InvoicesExport(2018), 'invoices.xlsx', 's3', null, 'private');
50 | }
51 | ```
52 |
53 | ::: warning File names cannot include certain characters:
54 | - `<` (less than)
55 | - `>` (greater than)
56 | - `:` (colon)
57 | - `"` (double quote)
58 | - `/` (forward slash)
59 | - `\` (backslash)
60 | - `|` (vertical bar or pipe)
61 | - `?` (question mark)
62 | - `*` (asterisk)
63 | :::
64 |
65 | ## Note about queuing
66 | If you are storing the export using `Excel::queue()` or using the `ShouldQueue` interface, make sure to have a look at the [queuing docs](https://docs.laravel-excel.com/3.1/exports/queued.html)
67 |
--------------------------------------------------------------------------------
/3.1/getting-started/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # Introduction
6 |
7 | :rocket: Laravel Excel is intended at being Laravel-flavoured PhpSpreadsheet: a simple, but elegant wrapper around PhpSpreadsheet with the goal of simplifying
8 | exports and imports.
9 |
10 | :fire: [PhpSpreadsheet](https://phpspreadsheet.readthedocs.io/) is a library written in pure PHP and providing a set of classes that allow you to read from and to write to different spreadsheet file formats, like Excel and LibreOffice Calc.
11 |
12 | ## Laravel Excel Features
13 |
14 | * Easily export collections to Excel.
15 | * Export queries with automatic chunking for better performance.
16 | * Queue exports for better performance.
17 | * Easily export Blade views to Excel.
18 | * Easily import to collections.
19 | * Read the Excel file in chunks.
20 | * Handle the import inserts in batches.
--------------------------------------------------------------------------------
/3.1/getting-started/installation.md:
--------------------------------------------------------------------------------
1 | # Installation
2 |
3 | [[toc]]
4 |
5 | ## Requirements
6 |
7 | * PHP: `^7.2\|^8.0`
8 | * Laravel: `^5.8`
9 | * PhpSpreadsheet: `^1.21`
10 | * PHP extension `php_zip` enabled
11 | * PHP extension `php_xml` enabled
12 | * PHP extension `php_gd2` enabled
13 | * PHP extension `php_iconv` enabled
14 | * PHP extension `php_simplexml` enabled
15 | * PHP extension `php_xmlreader` enabled
16 | * PHP extension `php_zlib` enabled
17 |
18 | ## Installation
19 |
20 | Require this package in the `composer.json` of your Laravel project. This will download the package and _PhpSpreadsheet_.
21 |
22 | ```
23 | composer require "maatwebsite/excel:^3.1"
24 | ```
25 |
26 | If installing your receive the following error
27 |
28 | ```
29 | Your requirements could not be resolved to an installable set of packages.
30 |
31 | Problem 1
32 | - Root composer.json requires maatwebsite/excel 3.1 -> satisfiable by maatwebsite/excel[3.1.0].
33 | - maatwebsite/excel 3.1.0 requires php ^7.0 -> your php version (8.2.8) does not satisfy that requirement.
34 | ```
35 |
36 | You can try simply to install without the caret
37 |
38 | ```
39 | composer require maatwebsite/excel
40 | ```
41 |
42 | If you don't get the latest version or run into more composer errors, please make sure you have installed all required PHP extensions like zip, gd, etc.
43 |
44 | The `Maatwebsite\Excel\ExcelServiceProvider` is __auto-discovered__ and registered by default.
45 |
46 | If you want to register it yourself, add the ServiceProvider in `config/app.php`:
47 |
48 | ```php
49 | 'providers' => [
50 | /*
51 | * Package Service Providers...
52 | */
53 | Maatwebsite\Excel\ExcelServiceProvider::class,
54 | ]
55 | ```
56 |
57 | The `Excel` facade is also __auto-discovered__.
58 |
59 | If you want to add it manually, add the Facade in `config/app.php`:
60 |
61 | ```php
62 | 'aliases' => [
63 | ...
64 | 'Excel' => Maatwebsite\Excel\Facades\Excel::class,
65 | ]
66 | ```
67 |
68 | To publish the config, run the vendor publish command:
69 |
70 | ```
71 | php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config
72 | ```
73 |
74 | This will create a new config file named `config/excel.php`.
75 |
--------------------------------------------------------------------------------
/3.1/getting-started/license.md:
--------------------------------------------------------------------------------
1 | # License
2 |
3 | [[toc]]
4 |
5 | ## MIT
6 | Our software is open source and licensed under the [MIT license](https://choosealicense.com/licenses/mit/). You are free to use the software as you like. The code can be forked and modified, but the original copyright author should always be included!
7 |
8 | ## Postcardware
9 | According to the [postcardware](https://en.wikipedia.org/wiki/Postcardware) concept, if you use the software for your project(s) we would appreciate to receive a postcard of your hometown. Please send it to:
10 |
11 | **Spartner**
12 | Markt 2
13 | 6231 LS Meerssen
14 | The Netherlands
15 |
16 | ## Created by Spartner (formerly Maatwebsite)
17 |
18 | We are a strategic development partner, creating web-based custom built software from Laravel. In need of a digital solution for your challenge? Give us a call.
19 |
20 | [https://spartner.software](https://spartner.software)
21 | [info@spartner.nl](mailto:info@spartner.nl)
22 | +31 (0) 10 - 7449312
23 |
24 | ## Support
25 |
26 | ::: warning Support
27 | We hold no liability and will provide support on a best effort basis. For more information about support please see [support](https://docs.laravel-excel.com/3.1/getting-started/support.html).
28 | :::
29 |
30 | :::tip Commercial Support
31 | :rocket: If you use the software commercially and need support urgently, we can offer this on a commercial basis. Please contact or phone +31 (0)10 744 9312.
32 | :::
33 |
--------------------------------------------------------------------------------
/3.1/getting-started/support.md:
--------------------------------------------------------------------------------
1 | # Support
2 |
3 | [[toc]]
4 |
5 | Our software is free and open source, meaning that the use of our software is optional. We hold no liability and there is no obligation to support. We will provide support on a best effort basis.
6 |
7 | :::tip Commercial Support
8 | If you use the software commercially and need elaborate support or need it urgently, we can offer this on a commercial basis. Please contact or via phone +31 (0)10 744 9312.
9 | :::
10 |
11 | ## Supported Versions
12 |
13 | Versions will be supported for a limited amount of time.
14 |
15 | | Version | Laravel Version | Php Version | Support |
16 | |---- |----|----|----|
17 | | 2.1 | <=5.6 | <=7.0 | Unsupported since 15-5-2018 |
18 | | 3.0 | ^5.5 | ^7.0 | Unsupported since 31-12-2018 |
19 | | 3.1 | ^5.8\|^6.0\|^7.0\|^8.0\|^9.0\|^10.0 | ^7.2\|^8.0 | New features |
20 |
21 | ::: warning PHP version support
22 | Support for PHP versions will only be maintained for a period of six months beyond the end-of-life of that PHP version.
23 | :::
24 |
25 | ## Requesting support
26 | Before you request support, please check the following:
27 | * Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
28 | * Check to make sure your support request isn't already present within the project.
29 | * Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
30 | * Use one of the [issue templates](https://github.com/SpartnerSoftware/Laravel-Excel/tree/3.1/.github/ISSUE_TEMPLATE).
31 |
32 | Filling out the template is required. Issues that do not include enough information might not be picked up. Please write in English (or Dutch).
33 |
34 | Please prefix your issue with one of the following: [BUG] [PROPOSAL] [QUESTION].
35 |
36 | And please be considerate towards maintainers when raising issues.
37 |
--------------------------------------------------------------------------------
/3.1/getting-started/upgrade.md:
--------------------------------------------------------------------------------
1 | # Upgrade Guide
2 |
3 | [[toc]]
4 |
5 | ## Upgrading to 3.1 from 3.0
6 |
7 | Version 3.1 is backwards compatible with 3.0. Only features were added in this release.
8 |
9 | __Additions__
10 |
11 | * Imports feature.
12 | * ChunkReading
13 | * BatchInserts
14 | * Queued imports
15 | * ToArray concern for Exports.
16 | * Custom value binders for Imports and Exports.
17 |
18 | __Removals__
19 |
20 | * `Excel::filter('chunk')` method is removed, chunk filter is automatically added when using chunk reading.
21 |
22 | ## Upgrading to 3.* from 2.1
23 |
24 | Version 3.* is not backwards compatible with 2.*. It's not possible to provide a step-by-step migration guide as it's a complete paradigm shift.
25 |
26 | __New dependencies__
27 |
28 | 3.* introduces some new dependencies.
29 |
30 | * Requires PHP 7.0 or higher.
31 | * Requires Laravel 5.5 (or higher).
32 | * Requires PhpSpreadsheet instead of PHPExcel.
33 |
34 | __Deprecations__
35 |
36 | ALL Laravel Excel 2.* methods are deprecated and will not be able to use in 3.0 .
37 |
38 | - `Excel::load()` is removed and replaced by `Excel::import($yourImport)`
39 | - `Excel::create()` is removed and replaced by `Excel::download/Excel::store($yourExport)`
40 | - `Excel::create()->string('xlsx')` is removed an replaced by `Excel::raw($yourExport, Excel::XLSX)`
41 | - 3.0 provides no convenience methods for styling, you are encouraged to use PhpSpreadsheets native methods.
42 |
43 | You can find an example upgrade for an export here: [https://github.com/SpartnerNL/Laravel-Excel/issues/1799](https://github.com/SpartnerNL/Laravel-Excel/issues/1799)
44 |
--------------------------------------------------------------------------------
/3.1/imports/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | ## :rocket: 5 minute quick start
6 |
7 | :muscle: Create an import class in `app/Imports`
8 |
9 | You may do this by using the `make:import` command.
10 |
11 | ```
12 | php artisan make:import UsersImport --model=User
13 | ```
14 |
15 | The file can be found in `app/Imports`:
16 |
17 | ::: vue
18 | .
19 | ├── app
20 | │ ├── `Imports`
21 | │ │ ├── UsersImport.php
22 | │
23 | └── composer.json
24 | :::
25 |
26 | If you prefer to create the import manually, you can create the following in `app/Imports`:
27 |
28 | ```php
29 | $row[0],
48 | 'email' => $row[1],
49 | 'password' => Hash::make($row[2]),
50 | ]);
51 | }
52 | }
53 | ```
54 |
55 | :fire: In your controller you can call this import now:
56 |
57 | ```php
58 |
59 | use App\Imports\UsersImport;
60 | use Maatwebsite\Excel\Facades\Excel;
61 | use App\Http\Controllers\Controller;
62 |
63 | class UsersController extends Controller
64 | {
65 | public function import()
66 | {
67 | Excel::import(new UsersImport, 'users.xlsx');
68 |
69 | return redirect('/')->with('success', 'All good!');
70 | }
71 | }
72 | ```
73 |
74 | :page_facing_up: Find the imported users in your database!
75 |
--------------------------------------------------------------------------------
/3.1/imports/basics.md:
--------------------------------------------------------------------------------
1 | ## Importing basics
2 |
3 | [[toc]]
4 |
5 | If you have followed the 5 minute quick start, you'll already have a `UsersImport` class.
6 |
7 | ```php
8 | $row[0],
27 | 'email' => $row[1],
28 | 'password' => Hash::make($row[2]),
29 | ]);
30 | }
31 | }
32 | ```
33 |
34 | ## Importing from default disk
35 |
36 | Passing the UsersImport object to the `Excel::import()` method will tell the package how to import the file that is passed as second parameter.
37 | The file is expected to be located in your default filesystem disk (see `config/filesystems.php`).
38 |
39 | ```php
40 | Excel::import(new UsersImport, 'users.xlsx');
41 | ```
42 |
43 | ### Importing from another disk
44 |
45 | You can specify another disk with the third parameter like your Amazon s3 disk. (see `config/filesystems.php`)
46 |
47 | ```php
48 | Excel::import(new UsersImport, 'users.xlsx', 's3');
49 | ```
50 |
51 | ## Importing uploaded files
52 |
53 | If you let your user upload the document, you can also just pass the uploaded file directly.
54 |
55 | ```php
56 | Excel::import(new UsersImport, request()->file('your_file'));
57 | ```
58 |
59 | ### Importing full path
60 |
61 | If you want to specifiy the path where your file is, without having to move it to a disk, you can directly pass that file path to the import method.
62 |
63 | ```php
64 | Excel::import(new UsersImport, storage_path('users.xlsx'));
65 | ```
66 |
67 | ## Importing to array or collection
68 |
69 | If you want to bypass the `ToArray` or `ToCollection` concerns and want to have an array of imported data in your controller (beware of performance!), you can use the `::toArray()` or `::toCollection()` method.
70 |
71 | ```php
72 | $array = Excel::toArray(new UsersImport, 'users.xlsx');
73 |
74 | $collection = Excel::toCollection(new UsersImport, 'users.xlsx');
75 | ```
76 |
77 | ## Specifying a reader type
78 |
79 | If the reader type is not detectable by the file extension, you can specify a reader type by passing it as fourth parameter.
80 |
81 | ```php
82 | Excel::import(new UsersImport, 'users.xlsx', 's3', \Maatwebsite\Excel\Excel::XLSX);
83 | ```
84 |
--------------------------------------------------------------------------------
/3.1/imports/collection.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # Importing to collections
6 |
7 | [[toc]]
8 |
9 | The easiest way to start an import is to create a custom import class. We'll use a user import as example.
10 |
11 | Create a new class called `UsersImport` in `app/Imports`:
12 |
13 | ```php
14 | namespace App\Imports;
15 |
16 | use App\User;
17 | use Illuminate\Support\Collection;
18 | use Maatwebsite\Excel\Concerns\ToCollection;
19 |
20 | class UsersImport implements ToCollection
21 | {
22 | public function collection(Collection $collection)
23 | {
24 | foreach ($collection as $row)
25 | {
26 | User::create([
27 | 'name' => $row[0],
28 | ]);
29 | }
30 | }
31 | }
32 | ```
33 |
34 | The collection method will receive a collection of rows. A row is an array filled with the cell values.
35 |
36 | In case of the file having multiple sheets, the `collection()` method will be called multiple times.
37 |
38 | In your controller we can now import this:
39 |
40 | ```php
41 | public function import()
42 | {
43 | Excel::import(new UsersImport, 'users.xlsx');
44 | }
45 | ```
46 |
47 | :::warning
48 | Whatever you return in the `collection()` method will **not** be returned to the controller.
49 | :::
50 |
--------------------------------------------------------------------------------
/3.1/imports/custom-csv-settings.md:
--------------------------------------------------------------------------------
1 | # Custom CSV Settings
2 |
3 | [[toc]]
4 |
5 | By default Laravel Excel uses the defaults from the config (`config/excel.php`). You can change this by adding the `WithCustomCsvSettings` interface.
6 |
7 | ```php
8 | namespace App\Imports;
9 |
10 | use Maatwebsite\Excel\Concerns\ToModel;
11 | use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;
12 |
13 | class UsersImport implements ToModel, WithCustomCsvSettings
14 | {
15 | public function model(array $row)
16 | {
17 | return new User([
18 | 'name' => $row['0'],
19 | 'email' => $row['1']
20 | ]);
21 | }
22 |
23 | public function getCsvSettings(): array
24 | {
25 | return [
26 | 'input_encoding' => 'ISO-8859-1'
27 | ];
28 | }
29 | }
30 | ```
31 |
32 |
33 | A CSV file stores data in rows and the values in each row is separated with a separator, also known as a delimiter. Although the file is defined as Comma Separated Values, the delimiter could be anything. Delimiter requires a single character. For Tab use `"\t"`. The most common delimiters are: a comma `,`, a semicolon `;`, a tab `\t`, a space ` `, or a pipe `|`.
34 |
35 | ```php
36 | public function getCsvSettings(): array
37 | {
38 | return [
39 | 'delimiter' => "\t"
40 | ];
41 | }
42 | ```
43 |
44 | ## Available settings
45 |
46 | * `delimiter`
47 | * `enclosure`
48 | * `escape_character`
49 | * `contiguous`
50 | * `input_encoding`
51 |
--------------------------------------------------------------------------------
/3.1/imports/custom-formatting-values.md:
--------------------------------------------------------------------------------
1 | # Custom Formatting Values
2 |
3 | [[toc]]
4 |
5 | ## Value Binder
6 |
7 | By default Laravel Excel uses PhpSpreadsheet's default value binder to intelligently format a cell's value when reading it. You may override this behavior by implementing the `WithCustomValueBinder` concern and the `bindValue` method. Your import class may also extend `DefaultValueBinder` to return the default behavior.
8 |
9 | ```php
10 | namespace App\Imports;
11 |
12 | use PhpOffice\PhpSpreadsheet\Cell\Cell;
13 | use Maatwebsite\Excel\Concerns\ToModel;
14 | use PhpOffice\PhpSpreadsheet\Cell\DataType;
15 | use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
16 | use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
17 |
18 | class UsersImport extends DefaultValueBinder implements WithCustomValueBinder, ToModel
19 | {
20 | public function bindValue(Cell $cell, $value)
21 | {
22 | if (is_numeric($value)) {
23 | $cell->setValueExplicit($value, DataType::TYPE_NUMERIC);
24 |
25 | return true;
26 | }
27 |
28 | // else return default behavior
29 | return parent::bindValue($cell, $value);
30 | }
31 | }
32 | ```
33 |
34 | ## Available DataTypes
35 |
36 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING`
37 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA`
38 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NUMERIC`
39 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_BOOL`
40 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NULL`
41 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_INLINE`
42 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_ERROR`
43 |
44 | ## Disable intelligent formatting
45 |
46 | If you want to disable the intelligent formatting of values, you can extend your import class with `\PhpOffice\PhpSpreadsheet\Cell\StringValueBinder`. In this case all values are passed on as strings.
47 |
48 | ```php
49 | namespace App\Imports;
50 |
51 | use Maatwebsite\Excel\Concerns\ToModel;
52 | use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
53 |
54 | class UsersImport extends \PhpOffice\PhpSpreadsheet\Cell\StringValueBinder implements WithCustomValueBinder, ToModel
55 | {
56 |
57 | }
58 | ```
59 |
60 | ## Default Value Binder
61 |
62 | If you want to use one value binder for all your imports, you can configure the default value binder in the config.
63 |
64 | In `config/excel.php`:
65 |
66 | ```php
67 | 'value_binder' => [
68 | 'default' => Maatwebsite\Excel\DefaultValueBinder::class,
69 | ],
70 | ```
71 |
--------------------------------------------------------------------------------
/3.1/imports/import-formats.md:
--------------------------------------------------------------------------------
1 | # Import formats
2 |
3 | [[toc]]
4 |
5 | By default, the import format is determined by the extension of the file. If you want
6 | to explicitly configure the import format, you can pass it through as 3rd parameter.
7 |
8 | ## XLSX
9 |
10 | ```php
11 | (new UsersImport)->import('users.xlsx', null, \Maatwebsite\Excel\Excel::XLSX);
12 | ```
13 |
14 | ## CSV
15 |
16 | ```php
17 | (new UsersImport)->import('users.csv', null, \Maatwebsite\Excel\Excel::CSV);
18 | ```
19 |
20 | ## TSV
21 |
22 | ```php
23 | (new UsersImport)->import('users.tsv', null, \Maatwebsite\Excel\Excel::TSV);
24 | ```
25 |
26 | ## ODS
27 |
28 | ```php
29 | (new UsersImport)->import('users.ods', null, \Maatwebsite\Excel\Excel::ODS);
30 | ```
31 |
32 | ## XLS
33 |
34 | ```php
35 | (new UsersImport)->import('users.xls', null, \Maatwebsite\Excel\Excel::XLS);
36 | ```
37 |
38 | ## SLK
39 |
40 | ```php
41 | (new UsersImport)->import('users.slk', null, \Maatwebsite\Excel\Excel::SLK);
42 | ```
43 |
44 | ## XML
45 |
46 | ```php
47 | (new UsersImport)->import('users.xml', null, \Maatwebsite\Excel\Excel::XML);
48 | ```
49 |
50 | ## GNUMERIC
51 |
52 | ```php
53 | (new UsersImport)->import('users.gnumeric', null, \Maatwebsite\Excel\Excel::GNUMERIC);
54 | ```
55 |
56 | ## HTML
57 |
58 | ```php
59 | (new UsersImport)->import('users.html', null, \Maatwebsite\Excel\Excel::HTML);
60 | ```
61 |
--------------------------------------------------------------------------------
/3.1/imports/importables.md:
--------------------------------------------------------------------------------
1 | # Importables
2 |
3 | [[toc]]
4 |
5 | In the previous example, we used the `Excel::import` facade to start an import.
6 |
7 | Laravel Excel also provides a `Maatwebsite\Excel\Concerns\Importable` trait, to make import classes importable.
8 |
9 | ```php
10 | namespace App\Imports;
11 |
12 | use App\User;
13 | use Maatwebsite\Excel\Concerns\ToModel;
14 | use Maatwebsite\Excel\Concerns\Importable;
15 |
16 | class UsersImport implements ToModel
17 | {
18 | use Importable;
19 |
20 | public function model(array $row)
21 | {
22 | return new User([
23 | 'name' => $row[0],
24 | ]);
25 | }
26 | }
27 | ```
28 |
29 | ## Importing
30 |
31 | We can now import without the need for the facade:
32 |
33 | ```php
34 | (new UsersImport)->import('users.xlsx', 'local', \Maatwebsite\Excel\Excel::XLSX);
35 | ```
36 |
37 | ## Queuing
38 |
39 | Or queue the import:
40 |
41 | ```php
42 | (new UsersImport)->queue('users.xlsx');
43 | ```
44 |
45 | ## To array
46 |
47 | The import can be loaded into an array :
48 |
49 | ```php
50 | $array = (new UsersImport)->toArray('users.xlsx');
51 | ```
52 |
53 | ## To collection
54 |
55 | The import can be loaded into a collection:
56 |
57 | ```php
58 | $collection = (new UsersImport)->toCollection('users.xlsx');
59 | ```
--------------------------------------------------------------------------------
/3.1/imports/mapped-cells.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # Mapped Cells
6 |
7 | In case you have a more custom spreadsheet and only want to access specific **cells**, you can implement the `WithMappedCells` concern.
8 |
9 | You might have a speadsheet looking like this:
10 |
11 | |name | Patrick Brouwers|
12 | |---- |----|
13 | | email | patrick@maatwebsite.nl |
14 |
15 | We can now map `name` to `B1` and `email` to `B2`. The value of those coordinates will then be available under the given array key.
16 |
17 | ```php
18 | namespace App\Imports;
19 |
20 | use App\User;
21 | use Maatwebsite\Excel\Concerns\ToModel;
22 | use Maatwebsite\Excel\Concerns\WithMappedCells;
23 |
24 | class UsersImport implements WithMappedCells, ToModel
25 | {
26 | public function mapping(): array
27 | {
28 | return [
29 | 'name' => 'B1',
30 | 'email' => 'B2',
31 | ];
32 | }
33 |
34 | public function model(array $row)
35 | {
36 | return new User([
37 | 'name' => $row['name'],
38 | 'email' => $row['email'],
39 | ]);
40 | }
41 | }
42 | ```
43 |
44 | ::: warning
45 | This concern is not meant to map **columns**, only specific **cell** reference are allowed.
46 | :::
47 |
48 | ## Multi-dimensional Mapping
49 |
50 | In case you have repeating data in your table, e. g. a spreadsheet looking like this:
51 |
52 | | Team 1 | | Team 2| |
53 | |-|-|-|-|
54 | | Max | 2 | Peter | 3 |
55 | | Annie | 0 | Alex | 1 |
56 |
57 | you are also able to define cell coordinates in a nested array:
58 |
59 | ```php
60 | public function mapping(): array
61 | {
62 | return [
63 | 'team1' => [
64 | [
65 | 'name' => 'A2',
66 | 'score' => 'B2',
67 | ],
68 | [
69 | 'name' => 'A3',
70 | 'score' => 'B3',
71 | ],
72 | ],
73 | 'team2' => [
74 | [
75 | 'name' => 'C2',
76 | 'score' => 'D2',
77 | ],
78 | [
79 | 'name' => 'C3',
80 | 'score' => 'D3',
81 | ],
82 | ],
83 | ];
84 | }```
85 |
86 | Note that an array of the same form will be returned.
87 |
--------------------------------------------------------------------------------
/3.1/imports/progress-bar.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # Progress Bar
6 |
7 | You can implement the `WithProgressBar` concern to display a progress bar when importing an Excel file via the console.
8 |
9 | For example, your import class could look like this:
10 |
11 | ```php
12 | $row[0],
30 | 'email' => $row[1],
31 | 'password' => Hash::make($row[2]),
32 | ]);
33 | }
34 | }
35 | ```
36 |
37 | In your console command, you'd use it as follows:
38 |
39 | ```php
40 | output->title('Starting import');
56 | (new UsersImport)->withOutput($this->output)->import('users.xlsx');
57 | $this->output->success('Import successful');
58 | }
59 | }
60 | ```
61 |
62 | By calling `php artisan import:excel` on the command line, your import will start.
63 | You should now see the start message, the progress bar and (when completed) the success message.
64 |
--------------------------------------------------------------------------------
/3.1/imports/start-row.md:
--------------------------------------------------------------------------------
1 | # Start row
2 |
3 | [[toc]]
4 |
5 | If you want to skip a certain number of rows during an import, you can specify the starting row by implementing the `WithStartRow` concern.
6 |
7 | ```php
8 | namespace App\Imports;
9 |
10 | use App\User;
11 | use Maatwebsite\Excel\Concerns\ToModel;
12 | use Maatwebsite\Excel\Concerns\WithStartRow;
13 |
14 | class UsersImport implements ToModel, WithStartRow
15 | {
16 | public function model(array $row)
17 | {
18 | return new User([
19 | 'name' => $row[0],
20 | ]);
21 | }
22 |
23 | public function startRow(): int
24 | {
25 | return 2;
26 | }
27 | }
28 | ```
29 |
--------------------------------------------------------------------------------
/3.1/imports/testing.md:
--------------------------------------------------------------------------------
1 | # Testing
2 |
3 | [[toc]]
4 |
5 | The Excel facade can be used to swap the importer to a fake.
6 |
7 | ## Testing imports
8 |
9 | ```php
10 | /**
11 | * @test
12 | */
13 | public function user_can_import_users()
14 | {
15 | Excel::fake();
16 |
17 | $this->actingAs($this->givenUser())
18 | ->get('/users/import/xlsx');
19 |
20 | Excel::assertImported('filename.xlsx', 'diskName');
21 |
22 | Excel::assertImported('filename.xlsx', 'diskName', function(UsersImport $import) {
23 | return true;
24 | });
25 |
26 | // When passing the callback as 2nd param, the disk will be the default disk.
27 | Excel::assertImported('filename.xlsx', function(UsersImport $import) {
28 | return true;
29 | });
30 | }
31 | ```
32 |
33 | ## Testing queuing imports
34 |
35 | ```php
36 | /**
37 | * @test
38 | */
39 | public function user_can_queue_the_users_import()
40 | {
41 | Excel::fake();
42 |
43 | $this->actingAs($this->givenUser())
44 | ->get('/users/queue/xlsx');
45 |
46 | Excel::assertQueued('filename.xlsx', 'diskName');
47 |
48 | Excel::assertQueued('filename.xlsx', 'diskName', function(UsersImport $import) {
49 | return true;
50 | });
51 |
52 | // When passing the callback as 2nd param, the disk will be the default disk.
53 | Excel::assertQueued('filename.xlsx', function(UsersImport $import) {
54 | return true;
55 | });
56 | }
57 | ```
58 |
59 | ## Testing imports with dynamic file name/path
60 |
61 | If you have dynamic naming for files or paths, you can use a regular expression to represent those while testing:
62 |
63 | ```php
64 | /**
65 | * @test
66 | */
67 | public function user_can_import_users()
68 | {
69 | Excel::fake();
70 |
71 | $this->actingAs($this->givenUser())
72 | ->get('/users/import/xlsx');
73 |
74 | // Tells the mock to use regular expressions
75 | Excel::matchByRegex();
76 | // For a given dynamic named file 'dynamic_1234_filename.xlsx'
77 | Excel::assertImported('/\w{7}_\d{4}\_\w{8}\.xlsx/', 'diskName');
78 | }
79 | ```
80 | Please note that your expression must match only one file/path. If more than one match is found, the test will fail.
81 |
--------------------------------------------------------------------------------
/4.x/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/4.x/architecture/concerns.md:
--------------------------------------------------------------------------------
1 | # Concerns
2 |
3 | [[toc]]
4 |
5 | Most of the export/import configuration is done by using **Concerns**.
6 |
7 | ## Contracts
8 |
9 | Concerns are basically just simple interfaces. Implementing them will make the object adhere to a
10 | certain contract. This contract can request specific methods that e.g. data can be passed through.
11 |
12 | For instance, the `FromCollection` requests the Export object to implement a `collection` method, that needs to return a `Collection` instance.
13 |
14 | ```php
15 | namespace App\Exports;
16 |
17 | use App\User;
18 | use Maatwebsite\Excel\Concerns\FromCollection;
19 |
20 | class UsersExport implements FromCollection
21 | {
22 | public function collection()
23 | {
24 | return User::all();
25 | }
26 | }
27 | ```
28 |
29 | ## Pointer interface
30 |
31 | In other cases it might not ask for any methods to be implemented, but merely functions as a pointer interface.
32 |
33 | For instance, the `ShouldAutoSize` concern doesn't pass on any specific information, but does tell the Export process that the columns need to be automatically sized.
34 |
35 | ```php
36 | namespace App\Exports;
37 |
38 | use App\User;
39 | use Maatwebsite\Excel\Concerns\ShouldAutoSize;
40 |
41 | class UsersExport implements ShouldAutoSize
42 | {
43 |
44 | }
45 | ```
46 |
--------------------------------------------------------------------------------
/4.x/exports/advanced.md:
--------------------------------------------------------------------------------
1 | # Advanced concepts
2 |
3 | [[toc]]
4 |
5 | ## Using PhpSpreadsheet
6 |
--------------------------------------------------------------------------------
/4.x/exports/concern-overview.md:
--------------------------------------------------------------------------------
1 | # Concern overview
2 |
--------------------------------------------------------------------------------
/4.x/exports/performance.md:
--------------------------------------------------------------------------------
1 | # Performance
2 |
3 | [[toc]]
4 |
5 | ## TLDR;
6 |
7 | 1 Data
8 |
9 | 2 Queuing
10 |
11 | 3 Cell caching
12 |
13 | ### Data
14 |
15 | Most important part of performance is the amount of data that is held in memory...
16 |
17 | ### Limiting data
18 |
19 | ```php
20 | public function query()
21 | {
22 | return User::query()
23 | ->with('role')
24 | ->select('users.id', 'users.name', 'users.email', 'role.name');
25 | }
26 | ```
27 |
28 | ### Joining data
29 |
30 | ```php
31 | public function query()
32 | {
33 | return User::query()
34 | ->innerJoin('roles')
35 | ->select('users.id', 'users.name', 'users.email', 'roles.name');
36 | }
37 | ```
38 |
39 | ### Skipping Eloquent hydration
40 |
41 | ```php
42 | public function query()
43 | {
44 | return DB
45 | ::table('users')
46 | ->innerJoin('roles')
47 | ->select('users.id', 'users.name', 'users.email', 'roles.name');
48 | }
49 | ```
50 |
51 | ### Using LazyCollections/Generators
52 |
53 | ```php
54 | public function collection()
55 | {
56 | return DB::table('users')->select('id', 'name', 'email')->lazy();
57 | }
58 | ```
59 |
60 | ## Queuing
61 |
62 | When the data set is too big for the user to wait sync, u can queue it.
63 |
64 | ```php
65 | class ExportUsers implements ShouldQueue
66 | {
67 | use Queuable;
68 |
69 | public $queue = 'long-running';
70 | public $timeout = 900;
71 |
72 | public function handle()
73 | {
74 | Excel::store(new UsersExport, 'users.xlsx');
75 | }
76 | }
77 | ```
78 |
79 | ## Cell caching
80 |
81 | By default PhpSpreadsheet keeps all cell values in memory, however when dealing with large files, this might result into memory issues. If you want to mitigate that, you can configure a cell caching driver here.
82 |
83 | When using the illuminate driver, it will store each value in the cache store. This can slow down the process, because it needs to store each value. However it will use less memory. It will automatically use your default cache store. However if you prefer to have the cell cache on a separate store, you can configure the store name here. You can use any store defined in your cache config. When leaving at "null" it will use the default store.
84 |
85 | You can use the "batch" store if you want to only persist to the store when the memory limit is reached. You can tweak the memory limit in the config.
86 |
--------------------------------------------------------------------------------
/4.x/exports/settings.md:
--------------------------------------------------------------------------------
1 | # Settings
2 |
3 | [[toc]]
4 |
5 | ## Properties
6 |
7 | By default the Worksheet properties get configured in `config/excel.php`. You can configure a default title, description, creator, etc.
8 |
9 | If you want to overrule on a per export basis, you can use the `WithProperties` concern.
10 |
11 | ```php
12 | namespace App\Exports;
13 |
14 | use Maatwebsite\Excel\Concerns\WithProperties;
15 |
16 | class UsersExport implements WithProperties
17 | {
18 | public function properties(): array
19 | {
20 | return [
21 | 'creator' => 'Patrick Brouwers',
22 | 'lastModifiedBy' => 'Patrick Brouwers',
23 | 'title' => 'Users Export',
24 | 'description' => 'Latest Users',
25 | 'subject' => 'Users',
26 | 'keywords' => 'users,export,spreadsheet',
27 | 'category' => 'Users',
28 | 'manager' => 'Patrick Brouwers',
29 | 'company' => 'Maatwebsite',
30 | ];
31 | }
32 | }
33 | ```
34 |
35 | It's not required to return all properties, you can ommit the keys you don't want to overrule.
36 |
37 | ```php
38 | public function properties(): array
39 | {
40 | return [
41 | 'creator' => 'Patrick Brouwers',
42 | ];
43 | }
44 | ```
45 |
46 | ## Custom CSV Settings
47 |
48 | By default Laravel Excel uses the defaults from the config (`config/excel.php`). You can change this by adding the `WithCustomCsvSettings` interface.
49 |
50 | ```php
51 | namespace App\Exports;
52 |
53 | use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;
54 |
55 | class UsersExport implements WithCustomCsvSettings
56 | {
57 | public function getCsvSettings(): array
58 | {
59 | return [
60 | 'delimiter' => ';'
61 | ];
62 | }
63 | }
64 | ```
65 |
66 | ### Available csv settings settings
67 |
68 | - delimiter
69 | - enclosure
70 | - line_ending
71 | - use_bom
72 | - include_separator_line
73 | - excel_compatibility
74 |
--------------------------------------------------------------------------------
/4.x/exports/testing.md:
--------------------------------------------------------------------------------
1 | # Testing
2 |
--------------------------------------------------------------------------------
/4.x/getting-started/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # Introduction
6 |
7 | :rocket: Laravel Excel is intended at being Laravel-flavoured PhpSpreadsheet: a simple, but elegant wrapper around PhpSpreadsheet with the goal of simplifying
8 | exports and imports.
9 |
10 | :fire: [PhpSpreadsheet](https://phpspreadsheet.readthedocs.io/) is a library written in pure PHP and providing a set of classes that allow you to read from and to write to different spreadsheet file formats, like Excel and LibreOffice Calc.
11 |
12 | ## Laravel Excel Features
13 |
14 | * Easily export collections to Excel.
15 | * Export queries with automatic chunking for better performance.
16 | * Queue exports for better performance.
17 | * Easily export Blade views to Excel.
18 | * Easily import to collections.
19 | * Read the Excel file in chunks.
20 | * Handle the import inserts in batches.
--------------------------------------------------------------------------------
/4.x/getting-started/installation.md:
--------------------------------------------------------------------------------
1 | # Installation
2 |
3 | [[toc]]
4 |
5 | ## Requirements
6 |
7 | * PHP: `^7.4\|^8.0`
8 | * Laravel: `^8.0`
9 | * PhpSpreadsheet: `^1.16`
10 | * PHP extension `php_zip` enabled
11 | * PHP extension `php_xml` enabled
12 | * PHP extension `php_gd2` enabled
13 | * PHP extension `php_iconv` enabled
14 | * PHP extension `php_simplexml` enabled
15 | * PHP extension `php_xmlreader` enabled
16 | * PHP extension `php_zlib` enabled
17 |
18 | ## Installation
19 |
20 | Require this package in the `composer.json` of your Laravel project. This will download the package and _PhpSpreadsheet_.
21 |
22 | ```
23 | composer require maatwebsite/excel
24 | ```
25 |
26 | The `Maatwebsite\Excel\ExcelServiceProvider` is __auto-discovered__ and registered by default.
27 |
28 | If you want to register it yourself, add the ServiceProvider in `config/app.php`:
29 |
30 | ```php
31 | 'providers' => [
32 | /*
33 | * Package Service Providers...
34 | */
35 | Maatwebsite\Excel\ExcelServiceProvider::class,
36 | ]
37 | ```
38 |
39 | The `Excel` facade is also __auto-discovered__.
40 |
41 | If you want to add it manually, add the Facade in `config/app.php`:
42 |
43 | ```php
44 | 'aliases' => [
45 | ...
46 | 'Excel' => Maatwebsite\Excel\Facades\Excel::class,
47 | ]
48 | ```
49 |
50 | To publish the config, run the vendor publish command:
51 |
52 | ```
53 | php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config
54 | ```
55 |
56 | This will create a new config file named `config/excel.php`.
57 |
--------------------------------------------------------------------------------
/4.x/getting-started/license.md:
--------------------------------------------------------------------------------
1 | # License
2 |
3 | [[toc]]
4 |
5 | ## MIT
6 | Our software is open source and licensed under the [MIT license](https://choosealicense.com/licenses/mit/). You are free to use the software as you like. The code can be forked and modified, but the original copyright author should always be included!
7 |
8 | ## Postcardware
9 | According to the [postcardware](https://en.wikipedia.org/wiki/Postcardware) concept, if you use the software for your project(s) we would appreciate to receive a postcard of your hometown. Please send it to:
10 |
11 | **Maatwebsite**
12 | Markt 2
13 | 6231 LS Meerssen
14 | The Netherlands
15 |
16 | ## Support
17 |
18 | ::: warning Support
19 | We hold no liability and will provide support on a best effort basis. For more information about support please see [support](https://docs.laravel-excel.com/3.1/getting-started/support.html).
20 | :::
21 |
22 | :::tip Commercial Support
23 | :rocket: If you use the software commercially and need support urgently, we can offer this on a commercial basis. Please contact or phone +31 (0)10 744 9312.
24 | :::
25 |
--------------------------------------------------------------------------------
/4.x/getting-started/support.md:
--------------------------------------------------------------------------------
1 | # Support
2 |
3 | [[toc]]
4 |
5 | Our software is free and open source, meaning that the use of our software is optional. We hold no liability and there is no obligation to support. We will provide support on best effort basis.
6 |
7 | :::tip Commercial Support
8 | If you use the software commercially and need elaborate support or need it urgently, we can offer this on a commercial basis. Please contact or via phone +31 (0)10 744 9312.
9 | :::
10 |
11 | ## Supported Versions
12 |
13 | Versions will be supported for a limited amount of time.
14 |
15 | | Version | Laravel Version | Php Version | Support |
16 | |---- |----|----|----|
17 | | 4.x | ^8.0 | ^7.4\|^8.0 | New features |
18 | | 3.1 | ^5.8\|^6.0\|^7.0\|^8.0 | ^7.2\|^8.0 | Support till ... |
19 | | 3.0 | ^5.5 | ^7.0 | Unsupported since 31-12-2018 |
20 | | 2.1 | <=5.6 | <=7.0 | Unsupported since 15-5-2018 |
21 |
22 | ::: warning PHP version support
23 | Support for PHP versions will only be maintained until the end-of-life of that PHP version.
24 | :::
25 |
26 | ## Requesting support
27 | Before you request support, please check the following:
28 | * Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
29 | * Check to make sure your support request isn't already present within the project.
30 | * Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
31 | * Use one of the [issue templates](https://github.com/SpartnerNL/Laravel-Excel/tree/3.1/.github/ISSUE_TEMPLATE).
32 |
33 | Filling out the template is required. Issues that do not include enough information might not be picked up. Please write in English (or Dutch).
34 |
35 | Please prefix your issue with one of the following: [BUG] [PROPOSAL] [QUESTION].
36 |
37 | And please be considerate towards maintainers when raising issues.
38 |
--------------------------------------------------------------------------------
/4.x/getting-started/upgrade.md:
--------------------------------------------------------------------------------
1 | # Upgrade Guide
2 |
3 | [[toc]]
4 |
5 | ## Upgrading to 4.x from 3.1
6 |
7 | Version 4.x is backwards compatible with 3.1. Only features were added.
8 |
9 | __Additions__
10 |
11 | * Column exports
12 | * Column imports
13 |
14 | __Deprecations__
15 |
16 | * Queued exports are deprecated and will be removed in 5.x. Please check the performance documentation for the new and improved way.
17 |
18 | ## Upgrading to 3.1 from 3.0
19 |
20 | Version 3.1 is backwards compatible with 3.0. Only features were added in this release.
21 |
22 | __Additions__
23 |
24 | * Imports feature.
25 | * ChunkReading
26 | * BatchInserts
27 | * Queued imports
28 | * ToArray concern for Exports.
29 | * Custom value binders for Imports and Exports.
30 |
31 | __Removals__
32 |
33 | * `Excel::filter('chunk')` method is removed, chunk filter is automatically added when using chunk reading.
34 |
35 | ## Upgrading to 3.* from 2.1
36 |
37 | Version 3.* is not backwards compatible with 2.*. It's not possible to provide a step-by-step migration guide as it's a complete paradigm shift.
38 |
39 | __New dependencies__
40 |
41 | 3.* introduces some new dependencies.
42 |
43 | * Requires PHP 7.0 or higher.
44 | * Requires Laravel 5.5 (or higher).
45 | * Requires PhpSpreadsheet instead of PHPExcel.
46 |
47 | __Deprecations__
48 |
49 | ALL Laravel Excel 2.* methods are deprecated and will not be able to use in 3.0 .
50 |
51 | - `Excel::load()` is removed and replaced by `Excel::import($yourImport)`
52 | - `Excel::create()` is removed and replaced by `Excel::download/Excel::store($yourExport)`
53 | - `Excel::create()->string('xlsx')` is removed an replaced by `Excel::raw($yourExport, Excel::XLSX)`
54 | - 3.0 provides no convenience methods for styling, you are encouraged to use PhpSpreadsheets native methods.
55 |
56 | You can find an example upgrade for an export here: [https://github.com/SpartnerNL/Laravel-Excel/issues/1799](https://github.com/SpartnerNL/Laravel-Excel/issues/1799)
57 |
--------------------------------------------------------------------------------
/4.x/imports/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | ## :rocket: 5 minute quick start
6 |
7 | :muscle: Create an import class in `app/Imports`
8 |
9 | You may do this by using the `make:import` command.
10 |
11 | ```
12 | php artisan make:import UsersImport --model=User
13 | ```
14 |
15 | The file can be found in `app/Imports`:
16 |
17 | ::: vue
18 | .
19 | ├── app
20 | │ ├── `Imports`
21 | │ │ ├── UsersImport.php
22 | │
23 | └── composer.json
24 | :::
25 |
26 | If you prefer to create the import manually, you can create the following in `app/Imports`:
27 |
28 | ```php
29 | $row[0],
48 | 'email' => $row[1],
49 | 'password' => Hash::make($row[2]),
50 | ]);
51 | }
52 | }
53 | ```
54 |
55 | :fire: In your controller you can call this import now:
56 |
57 | ```php
58 |
59 | use App\Imports\UsersImport;
60 | use Maatwebsite\Excel\Facades\Excel;
61 | use App\Http\Controllers\Controller;
62 |
63 | class UsersController extends Controller
64 | {
65 | public function import()
66 | {
67 | Excel::import(new UsersImport, 'users.xlsx');
68 |
69 | return redirect('/')->with('success', 'All good!');
70 | }
71 | }
72 | ```
73 |
74 | :page_facing_up: Find the imported users in your database!
75 |
--------------------------------------------------------------------------------
/4.x/imports/basics.md:
--------------------------------------------------------------------------------
1 | ## Importing basics
2 |
3 | [[toc]]
4 |
5 | If you have followed the 5 minute quick start, you'll already have a `UsersImport` class.
6 |
7 | ```php
8 | $row[0],
27 | 'email' => $row[1],
28 | 'password' => Hash::make($row[2]),
29 | ]);
30 | }
31 | }
32 | ```
33 |
34 | ## Importing from default disk
35 |
36 | Passing the UsersImport object to the `Excel::import()` method, will tell the package how to import the file that is passed as second parameter.
37 | The file is expected to be located in your default filesystem disk (see `config/filesystems.php`).
38 |
39 | ```php
40 | Excel::import(new UsersImport, 'users.xlsx');
41 | ```
42 |
43 | ### Importing from another disk
44 |
45 | You can specify another disk with the third parameter like your Amazon s3 disk. (see `config/filesystems.php`)
46 |
47 | ```php
48 | Excel::import(new UsersImport, 'users.xlsx', 's3');
49 | ```
50 |
51 | ## Importing uploaded files
52 |
53 | If you let your user upload the document, you can also just pass the uploaded file directly.
54 |
55 | ```php
56 | Excel::import(new UsersImport, request()->file('your_file'));
57 | ```
58 |
59 | ### Importing full path
60 |
61 | If you want to specifiy the path where your file is, without having to move it to a disk, you can directly pass that file path to the import method.
62 |
63 | ```php
64 | Excel::import(new UsersImport, storage_path('users.xlsx'));
65 | ```
66 |
67 | ## Importing to array or collection
68 |
69 | If you want to bypass the `ToArray` or `ToCollection` concerns and want to have an array of imported data in your controller (beware of performance!), you can use the `::toArray()` or `::toCollection()` method.
70 |
71 | ```php
72 | $array = Excel::toArray(new UsersImport, 'users.xlsx');
73 |
74 | $collection = Excel::toCollection(new UsersImport, 'users.xlsx');
75 | ```
76 |
77 | ## Specifying a reader type
78 |
79 | If the reader type is not detectable by the file extension, you can specify a reader type by passing it as fourth parameter.
80 |
81 | ```php
82 | Excel::import(new UsersImport, 'users.xlsx', 's3', \Maatwebsite\Excel\Excel::XLSX);
83 | ```
84 |
--------------------------------------------------------------------------------
/4.x/imports/batch-inserts.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # Batch inserts
6 |
7 | Importing a large file to Eloquent models, might quickly become a bottleneck as every row results into an insert query.
8 |
9 | With the `WithBatchInserts` concern you can limit the amount of queries done by specifying a batch size. This batch size will determine how many models will be inserted into the database in one time. This will drastically reduce the import duration.
10 |
11 | ```php
12 | namespace App\Imports;
13 |
14 | use App\User;
15 | use Maatwebsite\Excel\Concerns\ToModel;
16 | use Maatwebsite\Excel\Concerns\WithBatchInserts;
17 |
18 | class UsersImport implements ToModel, WithBatchInserts
19 | {
20 | public function model(array $row)
21 | {
22 | return new User([
23 | 'name' => $row[0],
24 | ]);
25 | }
26 |
27 | public function batchSize(): int
28 | {
29 | return 1000;
30 | }
31 | }
32 | ```
33 |
34 | :::warning ToModel
35 | This concern **only** works with the `ToModel` concern.
36 | :::
37 |
38 | :::tip Batch Size
39 | A batch size of `1000` will not be the most optimal situation for your import. Play around with this number to find the sweet spot.
40 | :::
41 |
42 | ## Batch upserts
43 |
44 | For batch upserts, you can additionally implement the `WithUpserts` concern.
45 |
46 | ```php
47 | class UsersImport implements ToModel, WithBatchInserts, WithUpserts
48 | {
49 | public function model(array $row)
50 | {
51 | return new User([
52 | 'name' => $row[0],
53 | ]);
54 | }
55 |
56 | public function batchSize(): int
57 | {
58 | return 1000;
59 | }
60 |
61 | public function uniqueBy()
62 | {
63 | return 'email';
64 | }
65 | }
66 | ```
67 |
68 | In the example above, if a user already exists with the same email, the row will be updated instead. Behind the scenes, this feature uses the Laravel `upsert` method and the `uniqueBy` method is used for the second argument of the `upsert` method, which lists the column(s) that uniquely identify records within the associated table.
69 |
70 | :::warning
71 | All databases except SQL Server require the `uniqueBy` columns to have a "primary" or "unique" index.
72 | :::
73 |
--------------------------------------------------------------------------------
/4.x/imports/collection.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # Importing to collections
6 |
7 | [[toc]]
8 |
9 | The easiest way to start an import is to create a custom import class. We'll use a user import as example.
10 |
11 | Create a new class called `UsersImport` in `app/Imports`:
12 |
13 | ```php
14 | namespace App\Imports;
15 |
16 | use App\User;
17 | use Illuminate\Support\Collection;
18 | use Maatwebsite\Excel\Concerns\ToCollection;
19 |
20 | class UsersImport implements ToCollection
21 | {
22 | public function collection(Collection $rows)
23 | {
24 | foreach ($rows as $row)
25 | {
26 | User::create([
27 | 'name' => $row[0],
28 | ]);
29 | }
30 | }
31 | }
32 | ```
33 |
34 | The collection method will receive a collection of rows. A row is an array filled with the cell values.
35 |
36 | In case of the file having multiple sheets, the `collection()` method will be called multiple times.
37 |
38 | In your controller we can now import this:
39 |
40 | ```php
41 | public function import()
42 | {
43 | Excel::import(new UsersImport, 'users.xlsx');
44 | }
45 | ```
46 |
47 | :::warning
48 | Whatever you return in the `collection()` method will **not** be returned to the controller.
49 | :::
50 |
--------------------------------------------------------------------------------
/4.x/imports/custom-csv-settings.md:
--------------------------------------------------------------------------------
1 | # Custom CSV Settings
2 |
3 | [[toc]]
4 |
5 | By default Laravel Excel uses the defaults from the config (`config/excel.php`). You can change this by adding the `WithCustomCsvSettings` interface.
6 |
7 | ```php
8 | namespace App\Imports;
9 |
10 | use Maatwebsite\Excel\Concerns\ToModel;
11 | use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;
12 |
13 | class UsersImport implements ToModel, WithCustomCsvSettings
14 | {
15 | public function model(array $row)
16 | {
17 | return new User([
18 | 'name' => $row['0'],
19 | 'email' => $row['1']
20 | ]);
21 | }
22 |
23 | public function getCsvSettings(): array
24 | {
25 | return [
26 | 'input_encoding' => 'ISO-8859-1'
27 | ];
28 | }
29 | }
30 | ```
31 |
32 |
33 | Delimiter requires a single character. For Tab use `"\t"`
34 |
35 | ```php
36 | public function getCsvSettings(): array
37 | {
38 | return [
39 | 'delimiter' => "\t"
40 | ];
41 | }
42 | ```
43 |
44 | ## Available settings
45 |
46 | * `delimiter`
47 | * `enclosure`
48 | * `escape_character`
49 | * `contiguous`
50 | * `input_encoding`
51 |
--------------------------------------------------------------------------------
/4.x/imports/custom-formatting-values.md:
--------------------------------------------------------------------------------
1 | # Custom Formatting Values
2 |
3 | [[toc]]
4 |
5 | ## Value Binder
6 |
7 | By default Laravel Excel uses PhpSpreadsheet's default value binder to intelligently format a cell's value when reading it. You may override this behavior by implementing the `WithCustomValueBinder` concern and the `bindValue` method. Your import class may also extend `DefaultValueBinder` to return the default behavior.
8 |
9 | ```php
10 | namespace App\Imports;
11 |
12 | use PhpOffice\PhpSpreadsheet\Cell\Cell;
13 | use Maatwebsite\Excel\Concerns\ToModel;
14 | use PhpOffice\PhpSpreadsheet\Cell\DataType;
15 | use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
16 | use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
17 |
18 | class UsersImport extends DefaultValueBinder implements WithCustomValueBinder, ToModel
19 | {
20 | public function bindValue(Cell $cell, $value)
21 | {
22 | if (is_numeric($value)) {
23 | $cell->setValueExplicit($value, DataType::TYPE_NUMERIC);
24 |
25 | return true;
26 | }
27 |
28 | // else return default behavior
29 | return parent::bindValue($cell, $value);
30 | }
31 | }
32 | ```
33 |
34 | ## Available DataTypes
35 |
36 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING`
37 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_FORMULA`
38 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NUMERIC`
39 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_BOOL`
40 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_NULL`
41 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_INLINE`
42 | * `PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_ERROR`
43 |
44 | ## Disable intelligent formatting
45 |
46 | If you want to disable the intelligent formatting of values, you can extend your import class with `\PhpOffice\PhpSpreadsheet\Cell\StringValueBinder`. In this case all values are passed on as strings.
47 |
48 | ```php
49 | namespace App\Imports;
50 |
51 | use Maatwebsite\Excel\Concerns\ToModel;
52 | use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
53 |
54 | class UsersImport extends \PhpOffice\PhpSpreadsheet\Cell\StringValueBinder implements WithCustomValueBinder, ToModel
55 | {
56 |
57 | }
58 | ```
59 |
60 | ## Default Value Binder
61 |
62 | If you want to use one value binder for all your imports, you can configure the default value binder in the config.
63 |
64 | In `config/excel.php`:
65 |
66 | ```php
67 | 'value_binder' => [
68 | 'default' => Maatwebsite\Excel\DefaultValueBinder::class,
69 | ],
70 | ```
71 |
--------------------------------------------------------------------------------
/4.x/imports/import-formats.md:
--------------------------------------------------------------------------------
1 | # Import formats
2 |
3 | [[toc]]
4 |
5 | By default, the import format is determined by the extension of the file. If you want
6 | to explicitly configure the import format, you can pass it through as 3rd parameter.
7 |
8 | ## XLSX
9 |
10 | ```php
11 | (new UsersImport)->import('users.xlsx', null, \Maatwebsite\Excel\Excel::XLSX);
12 | ```
13 |
14 | ## CSV
15 |
16 | ```php
17 | (new UsersImport)->import('users.csv', null, \Maatwebsite\Excel\Excel::CSV);
18 | ```
19 |
20 | ## TSV
21 |
22 | ```php
23 | (new UsersImport)->import('users.tsv', null, \Maatwebsite\Excel\Excel::TSV);
24 | ```
25 |
26 | ## ODS
27 |
28 | ```php
29 | (new UsersImport)->import('users.ods', null, \Maatwebsite\Excel\Excel::ODS);
30 | ```
31 |
32 | ## XLS
33 |
34 | ```php
35 | (new UsersImport)->import('users.xls', null, \Maatwebsite\Excel\Excel::XLS);
36 | ```
37 |
38 | ## SLK
39 |
40 | ```php
41 | (new UsersImport)->import('users.slk', null, \Maatwebsite\Excel\Excel::SLK);
42 | ```
43 |
44 | ## XML
45 |
46 | ```php
47 | (new UsersImport)->import('users.xml', null, \Maatwebsite\Excel\Excel::XML);
48 | ```
49 |
50 | ## GNUMERIC
51 |
52 | ```php
53 | (new UsersImport)->import('users.gnumeric', null, \Maatwebsite\Excel\Excel::GNUMERIC);
54 | ```
55 |
56 | ## HTML
57 |
58 | ```php
59 | (new UsersImport)->import('users.html', null, \Maatwebsite\Excel\Excel::HTML);
60 | ```
61 |
--------------------------------------------------------------------------------
/4.x/imports/importables.md:
--------------------------------------------------------------------------------
1 | # Importables
2 |
3 | [[toc]]
4 |
5 | In the previous example, we used the `Excel::import` facade to start an import.
6 |
7 | Laravel Excel also provides a `Maatwebsite\Excel\Concerns\Importable` trait, to make import classes importable.
8 |
9 | ```php
10 | namespace App\Imports;
11 |
12 | use App\User;
13 | use Maatwebsite\Excel\Concerns\ToModel;
14 | use Maatwebsite\Excel\Concerns\Importable;
15 |
16 | class UsersImport implements ToModel
17 | {
18 | use Importable;
19 |
20 | public function model(array $row)
21 | {
22 | return new User([
23 | 'name' => $row[0],
24 | ]);
25 | }
26 | }
27 | ```
28 |
29 | ## Importing
30 |
31 | We can now import without the need for the facade:
32 |
33 | ```php
34 | (new UsersImport)->import('users.xlsx', 'local', \Maatwebsite\Excel\Excel::XLSX);
35 | ```
36 |
37 | ## Queuing
38 |
39 | Or queue the import:
40 |
41 | ```php
42 | (new UsersImport)->queue('users.xlsx');
43 | ```
44 |
45 | ## To array
46 |
47 | The import can be loaded into an array :
48 |
49 | ```php
50 | $array = (new UsersImport)->toArray('users.xlsx');
51 | ```
52 |
53 | ## To collection
54 |
55 | The import can be loaded into a collection:
56 |
57 | ```php
58 | $collection = (new UsersImport)->toCollection('users.xlsx');
59 | ```
--------------------------------------------------------------------------------
/4.x/imports/mapped-cells.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # Mapped Cells
6 |
7 | In case you have a more custom spreadsheet and only want to access specific **cells**, you can implement the `WithMappedCells` concern.
8 |
9 | You might have a speadsheet looking like this:
10 |
11 | |name | Patrick Brouwers|
12 | |---- |----|
13 | | email | patrick@maatwebsite.nl |
14 |
15 | We can now map `name` to `B1` and `email` to `B2`. The value of those coordinates will then be available under the given array key.
16 |
17 | ```php
18 | namespace App\Imports;
19 |
20 | use App\User;
21 | use Maatwebsite\Excel\Concerns\ToModel;
22 | use Maatwebsite\Excel\Concerns\WithMappedCells;
23 |
24 | class UsersImport implements WithMappedCells, ToModel
25 | {
26 | public function mapping(): array
27 | {
28 | return [
29 | 'name' => 'B1',
30 | 'email' => 'B2',
31 | ];
32 | }
33 |
34 | public function model(array $row)
35 | {
36 | return new User([
37 | 'name' => $row['name'],
38 | 'email' => $row['email'],
39 | ]);
40 | }
41 | }
42 | ```
43 |
44 | ::: warning
45 | This concern is not meant to map **columns**, only specific **cell** reference are allowed.
46 | :::
47 |
48 | ## Multi-demensional Mapping
49 |
50 | In case you have repeating data in your table, e. g. a spreadsheet looking like this:
51 |
52 | | Team 1 | | Team 2| |
53 | |-|-|-|-|
54 | | Max | 2 | Peter | 3 |
55 | | Annie | 0 | Alex | 1 |
56 |
57 | you are also able to define cell coordinates in a nested array:
58 |
59 | ```php
60 | public function mapping(): array
61 | {
62 | return [
63 | 'team1' => [
64 | [
65 | 'name' => 'A2',
66 | 'score' => 'B2',
67 | ],
68 | [
69 | 'name' => 'A3',
70 | 'score' => 'B3',
71 | ],
72 | ],
73 | 'team2' => [
74 | [
75 | 'name' => 'C2',
76 | 'score' => 'D2',
77 | ],
78 | [
79 | 'name' => 'C3',
80 | 'score' => 'D3',
81 | ],
82 | ],
83 | ];
84 | }```
85 |
86 | Note that an array of the same form will be returned.
87 |
--------------------------------------------------------------------------------
/4.x/imports/progress-bar.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # Progress Bar
6 |
7 | You can implement the `WithProgressBar` concern to display a progress bar when importing an Excel file via the console.
8 |
9 | For example, your import class could look like this:
10 |
11 | ```php
12 | $row[0],
30 | 'email' => $row[1],
31 | 'password' => Hash::make($row[2]),
32 | ]);
33 | }
34 | }
35 | ```
36 |
37 | In your console command, you'd use it as follows:
38 |
39 | ```php
40 | output->title('Starting import');
56 | (new UsersImport)->withOutput($this->output)->import('users.xlsx');
57 | $this->output->success('Import successful');
58 | }
59 | }
60 | ```
61 |
62 | By calling `php artisan import:excel` on the command line, your import will start.
63 | You should now see the start message, the progress bar and (when completed) the success message.
64 |
--------------------------------------------------------------------------------
/4.x/imports/testing.md:
--------------------------------------------------------------------------------
1 | # Testing
2 |
3 | [[toc]]
4 |
5 | The Excel facade can be used to swap the importer to a fake.
6 |
7 | ## Testing imports
8 |
9 | ```php
10 | /**
11 | * @test
12 | */
13 | public function user_can_import_users()
14 | {
15 | Excel::fake();
16 |
17 | $this->actingAs($this->givenUser())
18 | ->get('/users/import/xlsx');
19 |
20 | Excel::assertImported('filename.xlsx', 'diskName');
21 |
22 | Excel::assertImported('filename.xlsx', 'diskName', function(UsersImport $import) {
23 | return true;
24 | });
25 |
26 | // When passing the callback as 2nd param, the disk will be the default disk.
27 | Excel::assertImported('filename.xlsx', function(UsersImport $import) {
28 | return true;
29 | });
30 | }
31 | ```
32 |
33 | ## Testing queuing imports
34 |
35 | ```php
36 | /**
37 | * @test
38 | */
39 | public function user_can_queue_the_users_import()
40 | {
41 | Excel::fake();
42 |
43 | $this->actingAs($this->givenUser())
44 | ->get('/users/queue/xlsx');
45 |
46 | Excel::assertQueued('filename.xlsx', 'diskName');
47 |
48 | Excel::assertQueued('filename.xlsx', 'diskName', function(UsersImport $import) {
49 | return true;
50 | });
51 |
52 | // When passing the callback as 2nd param, the disk will be the default disk.
53 | Excel::assertQueued('filename.xlsx', function(UsersImport $import) {
54 | return true;
55 | });
56 | }
57 | ```
58 |
59 | ## Testing imports with dynamic file name/path
60 |
61 | If you have dynamic naming for files or paths, you can use a regular expression to represent those while testing:
62 |
63 | ```php
64 | /**
65 | * @test
66 | */
67 | public function user_can_import_users()
68 | {
69 | Excel::fake();
70 |
71 | $this->actingAs($this->givenUser())
72 | ->get('/users/import/xlsx');
73 |
74 | // Tells the mock to use regular expressions
75 | Excel::matchByRegex();
76 | // For a given dynamic named file 'dynamic_1234_filename.xlsx'
77 | Excel::assertImported('/\w{7}_\d{4}\_\w{8}\.xlsx/', 'diskName');
78 | }
79 | ```
80 | Please note that your expression must match only one file/path. If more than one match is found, the test will fail.
81 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/csv/1.0/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/csv/1.0/exports/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # :rocket: 5 minute quick start
6 |
7 | [[toc]]
8 |
9 | :muscle: Create an export class in `app/Exports`
10 |
11 | ::: vue
12 | .
13 | ├── app
14 | │ ├── `Exports`
15 | │ │ ├── UsersExport.php
16 | :::
17 |
18 | ```php
19 | namespace App\Exports;
20 |
21 | use App\User;
22 | use Maatwebsite\LaravelCsv\Concerns\FromCollection;
23 |
24 | class UsersExport implements FromCollection
25 | {
26 | public function collection()
27 | {
28 | return User::all();
29 | }
30 | }
31 | ```
32 |
33 | :fire: In your controller you can call this export now:
34 |
35 | ```php
36 |
37 | use App\Exports\UsersExport;
38 | use App\Http\Controllers\Controller;
39 | use Maatwebsite\LaravelCsv\Facades\Csv;
40 |
41 | class UsersController extends Controller
42 | {
43 | public function export()
44 | {
45 | return Csv::download(new UsersExport, 'users.csv');
46 | }
47 | }
48 | ```
49 |
50 | :page_facing_up: Find your `users.csv` in your downloads folder!
--------------------------------------------------------------------------------
/csv/1.0/exports/collection.md:
--------------------------------------------------------------------------------
1 | # Exporting collections
2 |
3 | [[toc]]
4 |
5 | Create a new class called `UsersExport` in `app/Exports`:
6 |
7 | ::: vue
8 | .
9 | ├── app
10 | │ ├── `Exports`
11 | │ │ ├── UsersExport.php
12 | :::
13 |
14 | ```php
15 | [
13 | 'delimiter' => ',',
14 | 'enclosure' => '"',
15 | 'line_ending' => "\n",
16 | ],
17 | ];
18 | ```
19 |
20 | The default values match the default values used by League/Csv.
21 |
22 | __NB:__ The _delimiter_ and _enclosure_ both must be exactly one character in length.
23 |
24 | ## Query chunk size
25 | You can also customize the chunk size, which impacts performance for FromQuery concerns, as follows:
26 |
27 | ```php
28 | [
32 | 'chunk_size' => 10000,
33 | ],
34 | ];
35 | ```
36 |
37 | ::: warning
38 | You might need to find the sweet spot for your application, however we've experienced chunks bigger than 20000 to become slower.
39 | :::
--------------------------------------------------------------------------------
/csv/1.0/exports/exportables.md:
--------------------------------------------------------------------------------
1 | # Exportables
2 |
3 | [[toc]]
4 |
5 | In the previous example, we used the `Csv::download` facade to start an export.
6 |
7 | Laravel CSV also provides a `Maatwebsite\LaravelCsv\Concerns\Exportable` trait, to make export classes exportable.
8 |
9 | ```php
10 | download('users.csv');
33 | ```
34 |
35 | You can also pass optional headers to the download method:
36 |
37 | ```php
38 | return (new UsersExport)->download('users.csv', ['Content-Type' => 'text/csv']);
39 | ```
40 |
41 | Or store it on a disk:
42 |
43 | ```php
44 | return (new UsersExport)->store('users.csv', 's3');
45 | ```
46 |
47 | You can also pass options to the disk if you like:
48 |
49 | ```php
50 | return (new UsersExport)->store('users.csv', 's3', 'public');
51 | ```
52 |
53 | ## Responsable
54 |
55 | The previous (download) example can be made even shorter when adding Laravel's `Responsable` interface to the export class:
56 |
57 | ```php
58 | namespace App\Exports;
59 |
60 | use App\User;
61 | use Illuminate\Contracts\Support\Responsable;
62 | use Maatwebsite\LaravelCsv\Concerns\Exportable;
63 | use Maatwebsite\LaravelCsv\Concerns\FromCollection;
64 |
65 | class UsersExport implements FromCollection, Responsable
66 | {
67 | use Exportable;
68 |
69 | /**
70 | * It's required to define the fileName within
71 | * the export class when making use of Responsable.
72 | */
73 | private $fileName = 'users.csv';
74 |
75 | /**
76 | * Optional headers
77 | */
78 | private $headers = [
79 | 'Content-Type' => 'text/csv',
80 | ];
81 |
82 | public function collection()
83 | {
84 | return User::all();
85 | }
86 | }
87 | ```
88 |
89 | You can now easily return the export class, without the need of calling `->download()`.
90 |
91 | ```php
92 | return new UsersExport();
93 | ```
94 |
--------------------------------------------------------------------------------
/csv/1.0/exports/from-query.md:
--------------------------------------------------------------------------------
1 | # From Query
2 |
3 | [[toc]]
4 |
5 | Create a new class called `UsersExport` in `app/Exports`:
6 |
7 | ::: vue
8 | .
9 | ├── app
10 | │ ├── `Exports`
11 | │ │ ├── UsersExport.php
12 | :::
13 |
14 | ```php
15 | 10000,
58 | ];
59 | ```
60 |
--------------------------------------------------------------------------------
/csv/1.0/exports/heading-row.md:
--------------------------------------------------------------------------------
1 | # Heading row
2 |
3 | [[toc]]
4 |
5 |
6 | ## Adding a heading row
7 |
8 | A heading row can easily be added by adding the `WithHeadings` concern. The heading row will be added
9 | as very first row of the file.
10 |
11 | ```php
12 |
13 | use Maatwebsite\Excel\Concerns\FromQuery;
14 | use Maatwebsite\Excel\Concerns\WithHeadings;
15 |
16 | class InvoicesExport implements FromQuery, WithHeadings
17 |
18 | public function headings(): array
19 | {
20 | return [
21 | '#',
22 | 'Date',
23 | ];
24 | }
25 | }
26 | ```
27 |
28 | ## Multiple rows
29 | It is possible to return multiple heading rows. These will be added as the first x rows.
30 | Example:
31 | ```php
32 |
33 | use Maatwebsite\Excel\Concerns\FromQuery;
34 | use Maatwebsite\Excel\Concerns\WithHeadings;
35 |
36 | class InvoicesExport implements FromQuery, WithHeadings
37 |
38 | public function headings(): array
39 | {
40 | return [
41 | ['#', 'date'],
42 | ['Amount', 'Status'],
43 | ];
44 | }
45 | }
46 | ```
47 |
48 | This would result in the following export:
49 | ```
50 | "#","date"
51 | "amount","status"
52 | ```
--------------------------------------------------------------------------------
/csv/1.0/exports/mapping.md:
--------------------------------------------------------------------------------
1 | # Mapping data
2 |
3 | [[toc]]
4 |
5 | ## Mapping rows
6 |
7 | By adding `WithMapping` you map the data that needs to be added as row. This way you have control over the actual source for each column.
8 | In case of using the Eloquent query builder:
9 |
10 | ```php
11 |
12 | use App\Invoice;
13 | use Maatwebsite\LaravelCsv\Concerns\FromQuery;
14 | use Maatwebsite\LaravelCsv\Concerns\WithMapping;
15 |
16 | class InvoicesExport implements FromQuery, WithMapping
17 |
18 | /**
19 | * @var Invoice $invoice
20 | */
21 | public function map($invoice): array
22 | {
23 | return [
24 | $invoice->invoice_number,
25 | $invoice->created_at,
26 | ];
27 | }
28 | }
29 | ```
30 |
31 | ## Multiple rows
32 | When mapping data, you can also return multiple rows.
33 |
34 | Example:
35 | ```php
36 |
37 | use Maatwebsite\Excel\Concerns\FromQuery;
38 | use Maatwebsite\Excel\Concerns\WithHeadings;
39 |
40 | class InvoicesExport implements FromQuery, WithHeadings, WithMapping
41 |
42 | /**
43 | * @var Invoice $invoice
44 | */
45 | public function map($invoice): array
46 | {
47 | return [
48 | [
49 | $invoice->invoice_number,
50 | $invoice->created_at,
51 | ],
52 | [
53 | $invoice->order->amount,
54 | $invoice->order->status,
55 | ]
56 | ];
57 | }
58 | }
59 | ```
60 |
61 | This would result in the following export:
62 | ```
63 | "#","date"
64 | "amount","status"
65 | "201901564","2019-07-04"
66 | "350","paid"
67 | "201901566","2019-07-03"
68 | "645","pending"
69 | "201901568","2019-07-02"
70 | "100","paid"
71 | "201901458","2019-07-01"
72 | "999","cancelled"
73 | ```
--------------------------------------------------------------------------------
/csv/1.0/exports/queued.md:
--------------------------------------------------------------------------------
1 | # Queued
2 |
3 | [[toc]]
4 |
5 | In case you are working with a lot of data, it might be wise to queue the entire process.
6 |
7 | Create a new class called `UsersExport` in `app/Exports`:
8 |
9 | ::: vue
10 | .
11 | ├── app
12 | │ ├── `Exports`
13 | │ │ ├── UsersExport.php
14 | :::
15 |
16 | ```php
17 | chain([
65 | new AfterQueueExportJob(),
66 | ]);
67 | }
68 | }
69 | ```
70 |
71 | If you use the `store` method instead of the `queue` method, but the export class implements `ShouldQueue`,
72 | then `Csv::store` will still return a `PendingDispatch` instance, so this will still work:
73 | ```php
74 | use App\Exports\UsersExport;
75 | use App\Http\Controllers\Controller;
76 | use Maatwebsite\LaravelCsv\Facades\Csv;
77 |
78 | class UsersController extends Controller
79 | {
80 | public function export()
81 | {
82 | $queuedJob = Csv::store(new UsersExport, 'users.csv');
83 | $queuedJob->chain([
84 | new AfterQueueExportJob(),
85 | ]);
86 | }
87 | }
88 | ```
--------------------------------------------------------------------------------
/csv/1.0/exports/store.md:
--------------------------------------------------------------------------------
1 | # Storing exports on disk
2 |
3 | [[toc]]
4 |
5 | The store functionality uses the default Storage disk. It's possible to choose a different disk as well as custom disk options.
6 |
7 | In your controller you can customize the export like this:
8 |
9 | ```php
10 |
11 | use App\Exports\UsersExport;
12 | use App\Http\Controllers\Controller;
13 | use Maatwebsite\LaravelCsv\Facades\Csv;
14 |
15 | class UsersController extends Controller
16 | {
17 | public function export()
18 | {
19 | return Csv::store(
20 | new UsersExport,
21 | 'users.csv',
22 | 's3',
23 | 'public'
24 | );
25 | }
26 | }
27 | ```
28 |
29 | ## Disk options
30 | The disk option accepts:
31 | * disk name (_string_)
32 | * visibility option (_string_)
33 | * more advanced options (_array_)
34 |
--------------------------------------------------------------------------------
/csv/1.0/getting-started/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: no-toc
3 | ---
4 |
5 | # Introduction
6 |
7 | :rocket: Laravel CSV is intended to be a Laravel-flavoured [League/Csv](https://csv.thephpleague.com/): a simple, but elegant wrapper around League/Csv with the goal of simplifying
8 | large exports.
9 |
10 | :fire: [League/Csv](https://csv.thephpleague.com/) is designed for developers who want to deal with CSV data using modern code and without the high levels of bootstrap and low levels of usefulness provided by existing core functions or third party-code.
11 |
12 | ## Laravel CSV Features
13 |
14 | * Easily export collections to CSV.
15 | * Export queries with automatic chunking for better performance.
16 | * Queue exports for better performance.
17 | * Download or store exports.
18 |
--------------------------------------------------------------------------------
/csv/1.0/getting-started/contributing.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | [[toc]]
4 |
5 | Please read and understand the contribution guide before creating an issue or pull request.
6 |
7 | ## Important Links
8 |
9 | - [Docs](https://docs.laravel-excel.com/)
10 | - [Issue tracker](https://github.com/SpartnerNL/Laravel-Csv/issues)
11 | - [Support](/csv/1.0/getting-started/support.html)
12 |
13 | ## Etiquette
14 |
15 | This project is an open source project, and as such, the maintainers use their free time to build and maintain it.
16 | The code is freely available and can be used, forked and modified.
17 |
18 | Please be considerate towards maintainers when raising issues or presenting pull requests.
19 |
20 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
21 | quality to benefit the project. Many developers have different skill sets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
22 |
23 | ## Viability
24 |
25 | When requesting or submitting new features, first consider whether it might be useful to others. Open
26 | source projects are used by many developers, who may have entirely different needs to your own. Think about
27 | whether or not your feature is likely to be used by other users of the project.
28 |
29 | ## How to submit changes?
30 |
31 | - Check the codebase to ensure that your feature doesn't already exist.
32 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
33 | - Use the [pull request template](https://github.com/SpartnerNL/Laravel-Excel/blob/3.1/.github/PULL_REQUEST_TEMPLATE.md).
34 |
35 | ## How to report a bug?
36 |
37 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
38 | - Check to make sure your bug report isn't already present within the project.
39 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
40 | - Check the pull requests tab to ensure that the feature isn't already in progress.
41 | - Use the [bug template](https://github.com/SpartnerNL/Laravel-Excel/blob/3.1/.github/ISSUE_TEMPLATE/1_Bug_report.md).
42 |
43 | ## Requirements
44 |
45 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)**. - Style will get automatically fixed by StyleCI.
46 | - **Add tests backing up your change!** - You can run the test by running `vendor/bin/phpunit`
47 | - **Document any change in behaviour** - Documentation is located in the [https://github.com/SpartnerNL/laravel-excel-docs](https://github.com/SpartnerNL/laravel-excel-docs)
48 | - **One feature per Pull Request**
49 | - **Add meaningful commit messages**
50 |
--------------------------------------------------------------------------------
/csv/1.0/getting-started/installation.md:
--------------------------------------------------------------------------------
1 | # Installation
2 |
3 | [[toc]]
4 |
5 | ## Requirements
6 |
7 | * PHP: `^7.2`
8 | * Laravel: `^5.8`
9 | * League/Csv: `^9.0`
10 |
11 | ## Installation
12 |
13 | Require Laravel CSV in the `composer.json` of your Laravel project. This will download the package and _League/Csv_.
14 |
15 | ```
16 | composer require maatwebsite/laravel-csv
17 | ```
18 |
19 | The `Maatwebsite\LaravelCsv\LaravelCsvServiceProvider` is __auto-discovered__ and registered by default.
20 |
21 | If you want to register it yourself, add the ServiceProvider in `config/app.php`:
22 |
23 | ```php
24 | 'providers' => [
25 | /*
26 | * Package Service Providers...
27 | */
28 | Maatwebsite\LaravelCsv\LaravelCsvServiceProvider::class,
29 | ]
30 | ```
31 |
32 | The `Csv` facade is also __auto-discovered__.
33 |
34 | If you want to add it manually, add the Facade in `config/app.php`:
35 |
36 | ```php
37 | 'aliases' => [
38 | ...
39 | 'Csv' => Maatwebsite\LaravelCsv\Facades\Csv::class,
40 | ]
41 | ```
42 |
43 | To publish the config, run the `vendor:publish` command:
44 |
45 | ```
46 | php artisan vendor:publish --provider="Maatwebsite\LaravelCsv\LaravelCsvServiceProvider"
47 | ```
48 |
49 | This will create a new config file named `config/csv.php`.
50 |
--------------------------------------------------------------------------------
/csv/1.0/getting-started/license.md:
--------------------------------------------------------------------------------
1 | # License
2 |
3 | [[toc]]
4 |
5 | ## MIT
6 | Our software is open source and licensed under the [MIT license](https://choosealicense.com/licenses/mit/). You are free to use the software as you like. The code can be forked and modified, but the original copyright author should always be included!
7 |
8 | ## Postcardware
9 | According to the [postcardware](https://en.wikipedia.org/wiki/Postcardware) concept, if you use the software for your project(s) we would appreciate to receive a postcard of your hometown. Please send it to:
10 |
11 | **Maatwebsite**
12 | Markt 2
13 | 6231 LS Meerssen
14 | The Netherlands
15 |
16 | ## Support
17 |
18 | ::: warning Support
19 | We hold no liability and will provide support on a best effort basis. For more information about support please see [support](/csv/1.0/getting-started/support.html).
20 | :::
21 |
22 | :::tip Commercial Support
23 | :rocket: If you use the software commercially and need support urgently, we can offer this on a commercial basis. Please contact or phone +31 (0)10 744 9312.
24 | :::
25 |
--------------------------------------------------------------------------------
/csv/1.0/getting-started/support.md:
--------------------------------------------------------------------------------
1 | # Support
2 |
3 | [[toc]]
4 |
5 | Our software is free and open source, meaning that the use of our software is optional. We hold no liability and there is no obligation to support. We will provide support on a best effort basis.
6 |
7 | :::tip Commercial Support
8 | If you use the software commercially and need elaborate support or need it urgently, we can offer this on a commercial basis. Please contact or via phone +31 (0)10 744 9312.
9 | :::
10 |
11 | ## Supported Versions
12 |
13 | Versions will be supported for a limited amount of time.
14 |
15 | | Version | Laravel Version | Php Version | Support |
16 | |---- |----|----|----|
17 | | 1.0 | ^5.8 | ^7.2 | New features |
18 |
19 | ::: warning PHP version support
20 | Support for PHP versions will only be maintained for a period of six months beyond the end-of-life of that PHP version.
21 | :::
22 |
23 | ## Requesting support
24 | Before you request support, please check the following:
25 | * Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
26 | * Check to make sure your support request isn't already present within the project.
27 | * Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
28 | * Use one of the [issue templates](https://github.com/SpartnerNL/Laravel-Excel/tree/3.1/.github/ISSUE_TEMPLATE).
29 |
30 | Filling out the template is required. Issues that do not include enough information might not be picked up. Please write in English (or Dutch).
31 |
32 | Please prefix your issue with one of the following: [BUG] [PROPOSAL] [QUESTION].
33 |
34 | And please be considerate towards maintainers when raising issues.
35 |
--------------------------------------------------------------------------------
/csv/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/nova/1.0/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/nova/1.1/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/nova/1.x/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/nova/1.x/exports/README.md:
--------------------------------------------------------------------------------
1 | ## :rocket: 5 minute quick start
2 |
3 | :bulb: Require this package in the `composer.json` of your Laravel project. This will download the package and Laravel Excel.
4 |
5 | ```
6 | composer require maatwebsite/laravel-nova-excel
7 | ```
8 |
9 | :muscle: Go to your Nova resource. As example we'll use the `app/Nova/User.php`. Add `Maatwebsite\LaravelNovaExcel\Actions\DownloadExcel` action to your `actions()` list.
10 |
11 | ```php
12 | askForFilename()
21 | ];
22 | }
23 | ```
24 |
25 | The user will now be prompted with the question how he wants to name the file.
26 |
27 | 
28 |
29 | :bulb: If you want to have a custom label, you can simply pass that via the method: `(new DownloadExcel())->askForFilename(__('Filename for your export'))`
30 |
31 | :::warning
32 | When not specifying any default writer type, the user can control the file type by typing an extensions in the filename.
33 | E.g. `users.csv` will result into an Csv document. If the user doesn't specify any extension, it will default to `.xlsx`.
34 |
35 | If you don't want the user to have this kind of control,make sure to use `withWriterType()`.
36 | :::
37 |
38 | ## Asking the user for the writer type
39 |
40 | If you want your users to choose their own writer type when exporting a resource, you can use the `askForWriterType()` interaction.
41 |
42 | ```php
43 | /**
44 | * Get the actions available for the resource.
45 | *
46 | * @param \Illuminate\Http\Request $request
47 | *
48 | * @return array
49 | */
50 | public function actions(Request $request)
51 | {
52 | return [
53 | (new DownloadExcel())->askForWriterType()
54 | ];
55 | }
56 | ```
57 |
58 | 
59 |
60 | :bulb: If you want to specify the options the user can choose yourself, you can pass them via the `askForWriterType`:
61 |
62 | ```php
63 | /**
64 | * Get the actions available for the resource.
65 | *
66 | * @param \Illuminate\Http\Request $request
67 | *
68 | * @return array
69 | */
70 | public function actions(Request $request)
71 | {
72 | return [
73 | (new DownloadExcel)->askForWriterType([
74 | \Maatwebsite\Excel\Excel::CSV => __('Csv document'),
75 | ]),
76 | ];
77 | }
78 | ```
79 |
80 | :bulb: If you want to have a custom label, you can simply pass that via the method: `(new DownloadExcel())->askForWriterType(null, __('Filename for your export'))`
81 |
82 |
--------------------------------------------------------------------------------
/nova/1.x/exports/queued.md:
--------------------------------------------------------------------------------
1 | # Queued
2 |
3 | When dealing with a large resource selection (e.g. +20k models), you can choose to queue your export.
4 |
5 | In your resource class, add the `Maatwebsite\LaravelNovaExcel\Actions\QueuedExport` to `actions()`.
6 |
7 | ```php
8 | use Maatwebsite\LaravelNovaExcel\Actions\QueuedExport;
9 |
10 | public function actions(Request $request)
11 | {
12 | return [
13 | new QueuedExport(),
14 | ];
15 | }
16 | ```
17 |
18 | Now you should see "Export To Excel" in your list of actions.
19 |
20 | 
21 |
22 | The `users.xlxs` file will be stored in your `default` storage folder.
23 | Behind the scenes the query is chunked with a chunk count of **200** and each chunk is queued.
24 |
25 | You can customize this by using the `withChunkCount()` method.
26 |
27 | ```php
28 | /**
29 | * Get the actions available for the resource.
30 | *
31 | * @param \Illuminate\Http\Request $request
32 | *
33 | * @return array
34 | */
35 | public function actions(Request $request)
36 | {
37 | return [
38 | (new QueuedExport)->withChunkCount(1000),
39 | ];
40 | }
41 | ```
42 |
43 | ::: warning
44 | Queueing downloads is not supported! You can only queue exports that are stored to the disk.
45 | :::
46 |
--------------------------------------------------------------------------------
/nova/1.x/exports/store.md:
--------------------------------------------------------------------------------
1 | # Storing exports
2 |
3 | To store a resource export to a disk, add the `Maatwebsite\LaravelNovaExcel\Actions\ExportToExcel` to `actions()`.
4 |
5 | ```php
6 | use Maatwebsite\LaravelNovaExcel\Actions\ExportToExcel;
7 |
8 | public function actions(Request $request)
9 | {
10 | return [
11 | new ExportToExcel(),
12 | ];
13 | }
14 | ```
15 |
16 | Now you should see "Export To Excel" in your list of actions.
17 |
18 | 
19 |
20 | The `users.xlxs` file will be stored in your `default` storage folder. By default Laravel-settings this will be `storage/app`.
--------------------------------------------------------------------------------
/nova/1.x/getting-started/README.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | :rocket: Supercharge your Laravel Nova resource exports
4 |
5 | - **Easily export resources to Excel.** Supercharge your Nova resources and export them directly to an Excel or CSV document. Exporting has never been so easy.
6 |
7 | - **Supercharged resource exports.** Export resources with automatic chunking for better performance. You provide us the query, we handle the performance. Exporting even larger resources? No worries, Laravel Nova Excel has your back. You can queue your exports so all of this happens in the background.
8 |
9 | - **Export based on filters and selection.** Select or filter only certain resources and export only those to Excel!
10 |
11 | - **Export lenses.** Got custom lenses defined? When exporting from a lens, it will use the query of the lens to determine which data needs to be exported!
12 |
--------------------------------------------------------------------------------
/nova/1.x/getting-started/contributing.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | [[toc]]
4 |
5 | Please read and understand the contribution guide before creating an issue or pull request.
6 |
7 | ## Important Links
8 |
9 | - [Docs](https://docs.laravel-excel.com/)
10 | - [Issue tracker](https://github.com/SpartnerNL/Laravel-Nova-Excel/issues)
11 | - [Support](/nova/1.1/getting-started/support.html)
12 |
13 | ## Etiquette
14 |
15 | This project is an open source project, and as such, the maintainers use their free time to build and maintain it.
16 | The code is freely available and can be used, forked and modified.
17 |
18 | Please be considerate towards maintainers when raising issues or presenting pull requests.
19 |
20 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
21 | quality to benefit the project. Many developers have different skill sets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
22 |
23 | ## Viability
24 |
25 | When requesting or submitting new features, first consider whether it might be useful to others. Open
26 | source projects are used by many developers, who may have entirely different needs to your own. Think about
27 | whether or not your feature is likely to be used by other users of the project.
28 |
29 | ## How to submit changes?
30 |
31 | - Check the codebase to ensure that your feature doesn't already exist.
32 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
33 | - Use the [pull request template](https://github.com/SpartnerNL/Laravel-Excel/blob/3.1/.github/PULL_REQUEST_TEMPLATE.md).
34 |
35 | ## How to report a bug?
36 |
37 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
38 | - Check to make sure your bug report isn't already present within the project.
39 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
40 | - Check the pull requests tab to ensure that the feature isn't already in progress.
41 | - Use the [bug template](https://github.com/SpartnerNL/Laravel-Excel/blob/3.1/.github/ISSUE_TEMPLATE/1_Bug_report.md).
42 |
43 | ## Requirements
44 |
45 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)**. - Style will get automatically fixed by StyleCI.
46 | - **Add tests backing up your change!** - You can run the test by running `vendor/bin/phpunit`
47 | - **Document any change in behaviour** - Documentation is located in the [https://github.com/SpartnerNL/laravel-excel-docs](https://github.com/SpartnerNL/laravel-excel-docs)
48 | - **One feature per Pull Request**
49 | - **Add meaningful commit messages**
50 |
--------------------------------------------------------------------------------
/nova/1.x/getting-started/installation.md:
--------------------------------------------------------------------------------
1 | # Installation
2 |
3 | ## Requirements
4 |
5 | * PHP: `^7.1`
6 | * Laravel: `^5.5`
7 | * Laravel Nova:`Orion`
8 | * Maatwebsite Laravel Excel: `^3.0`
9 |
10 | ## Installation
11 |
12 | Before installing the package, make sure you have set-up Laravel Nova.
13 |
14 | Require this package (`maatwebsite/laravel-nova-excel`) in the `composer.json` of your Laravel project or run the following command in your console:
15 |
16 | ```
17 | composer require psr/simple-cache:^2.0 maatwebsite/laravel-nova-excel
18 | ```
19 |
20 | If composer require fails on Laravel 9 because of the simple-cache dependency, you will have to specify the psr/simple-cache version as ^2.0 in your composer.json to satisfy the PhpSpreadsheet dependency. You can install both at the same time as.
21 |
22 | ## Service Provider
23 |
24 | In case you don't have auto-discovery enabled, you'll have to add the following two service providers in `config/app.php`:
25 |
26 | ```
27 | 'providers' => [
28 | /*
29 | * Package Service Providers...
30 | */
31 | Maatwebsite\Excel\ExcelServiceProvider::class,
32 | Maatwebsite\LaravelNovaExcel\LaravelNovaExcelServiceProvider::class,
33 | ]
34 | ```
35 |
--------------------------------------------------------------------------------
/nova/1.x/getting-started/license.md:
--------------------------------------------------------------------------------
1 | # License
2 |
3 | [[toc]]
4 |
5 | ## MIT
6 | Our software is open source and licensed under the [MIT license](https://choosealicense.com/licenses/mit/). You are free to use the software as you like. The code can be forked and modified, but the original copyright author should always be included!
7 |
8 | ## Postcardware
9 | According to the [postcardware](https://en.wikipedia.org/wiki/Postcardware) concept, if you use the software for your project(s) we would appreciate to receive a postcard of your hometown. Please send it to:
10 |
11 | **Maatwebsite**
12 | Markt 2
13 | 6231 LS Meerssen
14 | The Netherlands
15 |
16 | ## Support
17 |
18 | ::: warning Support
19 | We hold no liability and will provide support on a best effort basis. For more information about support please see [support](/nova/1.1/getting-started/support.html).
20 | :::
21 |
22 | :::tip Commercial Support
23 | :rocket: If you use the software commercially and need support urgently, we can offer this on a commercial basis. Please contact or phone +31 (0)10 744 9312.
24 | :::
25 |
--------------------------------------------------------------------------------
/nova/1.x/getting-started/support.md:
--------------------------------------------------------------------------------
1 | # Support
2 |
3 | [[toc]]
4 |
5 | Our software is free and open source, meaning that the use of our software is optional. We hold no liability and there is no obligation to support. We will provide support on a best effort basis.
6 |
7 | :::tip Commercial Support
8 | If you use the software commercially and need elaborate support or need it urgently, we can offer this on a commercial basis. Please contact or via phone +31 (0)10 744 9312.
9 | :::
10 |
11 | ## Supported Versions
12 |
13 | Versions will be supported for a limited amount of time.
14 |
15 | | Version | Laravel Version | Php Version | Support |
16 | |---- |----|----|----|
17 | | 1.0 | ^5.5 | ^7.0 | Unsupported since DD-MM-YYYY |
18 | | 1.1 | ^5.5 | ^7.0 | New features |
19 |
20 | ::: warning PHP version support
21 | Support for PHP versions will only be maintained for a period of six months beyond the end-of-life of that PHP version.
22 | :::
23 |
24 | ## Requesting support
25 | Before you request support, please check the following:
26 | * Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
27 | * Check to make sure your support request isn't already present within the project.
28 | * Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
29 | * Use one of the [issue templates](https://github.com/SpartnerNL/Laravel-Excel/tree/3.1/.github/ISSUE_TEMPLATE).
30 |
31 | Filling out the template is required. Issues that do not include enough information might not be picked up. Please write in English (or Dutch).
32 |
33 | Please prefix your issue with one of the following: [BUG] [PROPOSAL] [QUESTION].
34 |
35 | And please be considerate towards maintainers when raising issues.
36 |
--------------------------------------------------------------------------------
/nova/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "scripts": {
3 | "docs:build": "vuepress build",
4 | "docs:dev": "vuepress dev"
5 | },
6 | "devDependencies": {
7 | "@vuepress/plugin-back-to-top": "^1.8.2",
8 | "@vuepress/plugin-google-analytics": "^1.8.2",
9 | "@vuepress/plugin-nprogress": "^1.8.2",
10 | "@vuepress/plugin-pwa": "^1.8.2",
11 | "vuepress": "^1.8.2",
12 | "vuepress-plugin-container": "^2.1.5",
13 | "vuepress-plugin-sitemap": "^2.3.1"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
|