您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

phpexecl导出 循环时间问题

2024/3/15 11:20:05发布34次查看
做php导出,需要循环输出数据到execl中,一开始写了一个,觉得时间有点长,就缩短了下,发现时间还变多了,求教这是为什么啊?谢谢了先。
原先的代码片段:
//归总每个一级分类下的二级分类foreach($first_cate_array as $fkey => $fvalue){ foreach($cate as $ck=>$cv){ if($cv['parentid'] == $fvalue['id']){ $first_cate_array[$fkey]['second_cate'][] = $cv; } } //获得每个一级分类下二级分类的数目 $second_count = count($first_cate_array[$fkey]['second_cate']); $first_cate_array[$fkey]['second_count'] = $second_count == 0 ? 1 : $second_count; }/*************************************************************************/foreach($first_cate_array as $fk => $fv){ //一级目录起始行数 if($fk == 0){ $stapos = $num; $en_stapos = $stapos+$cate_count; }else{ $stapos = $stapos+$first_cate_array[$fk-1]['second_count']; $en_stapos = $stapos+$cate_count; } foreach($fv['second_cate'] as $sck => $scv){ //二级目录起始行数 $stapos1 = $stapos+$sck; $en_stapos1 = $en_stapos+$sck; foreach($scv['pro'] as $spk => $spv){ $str1 = 70+$spk*3; $str1 = chr($str1); $str2 = 71+$spk*3; $str2 = chr($str2); $str3 = 72+$spk*3; $str3 = chr($str3); //中文 $collect = $spv['name'].'('.$spv['description'].')'; $objactsheet->setcellvalue($str1.$stapos1, $collect); $objactsheet->setcellvalue($str2.$stapos1, $spv['name']); $objactsheet->setcellvalue($str3.$stapos1, $spv['description']); //英文 $en_collect = $spv['en_name'].'('.$spv['en_description'].')'; $objactsheet->setcellvalue($str1.$en_stapos1, $en_collect); $objactsheet->setcellvalue($str2.$en_stapos1, $spv['en_name']); $objactsheet->setcellvalue($str3.$en_stapos1, $spv['en_description']); } //中文 $objactsheet->setcellvalue('e'.$stapos1, $scv['category']); //英文 $objactsheet->setcellvalue('e'.$en_stapos1, $scv['en_category']); } //中文 $objactsheet->setcellvalue('d'.$stapos, $fv['category']); $stopos = $stapos + $fv['second_count'] - 1; $mergecellstr = 'd'.$stapos.':d'.$stopos; $objactsheet->mergecells($mergecellstr); //英文 $objactsheet->setcellvalue('d'.$en_stapos, $fv['en_category']); $en_stopos = $en_stapos + $fv['second_count'] - 1; $en_mergecellstr = 'd'.$en_stapos.':d'.$en_stopos; $objactsheet->mergecells($en_mergecellstr);}

修改以后的片段:
$second_count = 0;//归总每个一级分类下的二级分类foreach($first_cate_array as $fkey => $fvalue){ //一级目录起始行数 $stapos = $num+$second_count; $en_stapos = $stapos+$cate_count; $second_stapos = 0; foreach($cate as $ck=>$cv){ if($cv['parentid'] == $fvalue['id']){ //二级目录起始行数 $stapos1 = $stapos+$second_stapos; $en_stapos1 = $en_stapos+$second_stapos; foreach($cv['pro'] as $spk => $spv){ $str1 = 70+$spk*3; $str1 = chr($str1); $str2 = 71+$spk*3; $str2 = chr($str2); $str3 = 72+$spk*3; $str3 = chr($str3); //中文 $collect = $spv['name'].'('.$spv['description'].')'; $objactsheet->setcellvalue($str1.$stapos1, $collect); $objactsheet->setcellvalue($str2.$stapos1, $spv['name']); $objactsheet->setcellvalue($str3.$stapos1, $spv['description']); //英文 $en_collect = $spv['en_name'].'('.$spv['en_description'].')'; $objactsheet->setcellvalue($str1.$en_stapos1, $en_collect); $objactsheet->setcellvalue($str2.$en_stapos1, $spv['en_name']); $objactsheet->setcellvalue($str3.$en_stapos1, $spv['en_description']); } //中文 $objactsheet->setcellvalue('e'.$stapos1, $cv['category']); //英文 $objactsheet->setcellvalue('e'.$en_stapos1, $cv['en_category']); $second_stapos ++ ; $second_count ++ ; } } //中文 $objactsheet->setcellvalue('d'.$stapos, $fvalue['category']); $stopos = $num + $second_count - 1; $mergecellstr = 'd'.$stapos.':d'.$stopos; $objactsheet->mergecells($mergecellstr); //英文 $objactsheet->setcellvalue('d'.$en_stapos, $fvalue['en_category']); $en_stopos = $num + $cate_count + $second_count - 1; $en_mergecellstr = 'd'.$en_stapos.':d'.$en_stopos; $objactsheet->mergecells($en_mergecellstr);}

我觉得原先的代码多一个上面的循环,时间应该多一点。。。查询1700条数据耗时84s。。。下面附上全文代码:
/** * 导出execl */ public function export(){ import(@.org.phpexcel); //import(lib.org.phpexcel.iofactory,app_path,.php); import(lib.org.phpexcel.writer.excel5,app_path,.php); import(lib.org.phpexcel.writer.excel2007,app_path,.php); // 创建一个处理对象实例 $objphpexcel = new phpexcel(); // 创建文件格式写入对象实例, uncomment //$objwriter = new phpexcel_writer_excel5($objphpexcel); // 用于其他版本格式 // or $objwriter = new phpexcel_writer_excel2007($objphpexcel); // 用于 2007 格式 //$objwriter->setoffice2003compatibility(true); //************************************* //设置文档基本属性 // $objprops = $objphpexcel->getproperties(); // $objprops->setcreator(test); //创建人// $objprops->setlastmodifiedby(test); //最后修改人// $objprops->settitle(office xls test document); //标题// $objprops->setsubject(office xls test document, demo); //题目// $objprops->setdescription(test document, generated by phpexcel.); //描述// $objprops->setkeywords(office excel phpexcel); //关键字// $objprops->setcategory(test); //种类 //************************************* //设置当前的sheet索引,用于后续的内容操作。 //一般只有在使用多个sheet的时候才需要显示调用。 //缺省情况下,phpexcel会自动创建第一个sheet被设置sheetindex=0 $objphpexcel->setactivesheetindex(0); $objactsheet = $objphpexcel->getactivesheet(); //设置当前活动sheet的名称 //$objactsheet->settitle('测试sheet'); //************************************* //设置单元格内容 // //由phpexcel根据传入内容自动判断单元格内容类型 //$objactsheet->setcellvalue('a1', '字符串内容'); // 字符串内容 //$objactsheet->setcellvalue('a2', 26); // 数值 //$objactsheet->setcellvalue('a3', true); // 布尔值 //$objactsheet->setcellvalue('a4', '=sum(a2:a2)'); // 公式 //填入主标题 $objactsheet->setcellvalue('a1', '电子地图'); $objactsheet->mergecells('a1:ac1'); //设置表头行高 $objactsheet->getrowdimension(1)->setrowheight(20); $objactsheet->setcellvalue('a2', '序号'); $objactsheet->mergecells('a2:a4'); $objactsheet->setcellvalue('b2', '公司名称'); $objactsheet->mergecells('b2:b4'); $objactsheet->setcellvalue('c2', '简称'); $objactsheet->mergecells('c2:c4'); $objactsheet->setcellvalue('d2', '产品与技术'); $objactsheet->mergecells('d2:n2'); $objactsheet->setcellvalue('o2', '相关信息'); $objactsheet->mergecells('o2:s2'); $objactsheet->setcellvalue('t2', '联系信息'); $objactsheet->mergecells('t2:ab2'); $objactsheet->setcellvalue('ac2', '描述'); $objactsheet->mergecells('ac2:ac4'); $objactsheet->setcellvalue('d3', '领域'); $objactsheet->mergecells('d3:e3'); $objactsheet->setcellvalue('f3', '产品'); $objactsheet->mergecells('f3:n3'); $objactsheet->setcellvalue('o3', '技术'); $objactsheet->mergecells('o3:o4'); $objactsheet->setcellvalue('p3', '应用'); $objactsheet->mergecells('p3:p4'); $objactsheet->setcellvalue('q3', '性质'); $objactsheet->mergecells('q3:q4'); $objactsheet->setcellvalue('r3', '成立时间'); $objactsheet->mergecells('r3:r4'); $objactsheet->setcellvalue('s3', '员工数'); $objactsheet->mergecells('s3:s4'); $objactsheet->setcellvalue('t3', '地址'); $objactsheet->mergecells('t3:t4'); $objactsheet->setcellvalue('u3', '电话'); $objactsheet->mergecells('u3:u4'); $objactsheet->setcellvalue('v3', '传真'); $objactsheet->mergecells('v3:v4'); $objactsheet->setcellvalue('w3', 'email'); $objactsheet->mergecells('w3:w4'); $objactsheet->setcellvalue('x3', '网站'); $objactsheet->mergecells('x3:x4'); $objactsheet->setcellvalue('y3', '经度'); $objactsheet->mergecells('y3:y4'); $objactsheet->setcellvalue('z3', '纬度'); $objactsheet->mergecells('z3:z4'); $objactsheet->setcellvalue('aa3', '园区'); $objactsheet->mergecells('aa3:aa4'); $objactsheet->setcellvalue('ab3', '城市'); $objactsheet->mergecells('ab3:ab4'); $objactsheet->setcellvalue('d4', '一级'); $objactsheet->setcellvalue('e4', '二级'); $objactsheet->setcellvalue('f4', '1'); $objactsheet->setcellvalue('g4', '品名'); $objactsheet->setcellvalue('h4', '描述'); $objactsheet->setcellvalue('i4', '2'); $objactsheet->setcellvalue('j4', '品名'); $objactsheet->setcellvalue('k4', '描述'); $objactsheet->setcellvalue('l4', '3'); $objactsheet->setcellvalue('m4', '品名'); $objactsheet->setcellvalue('n4', '描述'); //************************************* //搜索条件 $company_where = 1; $keyword = trim($_get['keyword']); if($_get['sub_category'] || $_get['first_cid']){ $c_uid =getuidbycate(); } if($_get['product_id']){ $p_uid =getuidbypro($_get['product_id']); } $uid_arr = $p_uid?array_intersect($c_uid,$p_uid):$c_uid; $uid_str = implode(',',$uid_arr); if($_get['sub_category'] || $_get['first_cid'] || $_get['product_id']){ $company_where .= ' and uid in('.$uid_str.')'; } if($keyword){ $company_where .= and company like '%$keyword%'; } $num = 5; //初始行数 //公司信息 $company = $this->company->field('')->where($company_where)->select(); if($company){ foreach((array)$company as $k => $v){ if($v['uid']){ //获取产品 $pro = $this->product->table(tname('product').' as pr')->join(tname('company_product').' as cp on pr.id=cp.pid')->field('')->where('cp.uid='.$v['uid'])->group('pr.id')->select(); $company[$k]['pid'] = $pro; //获取二级分类 $join = tname('company_category').' as cc on ca.id=cc.cid'; $field = ''; $where = cc.uid=.$v['uid']; $cate = $this->category->table(tname('category').' as ca')->join($join)->field($field)->where($where)->group('ca.id')->select(); if($cate){ $cate_count = count($cate); $second_cate = ''; $first_cate_array = ''; foreach($cate as $k1=>$v1){ //获取一级分类 $first_cate = $this->category->where('id='.$v1['parentid'])->find(); //归总公司的一级分类 if(!in_array($first_cate,$first_cate_array)){ $first_cate_array[] = $first_cate; } //归类二级分类下的产品 foreach($pro as $pk => $pv){ if($pv['cid'] == $v1['cid']){ $cate[$k1]['pro'][] = $pv; } } } /**************************************************************************/// $second_count = 0;// //归总每个一级分类下的二级分类// foreach($first_cate_array as $fkey => $fvalue){// //一级目录起始行数// $stapos = $num+$second_count;// $en_stapos = $stapos+$cate_count;// $second_stapos = 0;// foreach($cate as $ck=>$cv){// if($cv['parentid'] == $fvalue['id']){// //二级目录起始行数// $stapos1 = $stapos+$second_stapos;// $en_stapos1 = $en_stapos+$second_stapos; // foreach($cv['pro'] as $spk => $spv){// $str1 = 70+$spk*3;// $str1 = chr($str1);// $str2 = 71+$spk*3;// $str2 = chr($str2);// $str3 = 72+$spk*3;// $str3 = chr($str3);// //中文// $collect = $spv['name'].'('.$spv['description'].')';// $objactsheet->setcellvalue($str1.$stapos1, $collect);// $objactsheet->setcellvalue($str2.$stapos1, $spv['name']);// $objactsheet->setcellvalue($str3.$stapos1, $spv['description']);// //英文// $en_collect = $spv['en_name'].'('.$spv['en_description'].')';// $objactsheet->setcellvalue($str1.$en_stapos1, $en_collect);// $objactsheet->setcellvalue($str2.$en_stapos1, $spv['en_name']);// $objactsheet->setcellvalue($str3.$en_stapos1, $spv['en_description']);// }// //中文// $objactsheet->setcellvalue('e'.$stapos1, $cv['category']);// //英文// $objactsheet->setcellvalue('e'.$en_stapos1, $cv['en_category']);// $second_stapos ++ ;// $second_count ++ ;// }// } // //中文// $objactsheet->setcellvalue('d'.$stapos, $fvalue['category']);// $stopos = $num + $second_count - 1;// $mergecellstr = 'd'.$stapos.':d'.$stopos;// $objactsheet->mergecells($mergecellstr);// //英文// $objactsheet->setcellvalue('d'.$en_stapos, $fvalue['en_category']);// $en_stopos = $num + $cate_count + $second_count - 1;// $en_mergecellstr = 'd'.$en_stapos.':d'.$en_stopos;// $objactsheet->mergecells($en_mergecellstr);// } /**************************************************************************/ //归总每个一级分类下的二级分类 foreach($first_cate_array as $fkey => $fvalue){ foreach($cate as $ck=>$cv){ if($cv['parentid'] == $fvalue['id']){ $first_cate_array[$fkey]['second_cate'][] = $cv; } } //获得每个一级分类下二级分类的数目 $second_count = count($first_cate_array[$fkey]['second_cate']); $first_cate_array[$fkey]['second_count'] = $second_count == 0 ? 1 : $second_count; } /*************************************************************************/ foreach($first_cate_array as $fk => $fv){ //一级目录起始行数 if($fk == 0){ $stapos = $num; $en_stapos = $stapos+$cate_count; }else{ $stapos = $stapos+$first_cate_array[$fk-1]['second_count']; $en_stapos = $stapos+$cate_count; } foreach($fv['second_cate'] as $sck => $scv){ //二级目录起始行数 $stapos1 = $stapos+$sck; $en_stapos1 = $en_stapos+$sck; foreach($scv['pro'] as $spk => $spv){ $str1 = 70+$spk*3; $str1 = chr($str1); $str2 = 71+$spk*3; $str2 = chr($str2); $str3 = 72+$spk*3; $str3 = chr($str3); //中文 $collect = $spv['name'].'('.$spv['description'].')'; $objactsheet->setcellvalue($str1.$stapos1, $collect); $objactsheet->setcellvalue($str2.$stapos1, $spv['name']); $objactsheet->setcellvalue($str3.$stapos1, $spv['description']); //英文 $en_collect = $spv['en_name'].'('.$spv['en_description'].')'; $objactsheet->setcellvalue($str1.$en_stapos1, $en_collect); $objactsheet->setcellvalue($str2.$en_stapos1, $spv['en_name']); $objactsheet->setcellvalue($str3.$en_stapos1, $spv['en_description']); } //中文 $objactsheet->setcellvalue('e'.$stapos1, $scv['category']); //英文 $objactsheet->setcellvalue('e'.$en_stapos1, $scv['en_category']); } //中文 $objactsheet->setcellvalue('d'.$stapos, $fv['category']); $stopos = $stapos + $fv['second_count'] - 1; $mergecellstr = 'd'.$stapos.':d'.$stopos; $objactsheet->mergecells($mergecellstr); //英文 $objactsheet->setcellvalue('d'.$en_stapos, $fv['en_category']); $en_stopos = $en_stapos + $fv['second_count'] - 1; $en_mergecellstr = 'd'.$en_stapos.':d'.$en_stopos; $objactsheet->mergecells($en_mergecellstr); } $company[$k]['first_cid'] = $first_cate_array; } //$company[$k]['first_count'] = count($company[$k]['first_cid']); //获得二级分类的总数目 $company[$k]['total_rows'] = count($cate); //园区 if($v['park']){ $park = my_explode($v['park']); $company[$k]['park'] = my_arrytostr(array_unique($park),'park','name'); $company[$k]['en_park'] = my_arrytostr(array_unique($park),'park','en_name'); }else{ $v['park'] = ''; $v['en_park'] = ''; } //城市 if($v['city']){ $city = c('city'); foreach($city as $ck=>$cv){ if($v['city'] == $cv['id']){ $v['city'] = $cv['name']; $v['en_city'] = $cv['en_name']; } } } $total_rows = $company[$k]['total_rows'] == 0 ? 1 : $company[$k]['total_rows']; //中文************************************* $stop = $num - 1 + $total_rows; $objactsheet->setcellvalue('a'.$num, $v['uid']); $objactsheet->mergecells('a'.$num.':a'.$stop); $objactsheet->setcellvalue('b'.$num, $v['company']); $objactsheet->mergecells('b'.$num.':b'.$stop); $objactsheet->setcellvalue('c'.$num, $v['com']); $objactsheet->mergecells('c'.$num.':c'.$stop);//// $objactsheet->setcellvalue('d'.$num, $v['com']);// $objactsheet->setcellvalue('e'.$num, $v['uid']);// $objactsheet->setcellvalue('f'.$num, $v['uid']);// $objactsheet->setcellvalue('g'.$num, $v['uid']);// $objactsheet->setcellvalue('h'.$num, $v['uid']);// $objactsheet->setcellvalue('i'.$num, $v['uid']);// $objactsheet->setcellvalue('j'.$num, $v['uid']);// $objactsheet->setcellvalue('k'.$num, $v['uid']);// $objactsheet->setcellvalue('l'.$num, $v['uid']);// $objactsheet->setcellvalue('m'.$num, $v['uid']);// $objactsheet->setcellvalue('n'.$num, $v['uid']);// $objactsheet->setcellvalue('o'.$num, $v['technology']); $objactsheet->mergecells('o'.$num.':o'.$stop); $objactsheet->setcellvalue('p'.$num, $v['application']); $objactsheet->mergecells('p'.$num.':p'.$stop); $objactsheet->setcellvalue('q'.$num, $v['nature']); $objactsheet->mergecells('q'.$num.':q'.$stop); $objactsheet->setcellvalue('r'.$num, $v['established']); $objactsheet->mergecells('r'.$num.':r'.$stop); $objactsheet->setcellvalue('s'.$num, $v['employees']); $objactsheet->mergecells('s'.$num.':s'.$stop); $objactsheet->setcellvalue('t'.$num, $v['address']); $objactsheet->mergecells('t'.$num.':t'.$stop); $objactsheet->setcellvalue('u'.$num, $v['phone']); $objactsheet->mergecells('u'.$num.':u'.$stop); $objactsheet->setcellvalue('v'.$num, $v['fax']); $objactsheet->mergecells('v'.$num.':v'.$stop); $objactsheet->setcellvalue('w'.$num, $v['email']); $objactsheet->mergecells('w'.$num.':w'.$stop); $objactsheet->setcellvalue('x'.$num, $v['website']); $objactsheet->mergecells('x'.$num.':x'.$stop); $objactsheet->setcellvalue('y'.$num, $v['longitude']); $objactsheet->mergecells('y'.$num.':y'.$stop); $objactsheet->setcellvalue('z'.$num, $v['latitude']); $objactsheet->mergecells('z'.$num.':z'.$stop); $objactsheet->setcellvalue('aa'.$num, $v['park']); $objactsheet->mergecells('aa'.$num.':aa'.$stop); $objactsheet->setcellvalue('ab'.$num, $v['city']); $objactsheet->mergecells('ab'.$num.':ab'.$stop); $objactsheet->setcellvalue('ac'.$num, $v['description']); $objactsheet->mergecells('ac'.$num.':ac'.$stop); //英文************************************* $en_start = $num + $total_rows; $en_stop = $en_start - 1 + $total_rows; $objactsheet->setcellvalue('a'.$en_start, $v['uid']); $objactsheet->mergecells('a'.$en_start.':a'.$en_stop); $objactsheet->setcellvalue('b'.$en_start, $v['en_company']); $objactsheet->mergecells('b'.$en_start.':b'.$en_stop); $objactsheet->setcellvalue('c'.$en_start, $v['en_com']); $objactsheet->mergecells('c'.$en_start.':c'.$en_stop);//// $objactsheet->setcellvalue('d'.$en_start, $v['com']);// $objactsheet->setcellvalue('e'.$en_start, $v['uid']);// $objactsheet->setcellvalue('f'.$en_start, $v['uid']);// $objactsheet->setcellvalue('g'.$en_start, $v['uid']);// $objactsheet->setcellvalue('h'.$en_start, $v['uid']);// $objactsheet->setcellvalue('i'.$en_start, $v['uid']);// $objactsheet->setcellvalue('j'.$en_start, $v['uid']);// $objactsheet->setcellvalue('k'.$en_start, $v['uid']);// $objactsheet->setcellvalue('l'.$en_start, $v['uid']);// $objactsheet->setcellvalue('m'.$en_start, $v['uid']);// $objactsheet->setcellvalue('n'.$en_start, $v['uid']);// $objactsheet->setcellvalue('o'.$en_start, $v['en_technology']); $objactsheet->mergecells('o'.$en_start.':o'.$en_stop); $objactsheet->setcellvalue('p'.$en_start, $v['en_application']); $objactsheet->mergecells('p'.$en_start.':p'.$en_stop); $objactsheet->setcellvalue('q'.$en_start, $v['en_nature']); $objactsheet->mergecells('q'.$en_start.':q'.$en_stop); $objactsheet->setcellvalue('r'.$en_start, $v['established']); $objactsheet->mergecells('r'.$en_start.':r'.$en_stop); $objactsheet->setcellvalue('s'.$en_start, $v['employees']); $objactsheet->mergecells('s'.$en_start.':s'.$en_stop); $objactsheet->setcellvalue('t'.$en_start, $v['en_address']); $objactsheet->mergecells('t'.$en_start.':t'.$en_stop); $objactsheet->setcellvalue('u'.$en_start, $v['phone']); $objactsheet->mergecells('u'.$en_start.':u'.$en_stop); $objactsheet->setcellvalue('v'.$en_start, $v['fax']); $objactsheet->mergecells('v'.$en_start.':v'.$en_stop); $objactsheet->setcellvalue('w'.$en_start, $v['email']); $objactsheet->mergecells('w'.$en_start.':w'.$en_stop); $objactsheet->setcellvalue('x'.$en_start, $v['website']); $objactsheet->mergecells('x'.$en_start.':x'.$en_stop); $objactsheet->setcellvalue('y'.$en_start, $v['longitude']); $objactsheet->mergecells('y'.$en_start.':y'.$en_stop); $objactsheet->setcellvalue('z'.$en_start, $v['latitude']); $objactsheet->mergecells('z'.$en_start.':z'.$en_stop); $objactsheet->setcellvalue('aa'.$en_start, $v['en_park']); $objactsheet->mergecells('aa'.$en_start.':aa'.$en_stop); $objactsheet->setcellvalue('ab'.$en_start, $v['en_city']); $objactsheet->mergecells('ab'.$en_start.':ab'.$en_stop); $objactsheet->setcellvalue('ac'.$en_start, $v['en_description']); $objactsheet->mergecells('ac'.$en_start.':ac'.$en_stop); $num += $company[$k]['total_rows'] * 2; //下一公司的起始行数 } } } //************************************* //设置单元格样式 // //设置主标题字体 $objstylea1 = $objactsheet->getstyle('a1'); $objfonta1 = $objstylea1->getfont(); $objfonta1->setname('宋体'); $objfonta1->setsize(14); //$objfonta1->setbold(false); //$objfonta1->setunderline(phpexcel_style_font::underline_single); //$objfonta1->getcolor()->setargb('ff999999'); //************************************* //设置表头字体 $objstylea2 = $objactsheet->getstyle('a2:ac4'); $objfonta2 = $objstylea2->getfont(); $objfonta2->setname('cambria'); $objfonta2->setsize(10); //设置填充颜色 $objfilla2 = $objstylea2->getfill(); $objfilla2->setfilltype(phpexcel_style_fill::fill_solid); $objfilla2->getstartcolor()->setargb('b7b7b7'); //从指定的单元格复制样式信息. //$objactsheet->duplicatestyle($objstylea2, 'a2:ac4'); //************************************* //设置表格字体 $objactsheet->getstyle('a1:ac'.($num-1))->getfont()->setname('cambria'); $objactsheet->getstyle('a1:ac'.($num-1))->getfont()->setsize(9); //显示网格线: $objactsheet->setshowgridlines(true); //设置自动换行 $objactsheet->getstyle('a1:ac'.($num-1))->getalignment()->setwraptext(true); //所有垂直居中 $objactsheet->getstyle('a1:ac'.($num-1))->getalignment()->setvertical(phpexcel_style_alignment::vertical_center); //前4行水平居中 $objactsheet->getstyle('a1:ac4')->getalignment()->sethorizontal(phpexcel_style_alignment::horizontal_center); //后面水平左对齐 $objactsheet->getstyle('a5:ac'.($num-1))->getalignment()->sethorizontal(phpexcel_style_alignment::horizontal_left); //设置单元格边框 $objactsheet->getstyle('a1:ac'.($num-1))->getborders()->getallborders()->setborderstyle(phpexcel_style_border::border_thin); $objactsheet->getstyle('a1:ac'.($num-1))->getborders()->getallborders()->getcolor()->setargb('000000'); //************************************* //输出内容 //下面的路径按照你phpexcel的路径来修改 // $outputfilename = output.xlsx; //$outputfilename = output.xls; //到文件 //$objwriter->save($outputfilename); //or //到浏览器 header(content-type: application/force-download); header(content-type: application/octet-stream); header(content-type: application/download); header('content-disposition:inline;filename='.$outputfilename.''); header(content-transfer-encoding: binary); header(expires: mon, 26 jul 1997 05:00:00 gmt); header(last-modified: . gmdate(d, d m y h:i:s) . gmt); header(cache-control: must-revalidate, post-check=0, pre-check=0); header(pragma: no-cache); $objwriter->save('php://output'); }
回复内容: 做php导出,需要循环输出数据到execl中,一开始写了一个,觉得时间有点长,就缩短了下,发现时间还变多了,求教这是为什么啊?谢谢了先。
原先的代码片段:
//归总每个一级分类下的二级分类foreach($first_cate_array as $fkey => $fvalue){ foreach($cate as $ck=>$cv){ if($cv['parentid'] == $fvalue['id']){ $first_cate_array[$fkey]['second_cate'][] = $cv; } } //获得每个一级分类下二级分类的数目 $second_count = count($first_cate_array[$fkey]['second_cate']); $first_cate_array[$fkey]['second_count'] = $second_count == 0 ? 1 : $second_count; }/*************************************************************************/foreach($first_cate_array as $fk => $fv){ //一级目录起始行数 if($fk == 0){ $stapos = $num; $en_stapos = $stapos+$cate_count; }else{ $stapos = $stapos+$first_cate_array[$fk-1]['second_count']; $en_stapos = $stapos+$cate_count; } foreach($fv['second_cate'] as $sck => $scv){ //二级目录起始行数 $stapos1 = $stapos+$sck; $en_stapos1 = $en_stapos+$sck; foreach($scv['pro'] as $spk => $spv){ $str1 = 70+$spk*3; $str1 = chr($str1); $str2 = 71+$spk*3; $str2 = chr($str2); $str3 = 72+$spk*3; $str3 = chr($str3); //中文 $collect = $spv['name'].'('.$spv['description'].')'; $objactsheet->setcellvalue($str1.$stapos1, $collect); $objactsheet->setcellvalue($str2.$stapos1, $spv['name']); $objactsheet->setcellvalue($str3.$stapos1, $spv['description']); //英文 $en_collect = $spv['en_name'].'('.$spv['en_description'].')'; $objactsheet->setcellvalue($str1.$en_stapos1, $en_collect); $objactsheet->setcellvalue($str2.$en_stapos1, $spv['en_name']); $objactsheet->setcellvalue($str3.$en_stapos1, $spv['en_description']); } //中文 $objactsheet->setcellvalue('e'.$stapos1, $scv['category']); //英文 $objactsheet->setcellvalue('e'.$en_stapos1, $scv['en_category']); } //中文 $objactsheet->setcellvalue('d'.$stapos, $fv['category']); $stopos = $stapos + $fv['second_count'] - 1; $mergecellstr = 'd'.$stapos.':d'.$stopos; $objactsheet->mergecells($mergecellstr); //英文 $objactsheet->setcellvalue('d'.$en_stapos, $fv['en_category']); $en_stopos = $en_stapos + $fv['second_count'] - 1; $en_mergecellstr = 'd'.$en_stapos.':d'.$en_stopos; $objactsheet->mergecells($en_mergecellstr);}

修改以后的片段:
$second_count = 0;//归总每个一级分类下的二级分类foreach($first_cate_array as $fkey => $fvalue){ //一级目录起始行数 $stapos = $num+$second_count; $en_stapos = $stapos+$cate_count; $second_stapos = 0; foreach($cate as $ck=>$cv){ if($cv['parentid'] == $fvalue['id']){ //二级目录起始行数 $stapos1 = $stapos+$second_stapos; $en_stapos1 = $en_stapos+$second_stapos; foreach($cv['pro'] as $spk => $spv){ $str1 = 70+$spk*3; $str1 = chr($str1); $str2 = 71+$spk*3; $str2 = chr($str2); $str3 = 72+$spk*3; $str3 = chr($str3); //中文 $collect = $spv['name'].'('.$spv['description'].')'; $objactsheet->setcellvalue($str1.$stapos1, $collect); $objactsheet->setcellvalue($str2.$stapos1, $spv['name']); $objactsheet->setcellvalue($str3.$stapos1, $spv['description']); //英文 $en_collect = $spv['en_name'].'('.$spv['en_description'].')'; $objactsheet->setcellvalue($str1.$en_stapos1, $en_collect); $objactsheet->setcellvalue($str2.$en_stapos1, $spv['en_name']); $objactsheet->setcellvalue($str3.$en_stapos1, $spv['en_description']); } //中文 $objactsheet->setcellvalue('e'.$stapos1, $cv['category']); //英文 $objactsheet->setcellvalue('e'.$en_stapos1, $cv['en_category']); $second_stapos ++ ; $second_count ++ ; } } //中文 $objactsheet->setcellvalue('d'.$stapos, $fvalue['category']); $stopos = $num + $second_count - 1; $mergecellstr = 'd'.$stapos.':d'.$stopos; $objactsheet->mergecells($mergecellstr); //英文 $objactsheet->setcellvalue('d'.$en_stapos, $fvalue['en_category']); $en_stopos = $num + $cate_count + $second_count - 1; $en_mergecellstr = 'd'.$en_stapos.':d'.$en_stopos; $objactsheet->mergecells($en_mergecellstr);}

我觉得原先的代码多一个上面的循环,时间应该多一点。。。查询1700条数据耗时84s。。。下面附上全文代码:
/** * 导出execl */ public function export(){ import(@.org.phpexcel); //import(lib.org.phpexcel.iofactory,app_path,.php); import(lib.org.phpexcel.writer.excel5,app_path,.php); import(lib.org.phpexcel.writer.excel2007,app_path,.php); // 创建一个处理对象实例 $objphpexcel = new phpexcel(); // 创建文件格式写入对象实例, uncomment //$objwriter = new phpexcel_writer_excel5($objphpexcel); // 用于其他版本格式 // or $objwriter = new phpexcel_writer_excel2007($objphpexcel); // 用于 2007 格式 //$objwriter->setoffice2003compatibility(true); //************************************* //设置文档基本属性 // $objprops = $objphpexcel->getproperties(); // $objprops->setcreator(test); //创建人// $objprops->setlastmodifiedby(test); //最后修改人// $objprops->settitle(office xls test document); //标题// $objprops->setsubject(office xls test document, demo); //题目// $objprops->setdescription(test document, generated by phpexcel.); //描述// $objprops->setkeywords(office excel phpexcel); //关键字// $objprops->setcategory(test); //种类 //************************************* //设置当前的sheet索引,用于后续的内容操作。 //一般只有在使用多个sheet的时候才需要显示调用。 //缺省情况下,phpexcel会自动创建第一个sheet被设置sheetindex=0 $objphpexcel->setactivesheetindex(0); $objactsheet = $objphpexcel->getactivesheet(); //设置当前活动sheet的名称 //$objactsheet->settitle('测试sheet'); //************************************* //设置单元格内容 // //由phpexcel根据传入内容自动判断单元格内容类型 //$objactsheet->setcellvalue('a1', '字符串内容'); // 字符串内容 //$objactsheet->setcellvalue('a2', 26); // 数值 //$objactsheet->setcellvalue('a3', true); // 布尔值 //$objactsheet->setcellvalue('a4', '=sum(a2:a2)'); // 公式 //填入主标题 $objactsheet->setcellvalue('a1', '电子地图'); $objactsheet->mergecells('a1:ac1'); //设置表头行高 $objactsheet->getrowdimension(1)->setrowheight(20); $objactsheet->setcellvalue('a2', '序号'); $objactsheet->mergecells('a2:a4'); $objactsheet->setcellvalue('b2', '公司名称'); $objactsheet->mergecells('b2:b4'); $objactsheet->setcellvalue('c2', '简称'); $objactsheet->mergecells('c2:c4'); $objactsheet->setcellvalue('d2', '产品与技术'); $objactsheet->mergecells('d2:n2'); $objactsheet->setcellvalue('o2', '相关信息'); $objactsheet->mergecells('o2:s2'); $objactsheet->setcellvalue('t2', '联系信息'); $objactsheet->mergecells('t2:ab2'); $objactsheet->setcellvalue('ac2', '描述'); $objactsheet->mergecells('ac2:ac4'); $objactsheet->setcellvalue('d3', '领域'); $objactsheet->mergecells('d3:e3'); $objactsheet->setcellvalue('f3', '产品'); $objactsheet->mergecells('f3:n3'); $objactsheet->setcellvalue('o3', '技术'); $objactsheet->mergecells('o3:o4'); $objactsheet->setcellvalue('p3', '应用'); $objactsheet->mergecells('p3:p4'); $objactsheet->setcellvalue('q3', '性质'); $objactsheet->mergecells('q3:q4'); $objactsheet->setcellvalue('r3', '成立时间'); $objactsheet->mergecells('r3:r4'); $objactsheet->setcellvalue('s3', '员工数'); $objactsheet->mergecells('s3:s4'); $objactsheet->setcellvalue('t3', '地址'); $objactsheet->mergecells('t3:t4'); $objactsheet->setcellvalue('u3', '电话'); $objactsheet->mergecells('u3:u4'); $objactsheet->setcellvalue('v3', '传真'); $objactsheet->mergecells('v3:v4'); $objactsheet->setcellvalue('w3', 'email'); $objactsheet->mergecells('w3:w4'); $objactsheet->setcellvalue('x3', '网站'); $objactsheet->mergecells('x3:x4'); $objactsheet->setcellvalue('y3', '经度'); $objactsheet->mergecells('y3:y4'); $objactsheet->setcellvalue('z3', '纬度'); $objactsheet->mergecells('z3:z4'); $objactsheet->setcellvalue('aa3', '园区'); $objactsheet->mergecells('aa3:aa4'); $objactsheet->setcellvalue('ab3', '城市'); $objactsheet->mergecells('ab3:ab4'); $objactsheet->setcellvalue('d4', '一级'); $objactsheet->setcellvalue('e4', '二级'); $objactsheet->setcellvalue('f4', '1'); $objactsheet->setcellvalue('g4', '品名'); $objactsheet->setcellvalue('h4', '描述'); $objactsheet->setcellvalue('i4', '2'); $objactsheet->setcellvalue('j4', '品名'); $objactsheet->setcellvalue('k4', '描述'); $objactsheet->setcellvalue('l4', '3'); $objactsheet->setcellvalue('m4', '品名'); $objactsheet->setcellvalue('n4', '描述'); //************************************* //搜索条件 $company_where = 1; $keyword = trim($_get['keyword']); if($_get['sub_category'] || $_get['first_cid']){ $c_uid =getuidbycate(); } if($_get['product_id']){ $p_uid =getuidbypro($_get['product_id']); } $uid_arr = $p_uid?array_intersect($c_uid,$p_uid):$c_uid; $uid_str = implode(',',$uid_arr); if($_get['sub_category'] || $_get['first_cid'] || $_get['product_id']){ $company_where .= ' and uid in('.$uid_str.')'; } if($keyword){ $company_where .= and company like '%$keyword%'; } $num = 5; //初始行数 //公司信息 $company = $this->company->field('')->where($company_where)->select(); if($company){ foreach((array)$company as $k => $v){ if($v['uid']){ //获取产品 $pro = $this->product->table(tname('product').' as pr')->join(tname('company_product').' as cp on pr.id=cp.pid')->field('')->where('cp.uid='.$v['uid'])->group('pr.id')->select(); $company[$k]['pid'] = $pro; //获取二级分类 $join = tname('company_category').' as cc on ca.id=cc.cid'; $field = ''; $where = cc.uid=.$v['uid']; $cate = $this->category->table(tname('category').' as ca')->join($join)->field($field)->where($where)->group('ca.id')->select(); if($cate){ $cate_count = count($cate); $second_cate = ''; $first_cate_array = ''; foreach($cate as $k1=>$v1){ //获取一级分类 $first_cate = $this->category->where('id='.$v1['parentid'])->find(); //归总公司的一级分类 if(!in_array($first_cate,$first_cate_array)){ $first_cate_array[] = $first_cate; } //归类二级分类下的产品 foreach($pro as $pk => $pv){ if($pv['cid'] == $v1['cid']){ $cate[$k1]['pro'][] = $pv; } } } /**************************************************************************/// $second_count = 0;// //归总每个一级分类下的二级分类// foreach($first_cate_array as $fkey => $fvalue){// //一级目录起始行数// $stapos = $num+$second_count;// $en_stapos = $stapos+$cate_count;// $second_stapos = 0;// foreach($cate as $ck=>$cv){// if($cv['parentid'] == $fvalue['id']){// //二级目录起始行数// $stapos1 = $stapos+$second_stapos;// $en_stapos1 = $en_stapos+$second_stapos; // foreach($cv['pro'] as $spk => $spv){// $str1 = 70+$spk*3;// $str1 = chr($str1);// $str2 = 71+$spk*3;// $str2 = chr($str2);// $str3 = 72+$spk*3;// $str3 = chr($str3);// //中文// $collect = $spv['name'].'('.$spv['description'].')';// $objactsheet->setcellvalue($str1.$stapos1, $collect);// $objactsheet->setcellvalue($str2.$stapos1, $spv['name']);// $objactsheet->setcellvalue($str3.$stapos1, $spv['description']);// //英文// $en_collect = $spv['en_name'].'('.$spv['en_description'].')';// $objactsheet->setcellvalue($str1.$en_stapos1, $en_collect);// $objactsheet->setcellvalue($str2.$en_stapos1, $spv['en_name']);// $objactsheet->setcellvalue($str3.$en_stapos1, $spv['en_description']);// }// //中文// $objactsheet->setcellvalue('e'.$stapos1, $cv['category']);// //英文// $objactsheet->setcellvalue('e'.$en_stapos1, $cv['en_category']);// $second_stapos ++ ;// $second_count ++ ;// }// } // //中文// $objactsheet->setcellvalue('d'.$stapos, $fvalue['category']);// $stopos = $num + $second_count - 1;// $mergecellstr = 'd'.$stapos.':d'.$stopos;// $objactsheet->mergecells($mergecellstr);// //英文// $objactsheet->setcellvalue('d'.$en_stapos, $fvalue['en_category']);// $en_stopos = $num + $cate_count + $second_count - 1;// $en_mergecellstr = 'd'.$en_stapos.':d'.$en_stopos;// $objactsheet->mergecells($en_mergecellstr);// } /**************************************************************************/ //归总每个一级分类下的二级分类 foreach($first_cate_array as $fkey => $fvalue){ foreach($cate as $ck=>$cv){ if($cv['parentid'] == $fvalue['id']){ $first_cate_array[$fkey]['second_cate'][] = $cv; } } //获得每个一级分类下二级分类的数目 $second_count = count($first_cate_array[$fkey]['second_cate']); $first_cate_array[$fkey]['second_count'] = $second_count == 0 ? 1 : $second_count; } /*************************************************************************/ foreach($first_cate_array as $fk => $fv){ //一级目录起始行数 if($fk == 0){ $stapos = $num; $en_stapos = $stapos+$cate_count; }else{ $stapos = $stapos+$first_cate_array[$fk-1]['second_count']; $en_stapos = $stapos+$cate_count; } foreach($fv['second_cate'] as $sck => $scv){ //二级目录起始行数 $stapos1 = $stapos+$sck; $en_stapos1 = $en_stapos+$sck; foreach($scv['pro'] as $spk => $spv){ $str1 = 70+$spk*3; $str1 = chr($str1); $str2 = 71+$spk*3; $str2 = chr($str2); $str3 = 72+$spk*3; $str3 = chr($str3); //中文 $collect = $spv['name'].'('.$spv['description'].')'; $objactsheet->setcellvalue($str1.$stapos1, $collect); $objactsheet->setcellvalue($str2.$stapos1, $spv['name']); $objactsheet->setcellvalue($str3.$stapos1, $spv['description']); //英文 $en_collect = $spv['en_name'].'('.$spv['en_description'].')'; $objactsheet->setcellvalue($str1.$en_stapos1, $en_collect); $objactsheet->setcellvalue($str2.$en_stapos1, $spv['en_name']); $objactsheet->setcellvalue($str3.$en_stapos1, $spv['en_description']); } //中文 $objactsheet->setcellvalue('e'.$stapos1, $scv['category']); //英文 $objactsheet->setcellvalue('e'.$en_stapos1, $scv['en_category']); } //中文 $objactsheet->setcellvalue('d'.$stapos, $fv['category']); $stopos = $stapos + $fv['second_count'] - 1; $mergecellstr = 'd'.$stapos.':d'.$stopos; $objactsheet->mergecells($mergecellstr); //英文 $objactsheet->setcellvalue('d'.$en_stapos, $fv['en_category']); $en_stopos = $en_stapos + $fv['second_count'] - 1; $en_mergecellstr = 'd'.$en_stapos.':d'.$en_stopos; $objactsheet->mergecells($en_mergecellstr); } $company[$k]['first_cid'] = $first_cate_array; } //$company[$k]['first_count'] = count($company[$k]['first_cid']); //获得二级分类的总数目 $company[$k]['total_rows'] = count($cate); //园区 if($v['park']){ $park = my_explode($v['park']); $company[$k]['park'] = my_arrytostr(array_unique($park),'park','name'); $company[$k]['en_park'] = my_arrytostr(array_unique($park),'park','en_name'); }else{ $v['park'] = ''; $v['en_park'] = ''; } //城市 if($v['city']){ $city = c('city'); foreach($city as $ck=>$cv){ if($v['city'] == $cv['id']){ $v['city'] = $cv['name']; $v['en_city'] = $cv['en_name']; } } } $total_rows = $company[$k]['total_rows'] == 0 ? 1 : $company[$k]['total_rows']; //中文************************************* $stop = $num - 1 + $total_rows; $objactsheet->setcellvalue('a'.$num, $v['uid']); $objactsheet->mergecells('a'.$num.':a'.$stop); $objactsheet->setcellvalue('b'.$num, $v['company']); $objactsheet->mergecells('b'.$num.':b'.$stop); $objactsheet->setcellvalue('c'.$num, $v['com']); $objactsheet->mergecells('c'.$num.':c'.$stop);//// $objactsheet->setcellvalue('d'.$num, $v['com']);// $objactsheet->setcellvalue('e'.$num, $v['uid']);// $objactsheet->setcellvalue('f'.$num, $v['uid']);// $objactsheet->setcellvalue('g'.$num, $v['uid']);// $objactsheet->setcellvalue('h'.$num, $v['uid']);// $objactsheet->setcellvalue('i'.$num, $v['uid']);// $objactsheet->setcellvalue('j'.$num, $v['uid']);// $objactsheet->setcellvalue('k'.$num, $v['uid']);// $objactsheet->setcellvalue('l'.$num, $v['uid']);// $objactsheet->setcellvalue('m'.$num, $v['uid']);// $objactsheet->setcellvalue('n'.$num, $v['uid']);// $objactsheet->setcellvalue('o'.$num, $v['technology']); $objactsheet->mergecells('o'.$num.':o'.$stop); $objactsheet->setcellvalue('p'.$num, $v['application']); $objactsheet->mergecells('p'.$num.':p'.$stop); $objactsheet->setcellvalue('q'.$num, $v['nature']); $objactsheet->mergecells('q'.$num.':q'.$stop); $objactsheet->setcellvalue('r'.$num, $v['established']); $objactsheet->mergecells('r'.$num.':r'.$stop); $objactsheet->setcellvalue('s'.$num, $v['employees']); $objactsheet->mergecells('s'.$num.':s'.$stop); $objactsheet->setcellvalue('t'.$num, $v['address']); $objactsheet->mergecells('t'.$num.':t'.$stop); $objactsheet->setcellvalue('u'.$num, $v['phone']); $objactsheet->mergecells('u'.$num.':u'.$stop); $objactsheet->setcellvalue('v'.$num, $v['fax']); $objactsheet->mergecells('v'.$num.':v'.$stop); $objactsheet->setcellvalue('w'.$num, $v['email']); $objactsheet->mergecells('w'.$num.':w'.$stop); $objactsheet->setcellvalue('x'.$num, $v['website']); $objactsheet->mergecells('x'.$num.':x'.$stop); $objactsheet->setcellvalue('y'.$num, $v['longitude']); $objactsheet->mergecells('y'.$num.':y'.$stop); $objactsheet->setcellvalue('z'.$num, $v['latitude']); $objactsheet->mergecells('z'.$num.':z'.$stop); $objactsheet->setcellvalue('aa'.$num, $v['park']); $objactsheet->mergecells('aa'.$num.':aa'.$stop); $objactsheet->setcellvalue('ab'.$num, $v['city']); $objactsheet->mergecells('ab'.$num.':ab'.$stop); $objactsheet->setcellvalue('ac'.$num, $v['description']); $objactsheet->mergecells('ac'.$num.':ac'.$stop); //英文************************************* $en_start = $num + $total_rows; $en_stop = $en_start - 1 + $total_rows; $objactsheet->setcellvalue('a'.$en_start, $v['uid']); $objactsheet->mergecells('a'.$en_start.':a'.$en_stop); $objactsheet->setcellvalue('b'.$en_start, $v['en_company']); $objactsheet->mergecells('b'.$en_start.':b'.$en_stop); $objactsheet->setcellvalue('c'.$en_start, $v['en_com']); $objactsheet->mergecells('c'.$en_start.':c'.$en_stop);//// $objactsheet->setcellvalue('d'.$en_start, $v['com']);// $objactsheet->setcellvalue('e'.$en_start, $v['uid']);// $objactsheet->setcellvalue('f'.$en_start, $v['uid']);// $objactsheet->setcellvalue('g'.$en_start, $v['uid']);// $objactsheet->setcellvalue('h'.$en_start, $v['uid']);// $objactsheet->setcellvalue('i'.$en_start, $v['uid']);// $objactsheet->setcellvalue('j'.$en_start, $v['uid']);// $objactsheet->setcellvalue('k'.$en_start, $v['uid']);// $objactsheet->setcellvalue('l'.$en_start, $v['uid']);// $objactsheet->setcellvalue('m'.$en_start, $v['uid']);// $objactsheet->setcellvalue('n'.$en_start, $v['uid']);// $objactsheet->setcellvalue('o'.$en_start, $v['en_technology']); $objactsheet->mergecells('o'.$en_start.':o'.$en_stop); $objactsheet->setcellvalue('p'.$en_start, $v['en_application']); $objactsheet->mergecells('p'.$en_start.':p'.$en_stop); $objactsheet->setcellvalue('q'.$en_start, $v['en_nature']); $objactsheet->mergecells('q'.$en_start.':q'.$en_stop); $objactsheet->setcellvalue('r'.$en_start, $v['established']); $objactsheet->mergecells('r'.$en_start.':r'.$en_stop); $objactsheet->setcellvalue('s'.$en_start, $v['employees']); $objactsheet->mergecells('s'.$en_start.':s'.$en_stop); $objactsheet->setcellvalue('t'.$en_start, $v['en_address']); $objactsheet->mergecells('t'.$en_start.':t'.$en_stop); $objactsheet->setcellvalue('u'.$en_start, $v['phone']); $objactsheet->mergecells('u'.$en_start.':u'.$en_stop); $objactsheet->setcellvalue('v'.$en_start, $v['fax']); $objactsheet->mergecells('v'.$en_start.':v'.$en_stop); $objactsheet->setcellvalue('w'.$en_start, $v['email']); $objactsheet->mergecells('w'.$en_start.':w'.$en_stop); $objactsheet->setcellvalue('x'.$en_start, $v['website']); $objactsheet->mergecells('x'.$en_start.':x'.$en_stop); $objactsheet->setcellvalue('y'.$en_start, $v['longitude']); $objactsheet->mergecells('y'.$en_start.':y'.$en_stop); $objactsheet->setcellvalue('z'.$en_start, $v['latitude']); $objactsheet->mergecells('z'.$en_start.':z'.$en_stop); $objactsheet->setcellvalue('aa'.$en_start, $v['en_park']); $objactsheet->mergecells('aa'.$en_start.':aa'.$en_stop); $objactsheet->setcellvalue('ab'.$en_start, $v['en_city']); $objactsheet->mergecells('ab'.$en_start.':ab'.$en_stop); $objactsheet->setcellvalue('ac'.$en_start, $v['en_description']); $objactsheet->mergecells('ac'.$en_start.':ac'.$en_stop); $num += $company[$k]['total_rows'] * 2; //下一公司的起始行数 } } } //************************************* //设置单元格样式 // //设置主标题字体 $objstylea1 = $objactsheet->getstyle('a1'); $objfonta1 = $objstylea1->getfont(); $objfonta1->setname('宋体'); $objfonta1->setsize(14); //$objfonta1->setbold(false); //$objfonta1->setunderline(phpexcel_style_font::underline_single); //$objfonta1->getcolor()->setargb('ff999999'); //************************************* //设置表头字体 $objstylea2 = $objactsheet->getstyle('a2:ac4'); $objfonta2 = $objstylea2->getfont(); $objfonta2->setname('cambria'); $objfonta2->setsize(10); //设置填充颜色 $objfilla2 = $objstylea2->getfill(); $objfilla2->setfilltype(phpexcel_style_fill::fill_solid); $objfilla2->getstartcolor()->setargb('b7b7b7'); //从指定的单元格复制样式信息. //$objactsheet->duplicatestyle($objstylea2, 'a2:ac4'); //************************************* //设置表格字体 $objactsheet->getstyle('a1:ac'.($num
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product