微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

HTML上传excel文件,php解析逐条打印输出

 有问题可以扫码加我微信,有偿解决问题。承接小程序开发

微信小程序开发交流qq群   173683895  、 526474645 ;

正文:

nofollow">PHPExcel文件下载  ←跳转地址

demo

<pre class="has">
<code class="language-html"><!DOCTYPE html>
<html lang="zh">

<head>
    <<a href="https://www.jb51.cc/tag/Meta/" target="_blank" class="keywords">Meta</a> charset="UTF-8"&gt;
    <title>Title</title>
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.js"&gt;</script>
</head>

<body>
    <form action="http://gohosts.com/index.<a href="https://www.jb51.cc/tag/PHP/" target="_blank" class="keywords">PHP</a>" enctype="multipart/form-data" method="post"&gt;
        <input type="file" name="excel_file" class="input"&gt;
        <button class="btn btn-primary" type="submit"&gt;<a href="https://www.jb51.cc/tag/shangchuan/" target="_blank" class="keywords">上传</a></button>
    </form>
</body>

PHP

<pre class="has">
<code class="language-PHP"><?php
header("Content-type: text/html; charset=utf-8");
require_once 'phpExcel/PHPExcel.php';
$filePath = $_FILES ['excel_file'] ['tmp_name']; //[文件名][临时路径-写死的]
$PHPReader = new PHPExcel_Reader_Excel2007();
if(!$PHPReader->canRead($filePath)){
$PHPReader = new PHPExcel_Reader_Excel5();
if(!$PHPReader->canRead($filePath)){
echo 'no Excel';
return;
}
}
$PHPExcel = $PHPReader->load($filePath);
$currentSheet = $PHPExcel->getSheet(0); //读取第一张工作表
$allColumn = $currentSheet->getHighestColumn(); //取得最大的列号
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行
for($currentRow = 1;$currentRow <= $allRow;$currentRow++){
for($currentColumn='A';$currentColumn<= $allColumn; $currentColumn++){
$arr[$currentColumn] = (string)$currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue();
}
$val[]=$arr;
}
echo "

";
print_r($val);
?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐