<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                [![](http://static.phpgrace.com/statics/images/downcode.png)](http://www.phpgrace.com/tools/download/16.html) # excel 讀寫操作 ## **功能說明** excel 讀寫操作基于 PHPExecl 類庫,可以方便的對 Excel 進行操作。 ## **部署說明** >下載?PHPExcel.zip?解壓后將全部文件部署到?phpGrace/tools?下 ## **調用說明** 遵守第三方類庫規則(加載、命名空間),使用 tool() 函數實例化。 ## **生成 Excel 演示** ~~~ <?php class?indexController?extends?grace{ ????public?function?index(){ ????????$excel?=?tool('PHPExcel'); ????????//基礎信息 ????????$excel->getProperties()->setCreator("phpGrace") ?????????????????????????????->setLastModifiedBy("phpGrace") ?????????????????????????????->setTitle("phpGrace?demo") ?????????????????????????????->setSubject("objPHPExcel"); ???????????//設置?sheet?名稱 ???????????$excel->getActiveSheet(0)->setTitle('學生信息表'); ????????//標題 ????????$excel->setActiveSheetIndex(0) ????????????????????->setCellValue('A1',?'姓名') ????????????????????->setCellValue('B1',?'性別') ????????????????????->setCellValue('C1',?'年齡'); ???????? ????????//數據填充【此數據可以來自數據庫】 ????????$data?=?array( ????????????array('張三',?'男',?18), ????????????array('李四',?'男',?20), ????????????array('lucy',?'女',?18) ????????); ????????$i?=?2; ????????foreach($data?as?$rows){ ????????????$excel->setActiveSheetIndex(0) ????????????????????->setCellValue('A'.$i,?$rows[0]) ????????????????????->setCellValue('B'.$i,?$rows[1]) ????????????????????->setCellValue('C'.$i,?$rows[2]); ????????????$i++; ????????} ????????//保存為?xls ????????$objWriter?=?PHPExcel_IOFactory::createWriter($excel,?'Excel5'); ????????$objWriter->save('t.xls'); ????} } ~~~ ## **讀取 excel -?tool('PHPExcelReader');** 使用?PHPExcelReader 可以快速的讀取 excel 內容,返回數據格式: ~~~ array( ????//sheet?數據,多個元素對應數組?index ????0?=>?array( ????????//?工作表名 ????????'title'?=>?'sheet?名稱', ????????//工作表數據 ????????'data'??=>?array( ????????????//每一行數據 ????????????0?=>?array(單元內容,?單元內容,...) ????????????1?=>?array(......) ????????) ????), ????1?=>?array(......) ); ~~~ ## **讀取演示** ~~~ <?php class?indexController?extends?grace{ ????public?function?index(){ ????????//實例化?excel?讀取對象 ????????$PHPExcelReader?=?tool('PHPExcelReader'); ????????//讀取指定的?excel?文件 ????????$sheets?=?$PHPExcelReader->read('t.xls'); ????????echo?'<h2>'.$sheets[0]["title"].'</h2>'; ????????echo?'<table>'; ????????foreach($sheets[0]['data']?as?$sheet){ ????????????echo?'<tr> ????????????????<td>'.$sheet[0].'</td> ????????????????<td>'.$sheet[1].'</td> ????????????????<td>'.$sheet[2].'</td> ????????????</tr>'; ????????} ????????echo?'</table>'; ????????echo?'<h2>'.$sheets[1]["title"].'</h2>'; ????????echo?'<table>'; ????????foreach($sheets[1]['data']?as?$sheet){ ????????????echo?'<tr> ????????????????<td>'.$sheet[0].'</td> ????????????????<td>'.$sheet[1].'</td> ????????????</tr>'; ????????} ????????echo?'</table>'; ????} } ~~~ 更多資料 關于 PHPExcel 更多的介紹資料:?[https://blog.csdn.net/pengone/article/details/47724423](https://blog.csdn.net/pengone/article/details/47724423)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看