browserExport('07', $this->file_name . '.xls'); $objWrite->save('php://output'); } //head头 private function browserExport($type, $fileName) { if ($type == '05') { //输出xls文件 header('Content-Type: application/vnd.ms-excel'); } else { //输出xlsx文件 header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); } header('Content-Disposition: attachment;filename="' . $fileName . '"'); header('Cache-Control: max-age=0');//禁止缓存 } //设置自动宽度,中文支持的不好,基本不能用 public function setAutoSize($range) { foreach ($range as $columnID) { $this->getActiveSheet()->getColumnDimension($columnID) ->setAutoSize(true); } } //手动设置宽度 一个中文对应3 “出车日期” 4*3 12 public function setColumnSize($range, $width) { foreach ($range as $key => $columnID) { $this->getActiveSheet()->getColumnDimension($columnID) ->setWidth($width[$key]); } } }