PHP(18)php输出Exce转html

2023-07-08  本文已影响0人  弗兰克万岁

orcome/PHP-Read-Excel: Show data from excel to layout table (github.com)

<!DOCTYPE html>
<html>
<head>
    <title>Read Excel By PHP Excel</title>
</head>
<body>
    <center>
        <h2>Read Excel By PHP Excel</h2>

        <?php
            require_once "ClassesPhpExcel/PHPExcel.php";
            $path = "33.xlsx";
            $reader = PHPExcel_IOFactory::createReaderForFile($path);
            $excelObj = $reader->load($path);

            $worksheet = $excelObj->getSheet('0');

            $lastRow = $worksheet->getHighestRow();
            $columnCount = $worksheet->getHighestDataColumn();
            $columnCountNumber = PHPExcel_cell::columnIndexFromString($columnCount);

            echo "<table border='1'>";
            echo "<tr><td>NAMA</td><td>KELAS</td></tr>";
            jump_col=[1,7]
            for ($row = 2; $row <= $lastRow; $row++) {
                echo "<tr>";


                for ($col = 0; $col < $columnCountNumber; $col++) {
                    if($col )
                    echo "<td>";
                    echo iconv('utf-8','gbk',$worksheet->getCell(PHPExcel_Cell::stringFromColumnIndex($col).$row)->getValue());
                    echo "</td>";
                }
                echo "</tr>";
            }
            echo "</table>";

        ?>
    </center>
</body>
</html>
上一篇下一篇

猜你喜欢

热点阅读