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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                來源:https://blog.csdn.net/qq_34625397/article/details/136225972 前提是已經安裝了phpspreadsheet ( composer require phpoffice/phpspreadsheet ) 一、 數據拼裝,調用excel類 ``` <?php /** * 電子臺賬 * Date: 2023/4/20 * Time: 17:28 */ namespace app\store\controller; use app\common\controller\Excel; use app\common\model\ModelRedis; use app\store\model\ModelSaleStoreInput; class Ledger extends \app\ApiCommon { /** * 導出數據拼裝 * @param $ids string 出庫id 列表 1,2,3,4 */ public function export_input($ids,$start,$end){ $where = []; if(!empty($start) && !empty($end)){ $where[] = ['ctime','>=',strtotime($start)]; $where[] = ['ctime','<=',strtotime($end)]; }else{ $where[] = ['id','in',$ids]; } $list = ModelSaleStoreInput::where($where)->field($field)->select()->toArray(); if(empty($list)){ return $this->apiError('數據不存在'); } $data = $list; //此處說明:解決數字太長尾數變000的問題 //由于數字超過15位,會被顯示成0或者加小數點處理。造成這種情況是由于Excel內置的數值有效范圍是15位。超過15位,如果要顯示的話,就需要轉換成非數字格式。比如文本格式。 foreach ($data as $key => $value) { $tmp = []; $explode_no = self::decode_explode_no($value['explode_no']); array_push($tmp,"\t".$value['id']."\t"); array_push($tmp,"\t".$value['ctime']."\t"); array_push($tmp,"\t".$value['store_name']."\t"); array_push($tmp,"\t".$value['name']."\t"); array_push($tmp,"\t".$value['spec_name']."\t"); array_push($tmp,"\t".$value['amount']."\t"); array_push($tmp,"\t".$explode_no."\t"); array_push($tmp,"\t".$value['supply_company']."\t"); array_push($tmp,"\t".$value['deliver']."\t"); array_push($tmp,"\t".self::desensitizedIdCard($value['deliver_idcard'])."\t"); array_push($tmp,"\t".$value['carry_no']."\t"); array_push($tmp,"\t".$value['buy_no']."\t"); array_push($tmp,"\t".$value['storeman_names']."\t"); array_push($tmp,"\t".$value['storeman_signs']."\t"); array_push($tmp,"\t".$value['safety_name']."\t"); array_push($tmp,"\t".$value['safety_sign']."\t"); $data[$key] = $tmp; } //保存到本地臨時目錄 $path = './uploads/tmp/'; $excel_name = '數據盤點'; $title = ['id','時間','倉庫名','物品名稱','品種規格','物品數量','編號','供貨單位','送貨人','身份證號','運輸證號','購買證號','庫管員','庫管員簽字','安全員','安全員簽字']; $file_name = date('Y-m-d').rand(1000,9999).$excel_name.'.xlsx'; $res = Excel::export($title,$data,$path,$file_name); return $res; } } ``` 二、封裝好的Excel類:注意遠程圖片必須base64后緩存到本地再寫入excel。 ``` <?php /** * excel導入導出公共類 * Date: 2023/4/27 * Time: 18:39 */ namespace app\common\controller; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; use think\exception\ValidateException; use think\facade\Filesystem; class Excel { /** * 數據導出Excel * @param array $title 表頭 * @param array $data 數據源 * @param string $path 目錄 * @param string $file_name 文件名稱 * @return array */ public static function export($title = [], $data = [],$path,$file_name="") { try{ $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); // 表頭單元格內容 第一行 $titCol = 'A'; foreach ($title as $value) { // 單元格內容寫入 $sheet->setCellValue($titCol . '1', $value); $titCol++; } //單元格內容居中 $sheet->getDefaultRowDimension()->setRowHeight(60);//默認行高60 $sheet->getDefaultColumnDimension()->setAutoSize(true);//列寬自適應 $sheet->getStyle('A:'.$titCol)->getAlignment()->setVertical('center');//內容容垂居中 $sheet->getStyle('A:'.$titCol)->getAlignment()->setHorizontal('center');//內水平直居中 // 從第二行開始寫入數據 $row = 2; foreach ($data as $item) { $dataCol = 'A'; foreach ($item as $value) { // 單元格內容寫入 $values = explode(".",$value); $ext = trim(end($values)); if(in_array($ext,['jpg','png','jpeg'])){ //多圖導出 $num = 10; $images = explode(',', $value); foreach ($images as $k => $v) { $drawings[$k] = new Drawing(); $img = self::img_resource(trim($v),$path,$k); //圖片路徑,項目目錄下就行 $drawings[$k]->setResizeProportional(false); $drawings[$k]->setName('手動簽名圖片'); $drawings[$k]->setDescription('手動簽名圖片展示'); $drawings[$k]->setPath($img,true); $drawings[$k]->setWidth(60); $drawings[$k]->setHeight(60); $drawings[$k]->setOffsetX($num); $drawings[$k]->setOffsetY(10); $drawings[$k]->setCoordinates($dataCol . $row); $drawings[$k]->setWorksheet($sheet); $num = $num + 70; // 增加每張圖之間的間距 } }else{ $sheet->setCellValue($dataCol . $row, $value); } //自適應列寬 $len = strlen($value); if($len>1){ //空數據不做處理避免影響到有數據的列寬度 $sheet->getColumnDimension($dataCol)->setWidth($len); } $dataCol++; } $row++; } $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); if(is_file($path.$file_name)){ file_put_contents($path.$file_name,'');; } $writer->save($path.$file_name); return ['code'=>0,'url'=>trim($path.$file_name,'.')]; }catch (\Exception $e){ return ['code'=>1,'msg'=>$e->getMessage()]; } } /** * 圖片緩存到本地 * @param $url string 遠程圖片地址 * @param $dir string 本地緩存目錄 * @param $i int 圖片序號 * @return mixed */ public static function img_resource($url,$dir,$i){ $data = file_get_contents($url); $path = $dir.time().'-'.$i; file_put_contents($path, $data); return $path; } } ``` 效果: ![](https://img.kancloud.cn/5b/3b/5b3b9d55cef0d47c84ec875a4a674aac_950x527.png) ![](https://img.kancloud.cn/d9/99/d999be31c8dbb797c0953e1b00dc548a_886x352.png)
                  <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>

                              哎呀哎呀视频在线观看