Skip to content

This project is very simple demo to show you how to use the laravel excel package quickly.

Notifications You must be signed in to change notification settings

zhengjinghua/est-excel-demo

Repository files navigation

For Chinese

Description

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

This project is a very simple demo to show you how to use the laravel excel package quickly.

This project was created by The EST Group and PHPHub.

Screenshots

Run the demo

You can refer to this documentation to know how to run this demo.

Table of contents

  1. Installation
  2. Basic Usage
  3. More Usage

Installation

Require this package in your composer.json and update composer. This will download the package and PHPExcel of PHPOffice.

"maatwebsite/excel": "~2.1.0"

After updating composer, add the ServiceProvider to the providers array in config/app.php

'providers' => [
    ...
    Maatwebsite\Excel\ExcelServiceProvider::class,
],

You can use the facade for shorter code. Add this to your aliases:

'aliases' => [
    ...
    'Excel' => Maatwebsite\Excel\Facades\Excel::class,
]

To publish the config settings in Laravel 5 use:

php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider"

This will add an excel.php config file to your config folder.

Basic Usage

Decode Excel file

# $excel_file_path = Your excel file path
$excel_data = Excel::load($excel_file_path, function($reader) {
    $excel_data = Excel::load($excel_file_path)->get()->toArray();

    echo 'job.xlsx contents is:';
    dd($excel_data);
});

Simple Excel Export

// Export Excel
Excel::create($export_file_name, function ($excel) {
    $excel->sheet('Sheetname', function ($sheet) {
        $sheet->appendRow(['data 1', 'data 2']);
        $sheet->appendRow(['data 3', 'data 4']);
        $sheet->appendRow(['data 5', 'data 6']);
    });
})->download('xls');

// Export Excel and save it to a specified folder
Excel::create($export_file_name, function ($excel) {
    $excel->sheet('Sheetname', function ($sheet) {
        $sheet->appendRow(['data 1', 'data 2']);
        $sheet->appendRow(['data 3', 'data 4']);
        $sheet->appendRow(['data 5', 'data 6']);
    });
})->store('xls', $object_path);

Then you can get something like this.

More Usage

  1. Selecting sheets and columns;
  2. Format Dates;
  3. Calculate formulas;
  4. Caching and Cell caching;
  5. Chunk importer;
  6. Converting;
  7. @Blade to Excel

You can refer to the documentation to learn more about this package.


欢迎关注 LaravelTips, 一个专注于为 Laravel 开发者服务, 致力于帮助开发者更好的掌握 Laravel 框架, 提升开发效率的微信公众号.

About

This project is very simple demo to show you how to use the laravel excel package quickly.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages