thinkphp3.2导出


public function test()
{
set_time_limit(0);
ini_set('memory_limit', '500M');

//导入PHPExcel类库,因为PHPExcel没有用命名空间,只能inport导入
import("Org.Excel.PHPExcel");
//要导入的xls文件,位于根目录下的Public文件夹
//创建PHPExcel对象,注意,不能少了
$PHPExcel = new PHPExcel();

//如果excel文件后缀名为.xlsx,导入这下类
//import("Org.Util.PHPExcel.Reader.Excel2007");
//$PHPReader=new PHPExcel_Reader_Excel2007();

//如果excel文件后缀名为.xls,导入这个类
import("Org.Util.PHPExcel.Reader.Excel5");
$PHPReader = new PHPExcel_Reader_Excel5();


if ($_POST) {
$filePath = $_FILES['files']['tmp_name'];
//$PHPReader = new PHPExcel_Reader_Excel2007();
$PHPReader = new PHPExcel_Reader_Excel2007();
if (!$filePath) {
echo "<h1 style='color: red'> file don't exist! </h1>";
return;
}

if (!$PHPReader->canRead($filePath)) {
$PHPReader = new PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($filePath)) {
$PHPReader = new PHPExcel_Reader_CSV();
if (!$PHPReader->canRead($filePath)) {
echo 'no Excel';
return;
}
}
}
$PHPExcel = $PHPReader->load($filePath);
$currentSheet = $PHPExcel->getSheet(0);

/*取得一共有多少列*/
$allColumn = $currentSheet->getHighestColumn();
/*取得一共有多少行*/
$allRow = $currentSheet->getHighestRow();

for($currentRow=2;$currentRow <=$allRow;$currentRow++){
$trsaction_id = $currentSheet->getCell('A' . $currentRow)->getValue();
          //这里循环得到结果。

}
}
//-----------------------------------------------------------
$this->display();
}




2.页面:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="__URL__/test" method="post" enctype="multipart/form-data" >
导入:<input type="file" name="files" />
<input type="submit" name="sub" value="提交" />
</form>
</body>
</html>
原文地址:https://www.cnblogs.com/kobigood/p/4204440.html