美文网首页
PHP(18)php输出Exce转html

PHP(18)php输出Exce转html

作者: 弗兰克万岁 | 来源:发表于2023-07-08 13:18 被阅读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>
    

    相关文章

      网友评论

          本文标题:PHP(18)php输出Exce转html

          本文链接:https://www.haomeiwen.com/subject/gsqjudtx.html