php 使用PHPEXcel导出表数据(2)
[PHP]代码 ------------------------导入操作------------------------ /** * $sql=INSERT INTO .mymsg::WY_MMB. (dizhi,xingming) VALUES (; */ //先上传再读取文件 function upByFile($sql, $url, $
[PHP]代码
------------------------导入操作------------------------ /** * $sql="INSERT INTO ".mymsg::WY_MMB." (dizhi,xingming) VALUES ("; */ //先上传再读取文件 function upByFile($sql, $url, $curRow = 2, $RIQI = true,$merge = FALSE,$mergeCol='B') { $CI = &get_instance(); $config['allowed_types'] = '*'; //充许所有文件 $config['upload_path'] = IMPORT; // 只在文件的路径 $CI->load->library('upload', $config); if ($CI->upload->do_upload()) { //默认名是:userfile $data = $CI->upload->data(); $full_name = $data['full_path']; //得到保存后的路径 $full_name = mb_convert_encoding($full_name, "GBK", "UTF-8"); $sheet = $CI->input->post("sheet"); //读取第x列图表 if (empty($sheet)) { $sheet = 0; } $CI->read_write->read_Facotry($full_name, $sql, $sheet, $curRow, $RIQI,$merge,$mergeCol); //执行插入命令 } $this->alert_msg(mymsg::IMPORT_SUCCESS, site_url($url)); } ------------------------------导出操作---------------------------------- //导出指定的表字段 public function show_export(){ //-----数据库字段 $field=implode(",",$this->input->post("listCheckBox_show"));//数据库字段 //显示名称 $titleArray=$this->input->post("listCheckBox_field");//显示的字段名称(字段Comment注解名,因为传进来的有些空数组,所以必须过滤) $title=array(); foreach ($titleArray as $key => $value) { if (!empty($value)) { $title[]=$value; } } //---数据库表名 $table=$this->input->post("tableName"); //--数据库表名称(Comment注释) $show_name=$this->input->post("tableComment"); //--导出类型 $type=$this->input->post("type"); //--where 年月 $y_month=$this->input->post("year_month"); if(!empty($y_month)){ $where["riqi"]=$y_month; $datas=$this->mcom_model->queryByWhereReField($field,$where,$table); }else{ //--写出的数据 $datas=$this->mcom_model->queryByField($field,$table); } //---开始导出 $this->read_write->write_Factory($title,$datas,$show_name,$type); }
QQ截图20120711125755.gif
imgs/asCode/11125836_P8VJ.gif
收藏文章
精彩图集
精彩文章