您好,欢迎访问一九零五行业门户网

excel导出时列超过26时解决办法

excel导出时列超过26时解决办法
/**
     * 导出数据方法
     * @author 杭州仟奇信息技术有限公司
     */
    protected  function getexcel($filename,$headarr,$data){
//导入phpexcel类库,因为phpexcel没有用命名空间,只能inport导入
        import(org.util.phpexcel);
        import(org.util.phpexcel.writer.excel5);
        import(org.util.phpexcel.iofactory.php);
$date = date(y_m_d,time());
        $filename .= _{$date}.xls;
//创建phpexcel对象,注意,不能少了\
        $objphpexcel = new \phpexcel();
        $objprops = $objphpexcel->getproperties();
        //设置表头
        $key = 0;
        //print_r($headarr);exit;
        foreach($headarr as $v){
            //注意,不能少了。将列数字转换为字母\
            $colum = \phpexcel_cell::stringfromcolumnindex($key);
            $objphpexcel->setactivesheetindex(0) ->setcellvalue($colum.'1', $v);
            $key += 1;
        }
        $column = 2;
        $objactsheet = $objphpexcel->getactivesheet();
foreach($data as $key => $rows){ //行写入
            $span = 0;
            foreach($rows as $keyname=>$value){// 列写入
                $j = \phpexcel_cell::stringfromcolumnindex($span);
                $objactsheet->setcellvalue($j.$column, $value);
                $span++;
            }
            $column++;
        }
$filename = iconv(utf-8, gb2312, $filename);
        //重命名表
        $objphpexcel->getactivesheet()->settitle($date);
        //设置字体大小
        $objphpexcel->getdefaultstyle()->getfont()->setsize(14);
        //设置单元格宽度
        $objphpexcel->getactivesheet()->getcolumndimension('a')->setwidth(15);
        //设置默认行高
        $objphpexcel->getactivesheet()->getdefaultrowdimension()->setrowheight(23);
        //设置活动单指数到第一个表,所以excel打开这是第一个表
        $objphpexcel->setactivesheetindex(0);
        header('content-type: application/vnd.ms-excel');
        header(content-disposition: attachment;filename=\$filename\);
        header('cache-control: max-age=0');
$objwriter = \phpexcel_iofactory::createwriter($objphpexcel, 'excel5');
        $objwriter->save('php://output'); //文件通过浏览器下载
        exit;
    }
ad:真正免费,域名+虚机+企业邮箱=0元
其它类似信息

推荐信息