Home  >  Article  >  Backend Development  >  Read XLXS file in PHP and display header.

Read XLXS file in PHP and display header.

DDD
DDDOriginal
2024-10-02 14:08:01608browse

Read XLXS file in PHP and display header.

Read XLXS file using PHP

  • Use lib from GitHub call XLSXReader XLSXReader will helps to achieve this as it provide all the require functions. so, it begin with call it and use it further.

After install Composer and XLSXREADER call below file at top.

require('./XLSXReader.php');

  • Use any ExcelSheet for example..
    Add any Excel file in root of the project directory. So, we can use it latter.

  • Create index.php file and add below code.

<?php
require('./XLSXReader.php');
$targetPath = './hello world.xlsx';
$xlsx = new XLSXReader($targetPath);
$sheetNames = $xlsx->getSheetNames();
$imports=array();
$html="";
foreach($sheetNames as $sheetName) {

    $sheet = $xlsx->getSheet($sheetName);
    echo "<h3>".$sheet->sheetName."</h3>";

    $html.="<table border='1'>";
    foreach($sheet->getData() as $row) {
        $html.="<tr>";
        foreach($row as $key){
            $html.="<td>".$key."</td>"; 
        }
        $html.="<tr>";  
    }
    $html.="</table>";
}
echo $html;

Run it on your local or server. For more about demo and output visit at programmerdesk

The above is the detailed content of Read XLXS file in PHP and display header.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Small Swoole Entity ManagerNext article:None