Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • PHP Tutorial
  • PHP Exercises
  • PHP Array
  • PHP String
  • PHP Calendar
  • PHP Filesystem
  • PHP Math
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP GMP
  • PHP IntlChar
  • PHP Image Processing
  • PHP DsSet
  • PHP DsMap
  • PHP Formatter
  • Web Technology
Open In App
Next Article:
PHP | Spreadsheet
Next article icon

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:

  • Agendas
  • Budgets
  • Calendars
  • Cards
  • Charts and Diagrams
  • Financial Tools (Loan calculators etc.)
  • Flyers
  • Forms
  • Inventories
  • Invoices
  • Lists and to-do checklists
  • Planners
  • Plans and proposals
  • Reports
  • Schedules
  • Timesheets

Requirements: The following software is developed using PHPSpreadsheet:

  • PHP version 5.6 or newer
  • PHP extension php_zip enabled
  • PHP extension php_xml enabled
  • PHP 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 1


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"          }       }  }

Next Article
PHP | Spreadsheet

S

sarthak_ishu11
Improve
Article Tags :
  • Technical Scripter
  • GeeksforGeeks Initiatives
  • Web Technologies
  • PHP
  • PHP-function
  • PHP-Spreadsheet

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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences