Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpspreadsheet Laravel Package

phpoffice/phpspreadsheet

PhpSpreadsheet is a pure PHP library to read and write spreadsheet formats like Excel and LibreOffice Calc. Create, edit, and export workbooks (XLSX, XLS, ODS, CSV, etc.) with a rich API for cells, formulas, styles, and more.

View on GitHub
Deep Wiki
Context7

Creating a spreadsheet

The Spreadsheet class

The Spreadsheet class is the core of PhpSpreadsheet. It contains references to the contained worksheets, document security settings and document meta data.

To simplify the PhpSpreadsheet concept: the Spreadsheet class represents your workbook.

Typically, you will create a workbook in one of two ways, either by loading it from a spreadsheet file, or creating it manually. A third option, though less commonly used, is cloning an existing workbook that has been created using one of the previous two methods.

Loading a Workbook from a file

Details of the different spreadsheet formats supported, and the options available to read them into a Spreadsheet object are described fully in the Reading Files document.

$inputFileName = './sampleData/example1.xls';

/** Load $inputFileName to a Spreadsheet object **/
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);

Creating a new workbook

If you want to create a new workbook, rather than load one from file, then you simply need to instantiate it as a new Spreadsheet object.

/** Create a new Spreadsheet Object **/
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

A new workbook will always be created with a single worksheet.

Clearing a Workbook from memory

The PhpSpreadsheet object contains cyclic references (e.g. the workbook is linked to the worksheets, and the worksheets are linked to their parent workbook) which cause problems when PHP tries to clear the objects from memory when they are unset(), or at the end of a function when they are in local scope. The result of this is "memory leaks", which can easily use a large amount of PHP's limited memory.

This can only be resolved manually: if you need to unset a workbook, then you also need to "break" these cyclic references before doing so. PhpSpreadsheet provides the disconnectWorksheets() method for this purpose.

$spreadsheet->disconnectWorksheets();
unset($spreadsheet);
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai