From ed3f9c7aab6fe9c574b12066c17b10fff1db017c Mon Sep 17 00:00:00 2001 From: devil_gong Date: Mon, 21 Jan 2019 12:24:50 +0800 Subject: [PATCH] =?UTF-8?q?excel=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/lang/zh-cn.php | 12 +----------- extend/base/Excel.php | 12 +++++++++--- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/application/admin/lang/zh-cn.php b/application/admin/lang/zh-cn.php index 7c4bbee45..53fb9fa92 100755 --- a/application/admin/lang/zh-cn.php +++ b/application/admin/lang/zh-cn.php @@ -108,52 +108,42 @@ return array( // 用户excel导出标题列表 'excel_user_title_list' => array( 'username' => array( - 'col' => 'A', - 'name' => '姓名', + 'name' => '用户名', 'type' => 'string', ), 'nickname' => array( - 'col' => 'B', 'name' => '昵称', 'type' => 'int', ), 'gender_text' => array( - 'col' => 'C', 'name' => '性别', 'type' => 'string', ), 'birthday_text'=> array( - 'col' => 'D', 'name' => '生日', 'type' => 'string', ), 'mobile' => array( - 'col' => 'E', 'name' => '手机号码', 'type' => 'int', ), 'email' => array( - 'col' => 'F', 'name' => '电子邮箱', 'type' => 'string', ), 'province' => array( - 'col' => 'G', 'name' => '所在省', 'type' => 'string', ), 'city' => array( - 'col' => 'H', 'name' => '所在市', 'type' => 'string', ), 'address' => array( - 'col' => 'I', 'name' => '详细地址', 'type' => 'string', ), 'add_time' => array( - 'col' => 'J', 'name' => '注册时间', 'type' => 'string', ), diff --git a/extend/base/Excel.php b/extend/base/Excel.php index 8a285c0e9..84b14bd62 100755 --- a/extend/base/Excel.php +++ b/extend/base/Excel.php @@ -113,9 +113,12 @@ class Excel $charset = lang('common_excel_charset_list')[$excel_charset]['value']; // 标题 - foreach($this->title as $v) + $temp_key = 0; + foreach($this->title as $k=>$v) { - $excel->getActiveSheet()->setCellValue($v['col'].'1', ($excel_charset == 0) ? $v['name'] : iconv('utf-8', $charset, $v['name'])); + $col = \PHPExcel_Cell::stringFromColumnIndex($temp_key); + $excel->getActiveSheet()->setCellValue($col.'1', ($excel_charset == 0) ? $v['name'] : iconv('utf-8', $charset, $v['name'])); + $temp_key++; } // 内容 @@ -124,9 +127,12 @@ class Excel $i = $k+2; if(is_array($v) && !empty($v)) { + $temp_key = 0; foreach($this->title as $tk=>$tv) { - $excel->getActiveSheet()->setCellValueExplicit($tv['col'].$i, ($excel_charset == 0) ? $v[$tk] : iconv('utf-8', $charset, $v[$tk]), \PHPExcel_Cell_DataType::TYPE_STRING); + $col = \PHPExcel_Cell::stringFromColumnIndex($temp_key); + $excel->getActiveSheet()->setCellValueExplicit($col.$i, ($excel_charset == 0) ? $v[$tk] : iconv('utf-8', $charset, $v[$tk]), \PHPExcel_Cell_DataType::TYPE_STRING); + $temp_key++; } } } -- GitLab