Bạn có thể sử dụng FastExcel với Facade tùy chọn. Thêm dòng sau vào
$list = collect[[ [ 'id' => 1, 'name' => 'Jane' ], [ 'id' => 2, 'name' => 'John' ], ]]; [new FastExcel[$list]]->export['file.xlsx'];5 bên dưới khóa
$list = collect[[ [ 'id' => 1, 'name' => 'Jane' ], [ 'id' => 2, 'name' => 'John' ], ]]; [new FastExcel[$list]]->export['file.xlsx'];6
'FastExcel' => Rap2hpoutre\FastExcel\Facades\FastExcel::class,
Sử dụng Mặt tiền, bạn sẽ không có quyền truy cập vào hàm tạo. Bạn có thể đặt dữ liệu xuất của mình bằng phương thức
$list = collect[[ [ 'id' => 1, 'name' => 'Jane' ], [ 'id' => 2, 'name' => 'John' ], ]]; [new FastExcel[$list]]->export['file.xlsx'];7
use Rap2hpoutre\FastExcel\FastExcel; use App\User; // Load users $users = User::all[]; // Export all users [new FastExcel[$users]]->export['file.xlsx'];0
người trợ giúp toàn cầu
FastExcel cung cấp một trình trợ giúp toàn cầu thuận tiện để nhanh chóng khởi tạo lớp FastExcel ở bất kỳ đâu trong ứng dụng Laravel
use Rap2hpoutre\FastExcel\FastExcel; use App\User; // Load users $users = User::all[]; // Export all users [new FastExcel[$users]]->export['file.xlsx'];1
Sử dụng nâng cao
Xuất nhiều trang tính
Xuất nhiều trang tính bằng cách tạo một
$list = collect[[ [ 'id' => 1, 'name' => 'Jane' ], [ 'id' => 2, 'name' => 'John' ], ]]; [new FastExcel[$list]]->export['file.xlsx'];8
use Rap2hpoutre\FastExcel\FastExcel; use App\User; // Load users $users = User::all[]; // Export all users [new FastExcel[$users]]->export['file.xlsx'];2
Sử dụng chỉ mục để chỉ định tên trang tính
use Rap2hpoutre\FastExcel\FastExcel; use App\User; // Load users $users = User::all[]; // Export all users [new FastExcel[$users]]->export['file.xlsx'];3
Nhập nhiều trang tính
Nhập nhiều trang tính bằng cách sử dụng
$list = collect[[ [ 'id' => 1, 'name' => 'Jane' ], [ 'id' => 2, 'name' => 'John' ], ]]; [new FastExcel[$list]]->export['file.xlsx'];9
use Rap2hpoutre\FastExcel\FastExcel; use App\User; // Load users $users = User::all[]; // Export all users [new FastExcel[$users]]->export['file.xlsx'];4
Bạn cũng có thể nhập một trang tính cụ thể theo số của nó
use Rap2hpoutre\FastExcel\FastExcel; use App\User; // Load users $users = User::all[]; // Export all users [new FastExcel[$users]]->export['file.xlsx'];5
Nhập nhiều trang tính có tên trang tính
use Rap2hpoutre\FastExcel\FastExcel; use App\User; // Load users $users = User::all[]; // Export all users [new FastExcel[$users]]->export['file.xlsx'];6
Xuất các bộ sưu tập lớn với chunk
Xuất từng hàng một để tránh các vấn đề về
$invoices = App\Invoice::orderBy['created_at', 'DESC']->get[]; [new FastExcel[$invoices]]->export['invoices.csv'];0 bằng cách sử dụng
$invoices = App\Invoice::orderBy['created_at', 'DESC']->get[]; [new FastExcel[$invoices]]->export['invoices.csv'];1
use Rap2hpoutre\FastExcel\FastExcel; use App\User; // Load users $users = User::all[]; // Export all users [new FastExcel[$users]]->export['file.xlsx'];7
Thêm tiêu đề và kiểu hàng
Thêm kiểu tiêu đề và hàng với các phương thức
$invoices = App\Invoice::orderBy['created_at', 'DESC']->get[]; [new FastExcel[$invoices]]->export['invoices.csv'];2 và
$invoices = App\Invoice::orderBy['created_at', 'DESC']->get[]; [new FastExcel[$invoices]]->export['invoices.csv'];3
use Rap2hpoutre\FastExcel\FastExcel; use App\User; // Load users $users = User::all[]; // Export all users [new FastExcel[$users]]->export['file.xlsx'];8
Tại sao?
FastExcel được dự định là Spout có hương vị của Laravel. một trình bao bọc đơn giản nhưng trang nhã xung quanh Spout với mục tiêu đơn giản hóa việc nhập và xuất. Nó có thể được coi là một giải pháp thay thế nhanh hơn [và thân thiện với bộ nhớ] cho Laravel Excel, với ít tính năng hơn. Chỉ sử dụng nó cho các tác vụ đơn giản
điểm chuẩn
Đã thử nghiệm trên MacBook Pro 2015 2,7 GHz Intel Core i5 16 Go 1867 MHz DDR3. Thử nghiệm xuất XLSX cho 10000 dòng, 20 cột với dữ liệu ngẫu nhiên, 10 lần lặp, 2018-04-05. Đừng tin vào điểm chuẩn