定制 kahil-raghed/laravel-excel-extended 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kahil-raghed/laravel-excel-extended

最新稳定版本:v1.1.1

Composer 安装命令:

composer require kahil-raghed/laravel-excel-extended

包简介

laravel excel additional usefull futures

README 文档

README

Added additional futures to maatwebsite/excel package

installation

composer require kahil-raghed/laravel-excel-extended

The LaravelExcelExtended\Providers\FuturesProvider is auto-discovered and registered by default.

If you want to register it yourself, add the ServiceProvider in config/app.php:

'providers' => [
    /*
     * Package Service Providers...
     */
    LaravelExcelExtended\Providers\FuturesProvider::class,
]

Futures

Max width for auto size columns:

You can set maximum width to prevent columns from scalling too much.

Set for all columns:

namespace App\Exports;

use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use LaravelExcelExtended\Concerns\WithMaxidth;


class ProductsExport implements ShouldAutoSize, WithMaxWidth {
    public function maxWidth(){
        return 50;
    }
}

Or set for spacific columns:

namespace App\Exports;

use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use LaravelExcelExtended\Concerns\WithMaxidth;


class ProductsExport implements ShouldAutoSize, WithMaxWidth {
    public function maxWidth(){
        return [
            'A' => 50,
            'H' => 100
        ];
    }
}

Dropdown lists

You can create interactive drop down lists using WithDropdown concern.

namespace App\Exports;

use LaravelExcelExtended\Concerns\WithDropdown;


class ProductsExport implements WithDropdown {
    public function dropdown(){
        return [
            'B2:B100' => [ // product size
                'values' => [
                    'XS',
                    'S',
                    'M',
                    'L'
                ]
            ],
        ];
    }
}

But this approach has limitations refer phpspreadsheet data validation

It is important to remember that any string participating in an Excel formula is allowed to be maximum 255 characters (not bytes). This sets a limit on how many items you can have in the string "Item A,Item B,Item C". Therefore it is normally a better idea to type the item values directly in some cell range, say A1:A3, and instead use, say, $validation->setFormula1('\'Sheet title\'!$A$1:$A$3'). Another benefit is that the item values themselves can contain the comma , character itself.

For long lists or list containing values with commas it is better to set stratergy to Excel::LIST_STRATEGY_HIDDEN_COLUMN.

it stores allowed values in a hidden column after the data.

namespace App\Exports;

use Models\Category;
use LaravelExcelExtended\Concerns\WithDropdown;
use LaravelExcelExtended\Helpers\Excel;


class ProductsExport implements WithDropdown {
    public function dropdown(){
        $categories = Category::all(['id', 'name']);
        return [
            'B2:B100' => [
                'values' => $category->map(fn ($c) => $c->name),
                'strategy' => Excel::LIST_STRATEGY_HIDDEN_COLUMN
            ],
        ];
    }
}

统计信息

  • 总下载量: 28
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固