Yii中使用PHPexcel擷取excel中資料_PHP教程

來源:互聯網
上載者:User
1.view中代碼如下:



2.controller中代碼如下:

if(isset($_FILES['batchFile']) && $_FILES['batchFile']['error']==0)
{
spl_autoload_unregister(array('YiiBase','autoload')); //登出YII的自動載入,採用手動匯入,PHPexcel有自己的載入功能
include_once(dirname(dirname(__FILE__)).'\extensions/PHPExcel.php'); //按照自己的路徑匯入類檔案
include_once(dirname(dirname(__FILE__)).'\extensions/PHPExcel/IOFactory.php');

$objPHPExcel = PHPExcel_IOFactory::load($_FILES['batchFile']['tmp_name']); //匯入上傳的excel檔案的資料邏輯
$objWorksheet = $objPHPExcel->getActiveSheet(0); //擷取excel中sheet(0)的資料
spl_autoload_register(array('YiiBase','autoload')); //重新啟用YII的自動載入

$EXCEL_VALUE = array();
foreach ($objWorksheet->getRowIterator() as $row) //遍曆資料
{
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true);
foreach ($cellIterator as $cell)
{
$EXCEL_VALUE[] = $cell->getValue();
}
}
dump($EXCEL_VALUE);

這裡我只用到這些,其他的還不是很清楚,繼續研究。
參考:本人所用的PHPExcel版本為該地址資源:http://download.csdn.net/detail/btbdylq/3798155

http://www.bkjia.com/PHPjc/761777.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/761777.htmlTechArticle1.view中代碼如下: form name="frmBatchSettle" id="" action="" method="post" enctype="multipart/form-data" 請選擇包含批量IP稱的EXCEL檔案 input type="file" name="bat...

  • 聯繫我們

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