当前位置: 网学 > 编程文档 > PHP > 正文

PHPEXCEL 使用小记

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/18
;getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle(''D1'')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

$objPHPExcel->getActiveSheet()->getStyle(''A2''.($i))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$objPHPExcel->getActiveSheet()->getStyle(''B2''.($i))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle(''C2''.($i))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle(''D2''.($i))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle(''E2''.($i))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

if($this->_db->num_rows($query)>0)
{
$i=3;
while ($row = $this->_db->fetch_assoc($query))
{
$objPHPExcel->getActiveSheet()->setCellValue(''A''.($i),"BOX ".$row[''box_num'']);
$objPHPExcel->getActiveSheet()->setCellValue(''B''.($i),sprintf("%.2f",$row[''volume_weight'']));
$objPHPExcel->getActiveSheet()->setCellValue(''C''.($i),sprintf("%.2f",$row[''box_weight'']));
$objPHPExcel->getActiveSheet()->setCellValue(''D''.($i),sprintf("%.2f",$row[''system_weight'']));
$objPHPExcel->getActiveSheet()->setCellValue(''E''.($i),sprintf("%.2f",$row[''real_weight'']));

$objPHPExcel->getActiveSheet()->getStyle(''A''.($i))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
$objPHPExcel->getActiveSheet()->getStyle(''B''.($i))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle(''C''.($i))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle(''D''.($i))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle(''E''.($i))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$i++;
}
}

$fileName="exportBox.xls";
$filePath = dirname(dirname("__FILE__"))."/template/".$fileName;
$path = "./template/".$fileName;
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
if(file_exists($path)){
chmod($path, 0777);
unlink($path);
$objWriter->save($path);
header(''application/vnd.ms-excel'');
header(''Content-Disposition: attachment;filename=weight-''.$this->_packInfos["o_id"].".xlsx");
readfile($filePath);
die();
}
else
{
$objWriter->save($path);
header(''application/vnd.ms-excel'');
header(''Content-Disposition: attachment;filename=weight-''.$this->_packInfos["o_id"].".xlsx");
readfile($filePath);
die();
}

注:上面的php生成excel的方式是直接使用A标签形式的,如果使用ajax,可以不使用header,直接echo $path,前台window

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号