Jump to content

read excel file using php 8


Recommended Posts

Dear Respected Sir/Madam

 

I am looking for excel file reader specifically .xlsx reader using php 8

 

I was using PHPExcel-develop but doesnot support php 8
also tried
PhpSpreadsheet-master
PHPExcel-1.8
spreadsheet-reader-master

with no success
can anyone help me
compatible excel reader (preferably .xlsx)

 

Vikas

Link to comment
Share on other sites

To read .xlsx files using PHP 8, you can use the PhpSpreadsheet library. It's the successor to PHPExcel and fully supports PHP 8. You can run this command "composer require phpoffice/phpspreadsheet" and Once you have PhpSpreadsheet installed, you can use it to read .xlsx files. Here's a basic example:

<?php
require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\IOFactory;

try {
    $spreadsheet = IOFactory::load('path/to/your/file.xlsx');
    $sheet = $spreadsheet->getActiveSheet();

    // Get the highest row and column numbers referenced in the worksheet
    $highestRow = $sheet->getHighestRow(); // e.g. 10
    $highestColumn = $sheet->getHighestColumn(); // e.g 'F'

    // Iterate over each row in the worksheet in turn
    for ($row = 1; $row <= $highestRow; $row++) {
        $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
        print_r($rowData);
    }
} catch (Exception $e) {
    echo 'Error loading file: ', $e->getMessage();
}
?>

 

Link to comment
Share on other sites

3 hours ago, Olumide said:

To read .xlsx files using PHP 8, you can use the PhpSpreadsheet library. It's the successor to PHPExcel and fully supports PHP 8. You can run this command "composer require phpoffice/phpspreadsheet" and Once you have PhpSpreadsheet installed, you can use it to read .xlsx files. Here's a basic example:

<?php
require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\IOFactory;

try {
    $spreadsheet = IOFactory::load('path/to/your/file.xlsx');
    $sheet = $spreadsheet->getActiveSheet();

    // Get the highest row and column numbers referenced in the worksheet
    $highestRow = $sheet->getHighestRow(); // e.g. 10
    $highestColumn = $sheet->getHighestColumn(); // e.g 'F'

    // Iterate over each row in the worksheet in turn
    for ($row = 1; $row <= $highestRow; $row++) {
        $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
        print_r($rowData);
    }
} catch (Exception $e) {
    echo 'Error loading file: ', $e->getMessage();
}
?>

 

highly appreciate your help

 

Link to comment
Share on other sites

On 6/28/2024 at 10:48 AM, Olumide said:

To read .xlsx files using PHP 8, you can use the PhpSpreadsheet library. It's the successor to PHPExcel and fully supports PHP 8. You can run this command "composer require phpoffice/phpspreadsheet" and Once you have PhpSpreadsheet installed, you can use it to read .xlsx files. Here's a basic example:

<?php
require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\IOFactory;

try {
    $spreadsheet = IOFactory::load('path/to/your/file.xlsx');
    $sheet = $spreadsheet->getActiveSheet();

    // Get the highest row and column numbers referenced in the worksheet
    $highestRow = $sheet->getHighestRow(); // e.g. 10
    $highestColumn = $sheet->getHighestColumn(); // e.g 'F'

    // Iterate over each row in the worksheet in turn
    for ($row = 1; $row <= $highestRow; $row++) {
        $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
        print_r($rowData);
    }
} catch (Exception $e) {
    echo 'Error loading file: ', $e->getMessage();
}
?>

 

i  wish to read excel  using a php code that runs on  web server / website

1. My main issue is how to use composer on website before using this code can you please help me 

2. Which file i need to download from internet and how to run composer that will help me to run the code 

Link to comment
Share on other sites

On 7/2/2024 at 11:56 AM, VikasAthavale said:

i  wish to read excel  using a php code that runs on  web server / website

1. My main issue is how to use composer on website before using this code can you please help me 

2. Which file i need to download from internet and how to run composer that will help me to run the code 

You'll need to install Composer on your web server. Composer is a dependency manager for PHP that allows you to easily manage libraries and packages.

Go to the https://getcomposer.org/, download the Installer for Composer depending on your OS.

Open the downloaded Composer-Setup.exe (Windows OS as an example) file.

Follow the prompts in the installation wizard.

Make sure to select the option to add Composer to the system PATH during installation.

Verify Installation:

Open Command Prompt.

Type composer and press Enter.

You should see the Composer version and available commands, confirming that Composer is installed and accessible globally.

Open Command Prompt and navigate to your project directory: cd path\to\your\project\directory

Use Composer to install the PhpSpreadsheet library by creating a composer.json file and running composer install.

Include the Composer autoload file in your PHP script and use PhpSpreadsheet to read your Excel files.

Link to comment
Share on other sites

  • 2 weeks later...
On 7/5/2024 at 4:39 AM, Olumide said:

You'll need to install Composer on your web server. Composer is a dependency manager for PHP that allows you to easily manage libraries and packages.

Go to the https://getcomposer.org/, download the Installer for Composer depending on your OS.

Open the downloaded Composer-Setup.exe (Windows OS as an example) file.

Follow the prompts in the installation wizard.

Make sure to select the option to add Composer to the system PATH during installation.

Verify Installation:

Open Command Prompt.

Type composer and press Enter.

You should see the Composer version and available commands, confirming that Composer is installed and accessible globally.

Open Command Prompt and navigate to your project directory: cd path\to\your\project\directory

Use Composer to install the PhpSpreadsheet library by creating a composer.json file and running composer install.

Include the Composer autoload file in your PHP script and use PhpSpreadsheet to read your Excel files.

for those who struggle to use composer

On web server composer is already installed. open cpanel -> terminal for command prompt 

type command

>composer -v 

will show you the details of composer installed

https://packagist.org/ helps you the search the packages to be installed 

and on top the command to install using composer (to be used after opening terminal from cpanel

example

https://packagist.org/packages/phpmailer/phpmailer

on top of the page   command line to be used is shown

i had spent lot of time in finding this and wish to save your time incase you are not aware

 

 

 

Edited by VikasAthavale
forgot to mention https://packagist.org/ that was great help to me
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.