首页 > Web开发 > 详细

thinkphp3.2导出

时间:2015-01-05 21:39:44      阅读:349      评论:0      收藏:0      [点我收藏+]

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>

thinkphp3.2导出

原文:http://www.cnblogs.com/kobigood/p/4204440.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!