Year: 2017
PHPExcel 生成excel并合并单元格
- by chenxue4076
- 7 years ago
使用Excel模板 第一行定义字段名字 如下 7个字段 demo.xlsx 线路 项目 监测照片数量 实际挑选数量 缺失 可补拍点位 客户名称 数据如下 //整理数组 按 design_no, building_no 合并数据 $need_list_array = array( array( ‘route_name’ => ‘route_name’, ‘building_name’ => ‘building_name’, ‘report_photo_num’ => 1, ‘success_count’ => 1, ‘lost_count’ => 0, ‘position’ => array(11111,222222,333333,44444,555555), ‘design_name’ =>’design_name’, ), array(….) ); 主要代码 包括合并单元格 以上使用的 CI(CodeIgniter)框架 //PHPExcel require_once APPPATH. ‘/third_party/phpexcel/PHPExcel.php’; // Create new PHPExcel object $objPHPExcel = PHPExcel_IOFactory::load(APPPATH.’/resource/demo.xlsx’); $objPHPExcel->setActiveSheetIndex(0); $objActSheet = $objPHPExcel->getActiveSheet(); $base_row = 2; $col_array = array( ‘route_name’ => 0, ‘building_name’ => 1, ‘report_photo_num’ => 2, ‘success_count’ => 3, ‘lost_count’ => 4, ‘position’ => 5, ‘design_name’ => 6, ); //$temp_arr = array(); if( ! empty($need_list_array)) { $key = 0; foreach ($need_list_array as $design_building => $item) { $this_count = count($item[‘position’]); $objActSheet->setCellValueByColumnAndRow($col_array[‘route_name’], $base_row + $key, $item[‘route_name’]); $objActSheet->setCellValueByColumnAndRow($col_array[‘building_name’], $base_row + $key, $item[‘building_name’]); $objActSheet->setCellValueByColumnAndRow($col_array[‘report_photo_num’], $base_row + $key, $item[‘report_photo_num’]); $objActSheet->setCellValueByColumnAndRow($col_array[‘success_count’], $base_row + $key, $item[‘success_count’]); $objActSheet->setCellValueByColumnAndRow($col_array[‘lost_count’], $base_row + $key, $item[‘lost_count’]); foreach ($item[‘position’] as $i => $item_position) { $objActSheet->setCellValueByColumnAndRow($col_array[‘position’], $base_row + $key + $i, $item[‘position’][$i]); } $objActSheet->setCellValueByColumnAndRow($col_array[‘design_name’], $base_row + $key, $item[‘design_name’]); //合并单元格 if($this_count > 1) { $objActSheet->mergeCellsByColumnAndRow($col_array[‘route_name’], $base_row + $key, $col_array[‘route_name’], $base_row + $key + $this_count – 1); $objActSheet->getStyleByColumnAndRow($col_array[‘route_name’], $base_row + $key)->applyFromArray( array( ‘alignment’ => array( /*’horizontal’ => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,*/ ‘vertical’ => PHPExcel_Style_Alignment::VERTICAL_CENTER))); $objActSheet->mergeCellsByColumnAndRow($col_array[‘building_name’], $base_row + $key, $col_array[‘building_name’], $base_row + $key + $this_count –
查看全文解决 Can’t connect to HTTPS URL because the SSL module is not available
- by chenxue4076
- 8 years ago
解决 pip._vendor.requests.exceptions.SSLError: Can’t connect to HTTPS URL because the SSL module is not available.
pip._vendor.requests.packages.urllib3.exceptions.SSLError: Can’t connect to HTTPS URL because the SSL module is not available.
算法之 分治法/递归排序/归并排序 代码PHP版
- by chenxue4076
- 8 years ago
先定义递归/分治/归并函数 function merge_sort($data = array(), $start = 0, $length = 0) { if($length – $start > 1) { $middle = floor(($start + $length) / 2); $data = merge_sort($data, $start, $middle); $data = merge_sort($data, $middle, $length); $data = merge($data, $start, $middle, $length); } return $data; } function merge($data = array(), $start=0, $middle=0, $length=0) { $left = $middle – $start; $right = $length – $middle; $array_left = array(); $array_right = array(); for($i = 0; $i < $left; $i++) { $array_left[$i] = $data[$start + $i]; } for($j = 0; $j < $right; $j++) { $array_right[$j] = $data[$middle + $j]; } $m = $n = 0; for($k = $start; $k < $length; $k++) { if( ! empty($array_left[$m]) && ! empty($array_right[$n])) { if($array_left[$m] <= $array_right[$n]) { $data[$k] = $array_left[$m]; $m++; } else { $data[$k] = $array_right[$n]; $n++; } } elseif ( ! empty($array_left[$m])) { $data[$k] = $array_left[$m]; $m++; } else { $data[$k] = $array_right[$n]; $n++; } } return $data; } 调用方法 $result = merge_sort($data, 0, count($data)) 返回一个升序的数组 时间复杂度 Θ(n lgn) 难点: 感觉到处是难点 虽然自己成功调试出正确结果,但总是感觉不能全部理解。 (353)
查看全文