Hướng dẫn laravel excel drawing - bản vẽ excel của laravel

Bằng cách sử dụng mối quan tâm WithDrawings, bạn có thể thêm một hoặc nhiều bản vẽ vào bảng tính của mình.

# Khởi tạo một bản vẽ

Trước tiên, bạn phải khởi tạo một \PhpOffice\PhpSpreadsheet\Worksheet\Drawing mới và gán các thuộc tính của nó một giá trị có ý nghĩa.

$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setName('Logo');
$drawing->setDescription('This is my logo');
$drawing->setPath(public_path('/img/logo.jpg'));
$drawing->setHeight(90);

12345
2
3
4
5

Bạn có thể xem tất cả các thuộc tính có sẵn để vẽ trên các tài liệu PHPSPREADSHEET (mở cửa sổ mới). (opens new window).

# Thêm một bản vẽ duy nhất

Khi bạn đã khởi tạo bản vẽ, bạn có thể thêm mối quan tâm WithDrawings vào lớp xuất khẩu của mình.Trả về thể hiện bản vẽ trong phương thức drawings.



namespace App\Exports;

use Maatwebsite\Excel\Concerns\WithDrawings;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;

class InvoicesExport implements WithDrawings
{
    public function drawings()
    {
        $drawing = new Drawing();
        $drawing->setName('Logo');
        $drawing->setDescription('This is my logo');
        $drawing->setPath(public_path('/img/logo.jpg'));
        $drawing->setHeight(90);
        $drawing->setCoordinates('B3');

        return $drawing;
    }
}

123456789101112131415161718192021
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# Thêm nhiều bản vẽ

Bạn có thể thêm nhiều bản vẽ vào bảng tính bằng cách trả về một mảng trong phương thức drawings.



namespace App\Exports;

use Maatwebsite\Excel\Concerns\WithDrawings;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;

class InvoicesExport implements WithDrawings
{
    public function drawings()
    {
        $drawing = new Drawing();
        $drawing->setName('Logo');
        $drawing->setDescription('This is my logo');
        $drawing->setPath(public_path('/img/logo.jpg'));
        $drawing->setHeight(50);
        $drawing->setCoordinates('B3');

        $drawing2 = new Drawing();
        $drawing2->setName('Other image');
        $drawing2->setDescription('This is a second image');
        $drawing2->setPath(public_path('/img/other.jpg'));
        $drawing2->setHeight(120);
        $drawing2->setCoordinates('G2');

        return [$drawing, $drawing2];
    }
}

12345678910111213141516171819202122232425262728
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28