يضيف Fast Excel 5.x عمليات استيراد متدفقة وصادرات أكثر أمانًا - وهو إجراء عملي...
استكشف الأفكار الرئيسية والتفاصيل العملية والإرشادات المفيدة حول Fast Excel الذي تغير بشكل كبير منذ أن غطت Laravel News الحزمة في عام 2020. ث.

لقد تغير Fast Excel بشكل كبير منذ أن غطت Laravel News الحزمة في عام 2020. وقد غطت هذه المقالة عمليات تصدير المجموعة في عصر الإصدار 2.2، وتنزيلات المتصفح، والمصنفات متعددة الأوراق. يتضمن Fast Excel 5 الآن عمليات استيراد كسولة، وعناصر تحكم لتقسيم عمل جداول البيانات عبر المهام، واختيار الأوراق والأعمدة، ومعالجة أكثر أمانًا لقيم التصدير التي يتحكم فيها المستخدم.
تجعل الإصدارات الأخيرة Fast Excel أكثر فائدة لعمليات الاستيراد التشغيلية الكبيرة، وليس فقط تنزيلات التقارير البسيطة. لا تزال الحزمة تستخدم OpenSpout بدلاً من محاولة الكشف عن كل ميزة في تنسيق ملف Excel، مما يبقيها مركزة على قراءة وكتابة الصفوف ذات الاستخدام المنخفض للذاكرة.
importLazy()يقرأ الصفوف من خلال أLazyCollectionheaderRow(),startRow()، وlimitRows()دعم الواردات مقسمةsheet()وonlyColumns()حدد البيانات التي يحتاجها الاستيرادescapeFormulas()يكتب قيمًا تشبه الصيغة التي يتحكم فيها المستخدم كنص
الواردات كسول للملفات الكبيرة
import() تقوم بإرجاع مجموعة تحتوي على كل صف مستورد. بالنسبة للتحميل الكبير، يمكن أن يستخدم هذا مساحة أكبر من الذاكرة المتوفرة في عملية PHP. importLazy() ينتج صفوفًا من خلال a LazyCollection، بحيث يمكن للتطبيق تجميع عمل قاعدة البيانات دون الاحتفاظ بالملف الكامل:
useApp\Models\Contact;useIlluminate\Support\LazyCollection;useRap2hpoutre\FastExcel\FastExcel;
(newFastExcel)->importLazy('contacts.xlsx')->chunk(1_000)->each(function (LazyCollection $contacts) {Contact::insert($contacts->all()); });
تقديم برنامج Fast Excel 5.12 importLazy() جنبًا إلى جنب مع تدفق تغييرات التصدير. يقارن المعيار المعياري الخاص بالحزمة بين تصدير المولدات ومجموعة متحققة، ويتضمن المستودع البرنامج النصي القياسي. بالنسبة للاستيراد الذي يصل كملف CSV، يمكن أن يحل نفس الأسلوب محل بعض التحليل اليدوي المستخدم لتحميل ملف CSV كبير.
واردات مقسمة بعناوين مستقرة
تساعد ضوابط الاستيراد الأحدث عندما يتعين على مهمة واحدة في قائمة الانتظار معالجة جزء من جدول البيانات. headerRow() يقرأ المفاتيح من صف العنوان الفعلي، بينما startRow() يختار حيث يبدأ الجزء الحالي و limitRows() قبعات حجمها:
useRap2hpoutre\FastExcel\FastExcel;
$rows = (newFastExcel)->headerRow(1)->startRow(2+ ($page *1_000))->limitRows(1_000)->import('orders.xlsx');
قبل فاست إكسل 5.17، startRow() تعامل أيضًا مع الصف المحدد كعناوين. وبالتالي، يمكن للقطعة اللاحقة استخدام صف البيانات كمفاتيح لها. headerRow() يفصل بين تلك المواقف ويترك القديم startRow() لم يتغير السلوك إلا إذا قمت بالاشتراك. #418 أضافت الطريقة.
اختيار الأوراق والأعمدة
يمكن للحزمة تحديد ورقة بالاسم والاحتفاظ فقط بالأعمدة التي يحتاجها الاستيراد:
useRap2hpoutre\FastExcel\FastExcel;
$orders = (newFastExcel)->sheet('Orders')->onlyColumns(['A', 'B', 'H'])->import('customer-export.xlsx');
onlyColumns() يقبل أحرف الأعمدة أو المواضع القائمة على أساس واحد. فهو يتجنب إرجاع الحقول الفارغة من الأوراق التي تم تطبيق التنسيق فيها بما يتجاوز البيانات الحقيقية. limitColumns() يتوفر عندما يحتاج الاستيراد إلى كل عمود حتى موضع معين بدلاً من ذلك. وصلت هذه الخيارات إلى Fast Excel 5.16، الذي أضاف أيضًا خيار تمرير مثيل خلية OpenSpout كقيمة تصدير. #419
الهروب من صيغ جداول البيانات
يمكن لتطبيقات جداول البيانات التعامل مع القيم بدءًا من =, +, -، أو @ كصيغ. عندما تأتي هذه القيم من ملف CSV تم تحميله أو من حقل قاعدة بيانات يتحكم فيه المستخدمون، يمكن أن يؤدي تصدير التقرير إلى تحويل نص عادي إلى صيغة عندما يفتحه شخص ما.
يتصل escapeFormulas() قبل التصدير لكتابة هذه القيم كنص:
useRap2hpoutre\FastExcel\FastExcel;
(newFastExcel($rows))->escapeFormulas()->export('orders.xlsx');
أضاف Fast Excel 5.17 الطريقة #411.
التوافق
يتطلب Fast Excel 5 PHP 8.0 أو أحدث وLaravel 6 أو أحدث. يدعم الإصدار الحالي Laravel 6 إلى 13 ويستخدم OpenSpout 4. تحتاج التطبيقات التي لا تزال على خط الأساس Laravel 5 أو PHP 7 المدعوم بـ Fast Excel 2 إلى تخطيط ترقية التبعية بشكل منفصل.
يتضمن سجل الإصدار الرئيسي الانتقال من box/spout ل openspout/openspoutبالإضافة إلى متطلبات PHP 8 في Fast Excel 5. يجب على المشاريع التي تستخدم إصدار Fast Excel سابق التحقق من تغييرات التبعية هذه قبل التحديث.
تثبيت
تثبيت Fast Excel باستخدام Composer:
composerrequirerap2hpoutre/fast-excel
مراجع
- ملاحظات إصدار Fast Excel 5.12
- ملاحظات إصدار Fast Excel 5.16
- ملاحظات إصدار Fast Excel 5.17
- شيفرة Fast Excel المصدرية والتوثيق
Fast Excel has changed substantially since Laravel News covered the package in 2020. That article covered v2.2-era collection exports, browser downloads, and multi-sheet workbooks. Fast Excel 5 now includes lazy imports, controls for splitting spreadsheet work across jobs, sheet and column selection, and safer handling of user-controlled export values.
The recent releases make Fast Excel more useful for large operational imports, not only simple report downloads. The package still uses OpenSpout rather than trying to expose every feature in the Excel file format, which keeps it focused on reading and writing rows with low memory use.
importLazy()reads rows through aLazyCollectionheaderRow(),startRow(), andlimitRows()support chunked importssheet()andonlyColumns()select the data an import needsescapeFormulas()writes user-controlled formula-like values as text
Lazy imports for large files
import() returns a collection containing every imported row. For a large upload, that can use more memory than the PHP process has available. importLazy() yields rows through a LazyCollection, so an application can batch the database work without retaining the full file:
use App\Models\Contact;use Illuminate\Support\LazyCollection;use Rap2hpoutre\FastExcel\FastExcel; (new FastExcel)->importLazy('contacts.xlsx') ->chunk(1_000) ->each(function (LazyCollection $contacts) { Contact::insert($contacts->all()); });
Fast Excel 5.12 introduced importLazy() alongside streaming export changes. The package's own benchmark compares a generator export with a materialised collection, and the repository includes the benchmark script. For an import that arrives as CSV, the same approach can replace some of the manual parsing used for a large CSV upload.
Chunked imports with stable headings
The newer import controls help when one queued job should process a portion of a spreadsheet. headerRow() reads keys from the actual heading row, while startRow() selects where the current chunk begins and limitRows() caps its size:
use Rap2hpoutre\FastExcel\FastExcel; $rows = (new FastExcel) ->headerRow(1) ->startRow(2 + ($page * 1_000)) ->limitRows(1_000) ->import('orders.xlsx');
Before Fast Excel 5.17, startRow() also treated the selected row as the headings. A later chunk could therefore use a data row as its keys. headerRow() separates those positions and leaves the old startRow() behaviour unchanged unless you opt in. #418 added the method.
Selecting sheets and columns
The package can select a sheet by name and keep only the columns an import needs:
use Rap2hpoutre\FastExcel\FastExcel; $orders = (new FastExcel) ->sheet('Orders') ->onlyColumns(['A', 'B', 'H']) ->import('customer-export.xlsx');
onlyColumns() accepts column letters or one-based positions. It avoids returning empty fields from sheets where formatting was applied far beyond the real data. limitColumns() is available when an import needs every column up to a given position instead. These options arrived in Fast Excel 5.16, which also added the option to pass an OpenSpout cell instance as an export value. #419
Escaping spreadsheet formulas
Spreadsheet applications can treat values starting with =, +, -, or @ as formulas. When those values come from an uploaded CSV or a database field controlled by users, a report export can turn plain text into a formula when somebody opens it.
Call escapeFormulas() before exporting to write those values as text:
use Rap2hpoutre\FastExcel\FastExcel; (new FastExcel($rows)) ->escapeFormulas() ->export('orders.xlsx');
Fast Excel 5.17 added the method in #411.
Compatibility
Fast Excel 5 requires PHP 8.0 or later and Laravel 6 or later. The current release supports Laravel 6 through 13 and uses OpenSpout 4. Applications still on the Laravel 5 or PHP 7 baseline supported by Fast Excel 2 need to plan the dependency upgrade separately.
The major-version history includes a move from box/spout to openspout/openspout, plus a PHP 8 requirement in Fast Excel 5. Projects that use an earlier Fast Excel release should check those dependency changes before updating.
Installation
Install Fast Excel with Composer:
composer require rap2hpoutre/fast-excel
References
- Fast Excel 5.12 release notes
- Fast Excel 5.16 release notes
- ملاحظات إصدار Fast Excel 5.17
- شيفرة Fast Excel المصدرية والتوثيق
عبدالرحمن ربيع
Software Engineer & AI Builder
مطور برمجيات متكامل ومصمم جرافيك مع أكثر من 4 سنوات خبرة في بناء تطبيقات الويب الحديثة باستخدام PHP و JavaScript و HTML و CSS. خلفية قوية في تصميم UI/UX واستخدام متقدم لأدوات الذكاء الاصطناعي لتعزيز كفاءة التطوير والأتمتة واتخاذ القرارات. حاصل على ماجستير تنفي...
وسوم المقال
مصادر وروابط خارجية
مقالات ذات صلة
Gemini 3.8 Flash TTS وFlash-Lite TTS يوفران التحكم الصوتي الفوري
اقرأ المقال
دليل مبسط: بحث في امن المعلومات و التهديدات الأمنية والهجمات الالكت...
اقرأ المقال
دليل خطوة بخطوة: تثبيت Laravel 11 باستخدام Composer
اقرأ المقال
Abdelrhman Rabea

التعليقات (0)
كن أول من يعلّق على هذا المقال.