【问题标题】:How to extract values from excel (xlxs) to html text如何从excel(xlxs)中提取值到html文本
【发布时间】:2019-08-06 23:42:47
【问题描述】:

我正在尝试从 excel 表中提取值以放入我的 html 中。

这是我的excel数据:

例如,我希望能够获取每列的总数并将其插入到 html 中。如下:

<h1> VALUE </h1>

【问题讨论】:

    标签: html excel csv xlsx


    【解决方案1】:

    //首先,从(https://github.com/PHPOffice/PHPExcel)下载PHPExcel,保存到项目目录下。它已被弃用,但页面上有指向它当前版本的链接。以下代码适用于旧版本,但在经过测试和工作时可能会帮助您入门

    <?php
    require_once('PHPExcel.php');
    include 'PHPExcel/IOFactory.php';
    
    $inputFileName = 'test_data.xlsx'; // Your Excel spreadsheet
    
    if(file_exists($inputFileName)){
        //  Read your Excel workbook
        try {
            $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
            $objReader = PHPExcel_IOFactory::createReader($inputFileType);
            $objPHPExcel = $objReader->load($inputFileName);
        } catch (Exception $e) {
            die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
        }
    
        //  Get worksheet dimensions
        $sheet = $objPHPExcel->getSheet(0);
        $highestRow = $sheet->getHighestRow();
        $highestColumn = $sheet->getHighestColumn();
    
        //  Loop through each row of the worksheet in turn
        for ($row = 2; $row <= $highestRow; $row++) {
            //  Read a row of data into an array
            $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
            foreach($rowData[0] as $k=>$v){
                echo $k, $v.'<br>';
            }    
        }
    }
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-16
      • 1970-01-01
      • 2021-01-07
      • 2019-02-06
      • 2018-06-11
      • 2016-02-07
      • 1970-01-01
      相关资源
      最近更新 更多