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 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 PHP | Spreadsheet_Excel_Writer | setAlign() Function The setAlign() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set cell alignment of the spreadsheet. Syntax: void Format::setAlign( $location ) Parameters: This function accepts single parameter $location which takes the position, as Horizontal Alignments (left, c 2 min read PHP | Spreadsheet_Excel_Writer | setColor() Function The setColor() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the color of a cell content. Syntax: void Format::setColor( mixed $color ) Parameters: This function accepts single parameter as $color which takes value of color as string like 'green' or value fro 2 min read PHP | Spreadsheet_Excel_Writer | setHAlign() Function The setHAlign() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set cell alignment of the spreadsheet. Syntax: void Format::setHAlign( $location ) Parameters: This function accepts single parameter as $location which takes the position, at which text is to be place 2 min read PHP | Spreadsheet_Excel_Writer | addFormat() Function The addFormat() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the format of a spreadsheet. Syntax:Â Workbook::&addFormat( $properties = array() ) Parameters: This function accepts single parameter $properties which accepts the array value. In order to set 2 min read PHP | Spreadsheet_Excel_Writer | setOutLine() Function The setOutLine() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set outlining for a font. Syntax:Â void Format::setOutLine() Parameters: This function does not accept any parameter. Return Value: This function returns TRUE on success and PEAR_ERROR on failure. Exa 1 min read Like