zoukankan      html  css  js  c++  java
  • 用php 生成 excel 表格

     //引用新建对象
    require "../phpexcel/Classes/PHPExcel.php"; $excel = new PHPExcel();

    建表格

    //Excel表格式,这里简略写了4列
    $letter = array('A','B','C','D',);
    

     填充值

    $excel->getActiveSheet()->setCellValue("A1","差旅费报销单");  //填充A1的值
    $excel->getActiveSheet()->mergeCells('A1:D1');          //合并行从A1到D1
    $excel->getActiveSheet()->mergeCells('C7:c10'); //合并列从C7到C10
    $excel->getActiveSheet()->setCellValue("A2","姓名"); $excel->getActiveSheet()->setCellValue("B2","{$name}"); $excel->getActiveSheet()->setCellValue("C2","部门"); $excel->getActiveSheet()->setCellValue("D2","{$bm}");

     表格样式设置

    $excel->getActiveSheet()->getColumnDimension('A')->setWidth(13);//设置列的宽度
    $excel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
    $excel->getActiveSheet()->getColumnDimension('C')->setWidth(13);
    $excel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
    $excel->getActiveSheet()->getRowDimension(5)->setRowHeight(100);
     //设置行的高度数字代表第几行
    $excel->getActiveSheet()->getRowDimension(2)->setRowHeight(25);
    $excel->getActiveSheet()->getRowDimension(3)->setRowHeight(25);
    $excel->getActiveSheet()->getRowDimension(4)->setRowHeight(25);
    $excel->getActiveSheet()->getRowDimension(6)->setRowHeight(25);
    $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);//横向居中
    $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);//纵向居中

    生成表格

    $write = new PHPExcel_Writer_Excel5($excel);
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
    header("Content-Type:application/force-download");
    header("Content-Type:application/vnd.ms-execl");
    header("Content-Type:application/octet-stream");
    header("Content-Type:application/download");;
    header("Content-Disposition:attachment;filename={$ids}出差报销表.xls");//要生成的表名
    header("Content-Transfer-Encoding:binary");
    $write->save('php://output');
    
  • 相关阅读:
    struts2第一天——入门和基本操作
    eclipse各种小图标含义
    复制web项目时注意修改web项目名
    AndroidCityPicker仿IOS选择效果
    每日五题(Spring)
    block-循环引用
    给EasyUi的Form加入自己主动填充部分输入框的方法
    智能停车O2O 独角兽初现:“ETCP停车”获5000万美金A轮融资
    解决移动端页面滚动后不触发touchend事件
    《从零開始学Swift》学习笔记(Day 61)——Core Foundation框架之内存管理
  • 原文地址:https://www.cnblogs.com/yi11/p/7009146.html
Copyright © 2011-2022 走看看