首頁 > 後端開發 > php教程 > php excel讀取 excel下拉選單怎麼做 excel2013官方下載 excel2007

php excel讀取 excel下拉選單怎麼做 excel2013官方下載 excel2007

WBOY
發布: 2016-07-29 08:49:34
原創
1600 人瀏覽過

當然首先要判斷是否有文件和文件類型,接著把文件保存到某個路徑中

<span>/*</span><span>*
 * 读取excel数据
 * @author Red
 * @date
 * @param $filename 文件所在路径+文件名
 * @param string $encode
 * @param $file_type
 * @return array
 </span><span>*/</span><span>function</span> readExcel(<span>$filename</span>, <span>$encode</span> = 'utf-8', <span>$file_type</span><span>)
{
    </span><span>include</span> './plugins/excel/PHPExcel.php'<span>;
    </span><span>include</span> './plugins/excel/PHPExcel/Reader/Excel2007.php'<span>;
    </span><span>include</span> './plugins/excel/PHPExcel/Writer/Excel5.php'<span>;
    </span><span>include</span> './plugins/excel/PHPExcel/Writer/Excel2007.php'<span>;

    </span><span>if</span> (<span>$file_type</span> == 'xlsx'<span>) {
        </span><span>$objReader</span> = PHPExcel_IOFactory::createReader('Excel2007'<span>);
    } </span><span>else</span><span> {
        </span><span>$objReader</span> = PHPExcel_IOFactory::createReader('Excel5'<span>);
    }

    </span><span>$objReader</span>->setReadDataOnly(<span>true</span><span>);

    </span><span>$objPHPExcel</span>        = <span>$objReader</span>->load(<span>$filename</span><span>);
    </span><span>$objWorksheet</span>       = <span>$objPHPExcel</span>-><span>getActiveSheet();
    </span><span>$hightestrow</span>        = <span>$objWorksheet</span>-><span>getHighestRow();
    </span><span>$highestColumn</span>      = <span>$objWorksheet</span>-><span>getHighestColumn();
    </span><span>$highestColumnIndex</span> = PHPExcel_Cell::columnIndexFromString(<span>$highestColumn</span><span>);
    </span><span>$excelData</span>          = <span>array</span><span>();
   //从第二行开始
    </span><span>for</span> (<span>$row</span> = 2; <span>$row</span> <= <span>$hightestrow</span>; <span>$row</span>++<span>) {
        </span><span>for</span> (<span>$col</span> = 0; <span>$col</span> < <span>$highestColumnIndex</span>; <span>$col</span>++<span>) {
            </span><span>$excelData</span>[<span>$row</span>][] = (<span>string</span>)<span>$objWorksheet</span>->getCellByColumnAndRow(<span>$col</span>, <span>$row</span>)-><span>getValue();
        }
    }

    </span><span>return</span><span>$excelData</span><span>;
}</span>
登入後複製

以上就介紹了php excel讀取,包含了excel的內容,希望對PHP教學有興趣的朋友有幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板