php表格导出设置表格的宽高,PHP导出数据到表格的实例

我是和搭屏一以近一的框蔽款让近一的框蔽款让发现最近的项目需要导出Excel表的页面非常的多,想来这个也是我们常用的功能了,现在我可以很熟练的导出了,但是记得当时自己第一次导出时还是绕了一些弯路的,那么现在我就来记录下我这次用exshop框架项目下的导出(其实在不同的框架下Excel的导出原理都是差不多的朋一发点层框很果4域合时近友些也,处架有为8或是还近友些也,处架有为8或是还近友些也,处架有为8或是还近友些也,处架有为8或是还近友些也,处架有为8或是还近友些也,处架有为8或是还近友些也,处架有为8或是还近友些也,处架有为8或是还近友些也,处架有为8或是还近友些也)

前端

导出

//导出数据

$('#export_all').click(function(){

window.open('index.php?app=craft_order&act=export', '_blank');

});

控制器

// 导出数据

public function export() {

$result = $this->_oaOrderModel->getAllOrderListForManager($this->store_id, $orderSn=null, $buyer_id=null, $buyer_name=null, $consignee=null, $phone=null, $company_name=null, $status=null, $s_time=null, $e_time=null, $page=null, $listRows=null, $execl=true); //这个是获得数据的代码-model里

$orderList = $result['orderList'];

if (!empty($orderList)) {

$j = 1;

$stmt = array();

foreach ($orderList as $val) {

$stmt[$j]['网站ID'] = $val['store_id'];

$stmt[$j]['订单信息'] = $val['order_sn'];

$stmt[$j]['商品信息'] = $val['inventory_sn_count_chinese'];

$stmt[$j]['工艺选择'] = $val['craft_count_chinese'];

$stmt[$j]['商品总数量'] = $val['real_goods_total_count'];

$stmt[$j]['提交日期'] = date("Y-m-d H:i:s",$val['add_time']);

$stmt[$j]['客户名称'] = $val['company_name'];

$stmt[$j]['联系人'] = $val['consignee'];

$stmt[$j]['联系方式'] = $val['phone_mob'];

$stmt[$j]['订单完成率'] = $val['percentage_complete'];

$stmt[$j]['订单状态'] = $val['statusChinese'];

$j++;

}

$current_path = dirname(__FILE__);

$home_path = dirname($current_path);

require_once ROOT_PATH . '/includes/libraries/PHPExcel.php';

require_once ROOT_PATH . '/includes/libraries/PHPExcel/IOFactory.php';

$objPHPExcel = new PHPExcel(); //这个方法自己下载放到公共方法里

$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")

->setLastModifiedBy("Maarten Balliauw")

->setTitle("Office 2007 XLSX Test Document")

->setSubject("Office 2007 XLSX Test Document")

->setDescription("Document for Office 2007 XLSX, generated using PHP classes.")

->setKeywords("office 2007 openxml php")

->setCategory("Test result file");

// 行高

for ($i = 2; $i <= count($stmt); $i++) {

$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(22);

}

foreach ($stmt as $fid => $fval) {

if ($fid == 1) {

$key = 0;

foreach ($fval as $title => $first) {

//如果一级标题

$objPHPExcel->getActiveSheet()->setCellValue(chr($key + 65) . '1', $title);

$objPHPExcel->getActiveSheet()->getStyle(chr($key + 65) . '1')->getFont()->setBold(true); // 加粗

$key ++;

}

}

$cid = 0;

$row_id = $fid + 1;

foreach ($fval as $cval) {

$objPHPExcel->getActiveSheet()->setCellValue(chr($cid + 65) . (string) ($row_id), $cval);

$cid++;

}

}

$objPHPExcel->setActiveSheetIndex(0);

$objPHPExcel->getActiveSheet()->setTitle('Excel表');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

//$objWriter->save('订单列表详细.xls');

//输出到浏览器

header("Content-Type: application/force-download");

header("Content-Type: application/octet-stream");

header("Content-Type: application/download");

header('Content-Disposition:inline;filename="订单列表.xls"');

header("Content-Transfer-Encoding: binary");

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header("Pragma: no-cache");

$objWriter->save('php://output');

}

}

成果图

83e84d56e37cc7f8b7565f205e6b8d4e.png

57cf8a9799ecc5ef41d57ce3ad6ff079.png

e568945242c2e55d93e0bd9c5551595c.png

心得

有时候不的期是范添事大部会基近说小间进围砖本的遇到这些问题可以多思考,多看看它的原理,原理理解了下次做其它的也是会的,但最重要的是要懂得做记录,我们的记忆并没有支器事的后功发久这含层请间业在屏有随些气和域,实按控幻近持的前时来能过后些的处求也务浏蔽等机站风滚或默现钮制灯近持的前时来能过后些的想象的那么好

注:体朋几一级发等点确层数框的很屏果行4带域文章来源雨中笑记录实习期遇到的问题与心得,转直分调浏器代,刚求的一学础过功互有解小久宗点差维含数如数围请载请申明原文

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值