标签: laravel-excel

Laravel excel 将复杂的标题添加到导出中

我需要通过Laravel Excel导出具有复杂标题的工作表。我需要一个主标题和另一个子标题。

在此输入图像描述

我正在这样尝试,

use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;

class InvoicesExport implements FromQuery, WithHeadings
{   
    public function headings(): array
    {
        return [
            'Account 1' =>[
                "Account 1 id",
                "Account 1 branch"  
            ],
            'Account 2' =>[
                "Account 2 id",
                "Account 2 branch"  
            ],
        ];
    }
}
Run Code Online (Sandbox Code Playgroud)

但获取标题列,如 [“帐户 1 id”、“帐户 1 分支”]

有没有办法存档这个任务?

laravel-5 laravel-excel maatwebsite-excel

6
推荐指数
1
解决办法
6862
查看次数

如何在 laravel excel maatwebsite 中设置带分隔符的动态数字格式?

我有一个金额列,当数字没有小数时我想设置整数格式,当数字有小数时设置双精度格式。在这两种方式中,我想为数字添加分隔符。目前,我使用bindValue,但Excel单元格不知道金额列是数字格式,我应该选择它们并将它们转换为数字。

public function bindValue(Cell $cell, $value)
{
    if (is_int($value)) {
        $cell->setValueExplicit($value, '#,##0');

        return true;
    }else if (is_double($value)) {
        $cell->setValueExplicit($value, '#,##0.00');

        return true;
    }else{
        $cell->setValueExplicit($value,  DataType::TYPE_STRING);

        return true;

    }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我该如何修复它?

excel number-formatting laravel laravel-excel maatwebsite-excel

6
推荐指数
1
解决办法
1849
查看次数

laravel-excel无法使用带有图像的刀片导出xls文件

对不起,我想用laravel-excel导出我的报告.这是控制器:

public function getExcelfile(){
        $users = UserService::findAllPublic();
        $total = UserService::count();
        $total_with_photo = UserService::countWithPhoto();
        Excel::create('excelfile', function($excel) use ($users, $total, $total_with_photo) {
            $excel->sheet('Excel', function($sheet) use ($users, $total, $total_with_photo) {
                $sheet->loadView('report.excel')->with("users", $users)->with("total", $total)->with("total_with_photo", $total_with_photo);
            });
        })->export('xls');
    }
Run Code Online (Sandbox Code Playgroud)

这是位于报告文件夹的excel.blade.php:

<html> <body> Total Registered User : {{$total}} Total Registered User With Photo : {{$total_with_photo}} <h1>Data User</h1> @if(!empty($users)) <table class="table table-striped table-bordered">
    <thead>
    <tr>
        <th>ID</th>
        <th>Photo</th>
        <th>Nama</th>
        <th>Struck</th>
        <th>Email</th>
        <th>Phone</th>
        <th>FB ID</th>
        <th>Timestamp</th>
        <th>Publish</th>
    </tr>
    </thead>
    @foreach ($users as $row)
    <tr>
        <td>{{$row->id}}</td>
        <td><img src="{{URL::asset('assets/images/upload/' . $row->photo)}}" …
Run Code Online (Sandbox Code Playgroud)

html php excel laravel laravel-excel

5
推荐指数
1
解决办法
5485
查看次数

Laravel 5 Excel安装失败

我正在尝试将Laravel Excel(http://www.maatwebsite.nl/laravel-excel/docs)软件包安装到我的Laravel 5上.这是我到目前为止所做的:

  • 添加"maatwebsite/excel": "2.*"到我的要求,composer update 完成就好了,我有所有的包文件
  • 添加'Maatwebsite\Excel\ExcelServiceProvider',到提供者数组
  • 添加'Excel' => 'Maatwebsite\Excel\Facades\Excel',到别名数组

这是问题 - 当我尝试跑步时php artisan vendor:publish,它会告诉我Nothing to publish for tag [].

当我使用php artisan tinker并运行时$excel = App::make('excel'),它会告诉我ReflectionException with message 'Class excel does not exist'.

我究竟做错了什么?

php laravel laravel-5 laravel-excel

5
推荐指数
1
解决办法
2321
查看次数

使用Laravel-Excel插入图像

我正在使用这个包用Laravel生成excel文档:https: //github.com/Maatwebsite/Laravel-Excel

但是,文档没有说明如何将文件中的图像插入到我的Excel文档中.我非常确定本地phpexcel本身是可能的,但如何通过这个包来做到这一点?

一些示例代码将非常感激..

phpexcel laravel laravel-5 laravel-excel

5
推荐指数
1
解决办法
8646
查看次数

Laravel-Excel(MaatWebSite)需要长时间阅读

我不知道我做错了什么,或者它可能是正常的.我必须加载并"读取"大约12000行的excell.我使用这个代码.

Excel::selectSheetsByIndex(0)->load($path.$fileName, function ($reader) {
    $reader->each(function($row){
        Log::info('$row');
    });
});
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,没有什么可以使阅读变得如此缓慢.我需要在读取后处理数据,如果只读取超过5-10分钟就会出现问题.

我也尝试使用块过滤器,但没有什么比这更好了.

这是正常的吗?

我知道excel阅读速度很慢,正如我在其他问题中读到的那样,但"这个"很慢?谢谢.

php excel laravel-excel

5
推荐指数
1
解决办法
1053
查看次数

如何在 laravel 中读取 xls 文件 - laravel-excel

我正在使用laravel-excel库来读取 Excel 文件。

http://www.maatwebsite.nl/laravel-excel/docs/import

   //http://localhost:8000/assets/panel/excel/test123.xls
    $address = URL::to('/assets/panel/excel/').'/test123.xls';
   // dd($address);
    Excel::load($address, function($reader) {

        $results = $reader->get();
        dd($results);

    });
Run Code Online (Sandbox Code Playgroud)

该文件http://localhost:8000/assets/panel/excel/test123.xls存在,但我收到此错误:

Could not open C:\xampp\htdocs\tahrircenter\http://localhost:8000/assets/panel/excel/test123.xls for reading! File does not exist.
Run Code Online (Sandbox Code Playgroud)

我知道错误的含义,但是如何使用我的地址而不是该库中的目录地址?

php excel laravel laravel-5 laravel-excel

5
推荐指数
1
解决办法
2万
查看次数

如何更改 Laravel Excel Maat 网站角色的颜色?

我从这里获取教程:https ://laravel-excel.maatwebsite.nl/3.0/exports/extending.html

所以我使用版本3

我的Excel是这样的:

在此输入图像描述

我想把它改成这样:

在此输入图像描述

所以我想将字符England更改为红色并加粗

我尝试这样:

namespace App\Exports;
...
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\BeforeExport;
use Maatwebsite\Excel\Events\AfterSheet;

class SummaryExport implements FromView, WithEvents
{
    ...
    public function registerEvents(): array
    {
        return [
            AfterSheet::class    => function(AfterSheet $event) {
                $event->sheet->styleCells(
                    'B1:D1',
                    [
                        'borders' => [
                            'outline' => [
                                'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
                                'color' => ['argb' => 'EB2B02'],
                            ],
                        ]
                    ]
                );
            },
        ];
    }
}
Run Code Online (Sandbox Code Playgroud)

存在这样的错误:

Method Maatwebsite\Excel\Sheet::styleCells does not exist.
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个错误?

excel laravel laravel-5 laravel-excel laravel-5.6

5
推荐指数
1
解决办法
1万
查看次数

Laravel 7 w/ Laravel Excel:您的需求无法解析为一组可安装的包

我正在尝试在使用PHP 7.4的Docker 容器中运行的Larevel 7中安装Laravel Excel,但出现此错误,但我不知道如何修复。

\n\n
e-learning-app/src on \xee\x82\xa0 dev [$!] via \xe2\xac\xa2 v12.8.1 via  v7.4.4\n\xe2\x9e\x9c docker:composer require maatwebsite/excel\nStarting e-learning-app-php ... done\nUsing version ^3.1 for maatwebsite/excel\n./composer.json has been updated\nLoading composer repositories with package information\nUpdating dependencies (including require-dev)\nYour requirements could not be resolved to an installable set of packages.\n\n  Problem 1\n    - maatwebsite/excel 3.1.x-dev requires phpoffice/phpspreadsheet ^1.11 -> satisfiable by phpoffice/phpspreadsheet[1.11.0, 1.12.0, 1.13.0].\n    - maatwebsite/excel 3.2.x-dev requires phpoffice/phpspreadsheet ^1.11 -> satisfiable by phpoffice/phpspreadsheet[1.11.0, 1.12.0, …
Run Code Online (Sandbox Code Playgroud)

php laravel docker laravel-excel

5
推荐指数
1
解决办法
3082
查看次数

Laravel Excel 可以工作,但文件无法打开

我正在使用Laravel Excel创建包含多个工作表的 Excel 文档。我一直在遵循他们的示例,了解他们是如何做到这一点的,但是当我去下载文件时,它是:

Excel 无法打开文件“kingdoms (1).xlsx”,因为文件格式或文件扩展名无效。验证文件未损坏并且文件扩展名与文件格式匹配。

我不确定为什么。

所以我是这样做的:

控制器方法:

public function export() {
    return Excel::download(new KingdomsExport, 'kingdoms.xlsx', \Maatwebsite\Excel\Excel::XLSX);
}
Run Code Online (Sandbox Code Playgroud)

出口类

class KingdomsExport implements WithMultipleSheets {

    use Exportable;

    /**
     * @return array
     */
    public function sheets(): array {
        $sheets   = [];

        $sheets[] = new BuildingsSheet;

        // .. other commented out sheets.

        return $sheets;
    }
}
Run Code Online (Sandbox Code Playgroud)

建筑物板材

class BuildingsSheet implements FromView, WithTitle, ShouldAutoSize {

    /**
     * @return View
     */
    public function view(): View {
        return view('admin.exports.kingdoms.sheets.buildings', [
            'buildings' => …
Run Code Online (Sandbox Code Playgroud)

excel laravel-excel laravel-8

5
推荐指数
1
解决办法
5870
查看次数