时间:2021-07-01 10:21:17 帮助过:44人阅读
public function outxls() { $model = D($this->dbname); $map = $this->_search(); if (method_exists($this, '_filter')) { $this->_filter($map); } $list = $model->where($map)->field('id,status,yewujindu,fenlei,uid,juid,juname,uuid,uuname,xcrq,xingming,phone,type,introduce,introphone,daikuanpro,addtime,uname,addm,updatetime,sex,birth,marry,shenhu,shebaonianshu,shebaojishu,baoxianjiaoe')->select(); $headArr=array('ID','进展','公司名称','下次联系','联系人','添加人','添加时间','更新时间'); $filename='客户管理'; $this->xlsout($filename,$headArr,$list); }
Invalid cell coordinate 无效的单元格坐标
把你的 xlsout 方法贴出了看看!
关键是列号生成的部分
Invalid cell coordinate 无效的单元格坐标
把你的 xlsout 方法贴出了看看!
关键是列号生成的部分
public function xlsout($filename='数据表',$headArr,$list){ //导入PHPExcel类库,因为PHPExcel没有用命名空间,只能inport导入 import("Org.Util.PHPExcel"); import("Org.Util.PHPExcel.Writer.Excel5"); import("Org.Util.PHPExcel.IOFactory.php"); $this->getExcel($filename,$headArr,$list); }public function getExcel($fileName,$headArr,$data){ //对数据进行检验 if(empty($data) || !is_array($data)){ die("data must be a array"); } //检查文件名 if(empty($fileName)){ exit; } $date = date("Y_m_d",time()); $fileName .= "_{$date}.xls"; //创建PHPExcel对象,注意,不能少了\ $objPHPExcel = new \PHPExcel(); $objProps = $objPHPExcel->getProperties(); //设置表头 $key = ord("A"); foreach($headArr as $v){ $colum = chr($key); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum.'1', $v); $key += 1; } $column = 2; $objActSheet = $objPHPExcel->getActiveSheet(); //设置为文本格式 foreach($data as $key => $rows){ //行写入 $span = ord("A"); foreach($rows as $keyName=>$value){// 列写入 $j = chr($span); $objActSheet->setCellValueExplicit($j.$column, $value); $span++; } $column++; } $fileName = iconv("utf-8", "gb2312", $fileName); //重命名表 // $objPHPExcel->getActiveSheet()->setTitle('test'); //设置活动单指数到第一个表,所以Excel打开这是第一个表 $objPHPExcel->setActiveSheetIndex(0); ob_end_clean();//清除缓冲区,避免乱码 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; }
$span = ord("A"); foreach($rows as $keyName=>$value){// 列写入 $j = chr($span); $objActSheet->setCellValueExplicit($j.$column, $value); $span++; }
function CellName($n) { $r = ''; do { $m = $n % 26; $n = intval($n / 26); $r = chr(65 + $m - ($r ? 1 : 0)) . $r; }while($n > 0); return $r;}
$c = 'A';for($i=0; $i<100; $i++) printf("%s %s\n", $i, $c++);
$span = "A"; foreach($rows as $keyName=>$value){// 列写入 $j = $span; $objActSheet->setCellValueExplicit($j.$column, $value); $span++; }
$span = ord("A"); foreach($rows as $keyName=>$value){// 列写入 $j = chr($span); $objActSheet->setCellValueExplicit($j.$column, $value); $span++; }
function CellName($n) { $r = ''; do { $m = $n % 26; $n = intval($n / 26); $r = chr(65 + $m - ($r ? 1 : 0)) . $r; }while($n > 0); return $r;}
$c = 'A';for($i=0; $i<100; $i++) printf("%s %s\n", $i, $c++);
$span = "A"; foreach($rows as $keyName=>$value){// 列写入 $j = $span; $objActSheet->setCellValueExplicit($j.$column, $value); $span++; }