phpexcel匯出資料表格

來源:互聯網
上載者:User

標籤:log   eval   ida   pex   file   attach   class   new   str   

1.下載phpexcel

2.在頁面引入phpexcel的類檔案,並且造該類的對象

include("../chajian/phpexcel/Classes/PHPExcel.php");$excel = new PHPExcel();

3.查詢資料庫得出二維數組這裡數組名為:$attr

4.匯出excel代碼,表頭數組和資料數組對應:

//Excel表格式,這裡簡略寫了10列$letter = array(‘A‘,‘B‘,‘C‘,‘D‘,‘E‘,‘F‘,‘F‘,‘G‘,‘H‘,‘I‘);//表頭數組$tableheader = array(‘彙報時間‘,‘彙報完成度‘,‘彙報人員‘,‘最終完成度‘,‘導師評語‘);//填充表頭資訊for($i = 0;$i < count($tableheader);$i++) {$excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");}//填充表格資訊for ($i = 2;$i <= count($attr) + 1;$i++) {$j = 0;foreach ($attr[$i - 2] as $key=>$value) {$excel->getActiveSheet()->setCellValue("$letter[$j]$i","$value");$j++;}}//建立Excel輸入對象$write = new PHPExcel_Writer_Excel5($excel);header("Pragma: public");header("Expires: 0");header("Cache-Control:must-revalidate, post-check=0, pre-check=0");header("Content-Type:application/force-download");header("Content-Type:application/vnd.ms-execl");header("Content-Type:application/octet-stream");header("Content-Type:application/download");;header("Content-Disposition:attachment;filename=‘{$sj}_{$bt}作業.xls‘");header("Content-Transfer-Encoding:binary");$write->save(‘php://output‘);

5.如果長數字串顯示為科學計數解決方案

(1)在設定值的時候顯示的指定資料類型

$excel->getActiveSheet()->setCellValueExplicit(‘D1‘,120000000000,PHPExcel_Cell_DataType::TYPE_STRING);

(2)在數字字串前加一個空格使之成為字串

$excel->getActiveSheet()->setCellValue(‘D1‘,‘ ‘ . 120000000000);

phpexcel匯出資料表格

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.