PHP | Spreadsheet Last Updated : 07 Mar, 2024 Comments Improve Suggest changes Like Article Like Report Introduction: PHPSpreadsheet is a library written in PHP which helps to read from and write to different types of spreadsheet file formats with the help of a given set of classes. The various format which support spreadsheet are Excel(.xlsx), Open Document Format(.ods),SpreadsheetML(.xml), CSV and many more. Advantages: Easy and effective comparisons.Powerful analysis of large amounts of data. Usability: AgendasBudgetsCalendarsCardsCharts and DiagramsFinancial Tools (Loan calculators etc.)FlyersFormsInventoriesInvoicesLists and to-do checklistsPlannersPlans and proposalsReportsSchedulesTimesheets Requirements: The following software is developed using PHPSpreadsheet: PHP version 5.6 or newerPHP extension php_zip enabledPHP extension php_xml enabledPHP extension php_gd2 enabled Installation: The PHPSpreadsheet can be installed with the help of Composer. On Terminal: The following command runs on the terminal to install PHPSpreadsheet: composer require phpoffice/phpspreadsheet Example 1: PHP <?php // require_once('vendor/autoload.php'); use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; // Creates New Spreadsheet $spreadsheet = new Spreadsheet(); // Retrieve the current active worksheet $sheet = $spreadsheet->getActiveSheet(); // Set the value of cell A1 $sheet->setCellValue('A1', 'GeeksForGeeks!'); // Sets the value of cell B1 $sheet->setCellValue('B1', 'A Computer Science Portal For Geeks'); // Write an .xlsx file $writer = new Xlsx($spreadsheet); // Save .xlsx file to the current directory $writer->save('gfg.xlsx'); ?> Output: Example 2: PHP <?php // require_once('path/vendor/autoload.php'); // Load an .xlsx file $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('gfg.xlsx'); // Store data from the activeSheet to the variable // in the form of Array $data = array(1,$spreadsheet->getActiveSheet() ->toArray(null,true,true,true)); // Display the sheet content var_dump($data); ?> Output: array(2) { [0]=> int(1) [1]=> array(1) { [1]=> array(2) { ["A"]=> string(14) "GeeksForGeeks!" ["B"]=> string(35) "A Computer Science Portal For Geeks" } } } Comment More infoAdvertise with us Next Article PHP | Spreadsheet S sarthak_ishu11 Follow Improve Article Tags : Technical Scripter GeeksforGeeks Initiatives Web Technologies PHP PHP-function PHP-Spreadsheet +2 More Similar Reads PHP | Spreadsheet_Excel_Writer | Introduction Introduction: Spreadsheet_Excel_Writer is a library written in PHP which helps to read from and write to different types of spreadsheet file formats with the help of given set of classes. Advantages: Easy and effective comparisons. Powerful analysis of large amounts of data. Splitting out large (or 1 min read PHP | Spreadsheet_Excel_Writer | send() Function The send() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to send HTTP headers with the correct content-type (application/vnd.ms-excel), cache control and filename for the file. Syntax: void Spreadsheet_Excel_Writer::send( $filename ) Parameters: This function accept 2 min read PHP | Spreadsheet_Excel_Writer | Close() Function The close() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to finalize the spreadsheet after which all the operations are done. This method should always be the last one to be called on every workbook. Syntax:Â mixed Workbook::close() Parameters: This function does n 2 min read PHP Variables A variable in PHP is a container used to store data such as numbers, strings, arrays, or objects. The value stored in a variable can be changed or updated during the execution of the script.All variable names start with a dollar sign ($).Variables can store different data types, like integers, strin 5 min read PHP | Spreadsheet_Excel_Writer | setBold() Function The setBold() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the boldness of the text. Syntax:Â void Format::setBold( $weight = 1 ) Parameters: This function accepts a single parameter $weight which is used to set the weight of the text. The default value of t 2 min read Like