PHP-phpexcel导出时循环输出表头时的问题

Web程序数据库 Web程序数据库 主题:1214 回复:2505

PHP-phpexcel导出时循环输出表头时的问题

瑾兮 发布于 2017-04-15 字数 1225 浏览 1133 回复 1

我用phpexcel循环输出表头,先将所有的表头信息放入一个数值里面,然后循环输出,却总是出错,各位大神能不能帮我看看到底是怎么回事。

$head  = array("工号","姓名","性别","出生日期","脚码","民族","年龄","毕业院校","所学专业","目前所在城市","身高","体重","籍贯","户口性质","入学前户口所在地","身份证","政治面貌","婚姻状况","毕业时间","手机号码","手机号码二","电子信箱","相片","通信地址","邮政编码","投递职位","投递部门","期望月薪(税前)","是否接受调配","关系","姓名","年龄","工作单位","职务","关系","姓名","年龄","工作单位","职务","关系","姓名","年龄","工作单位","职务","开始/结束时间","学校名称","学历","专业名称","学位","年级排名","主修课程","开始/结束时间","学校名称","学历","专业名称","学位","年级排名","主修课程","开始/结束时间","学校名称","学历","专业名称","学位","年级排名","主修课程","开始/结束时间","学校名称","学历","专业名称","学位","年级排名","主修课程","外语语种","等级证书","考试分数","听说能力","阅读能力");

foreach($head as $key => $value){
$rm = iconv("GB2312","UTF-8",$value);
for ($i = 'A'; $i <= 'Z'; $i++){
foreach($rm as $key => $value){
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($i."1", $value);
}
}
}

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

支持 Markdown 语法,需要帮助?

评论(1

想挽留 2017-07-02 1 楼

出错的应该是下边这个循环

for ($i = 'A'; $i <= 'Z'; $i++){}

详细解释可以参考 @php字符递增

所以可以改写为:

foreach($head as $key => $value){
$rm = iconv("GB2312","UTF-8",$value);
foreach(range('A','Z') as $k=>$i) {
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($i."1", $rm);
}
}

或者参考 @php字符递增 中的答案给出的解决方法。