thinkphp3.2匯出

來源:互聯網
上載者:User

標籤:


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匯出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.