您当前的位置: 首页 > 网站编程 > PHP教程 > 导出考核统计php导出Excelde应用

导出考核统计php导出Excelde应用

作者:不详 来源:网络 发布时间: 2014-08-18 12:13 点击:
// 导出考核统计 function daochu(){ require_once 'outExcel.class.php'; header(Content-Type: application/vnd.ms-excel;charset=utf-8); $kaoheCode = $_GET['kaoheCode']; $dao = new PerformanceServices(); $kaoheinfo = $dao-getKaoheInfo($kaoheCode); $filen

导出考核统计php导出Excelde应用

  // 导出考核统计

  function daochu(){

  require_once 'outExcel.class.php';

  header("Content-Type: application/vnd.ms-excel;charset=utf-8");

  $kaoheCode = $_GET['kaoheCode'];

  $dao = new PerformanceServices();

  $kaoheinfo = $dao->getKaoheInfo($kaoheCode);

  $filename=$kaoheinfo['KH_NAME']."考核统计";

  $encoded_filename = urlencode($filename);

  $encoded_filename = str_replace("+", "%20", $encoded_filename);

  $ua = $_SERVER["HTTP_USER_AGENT"];

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

  if (preg_match("/MSIE/", $ua)) {

  header('Content-Disposition: attachment; filename="' . $encoded_filename . '.xls"');

  } else if (preg_match("/Firefox/", $ua)) {

  header('Content-Disposition: attachment; filename*="utf8''' . $filename . '.xls"');

  } else {

  header('Content-Disposition: attachment; filename="' . $filename . '.xls"');

  }

  header("Pragma: no-cache");

  header("Expires: 0");

  $dates_excel = $dao->getTongjiInfo($kaoheCode);

  $mytime = date("Y-m-d H:i:s",$dates_excel['KH_TIME']);

  $excel=new SimpleExcel();//调用类开始

  $excel->excelItem(array("统计时间",$mytime));//第一行标题,可以不要

  $excel->excelItem(array("序号","姓 名","部门","分数"));//第一行标题,可以不要

  $excel->colsAttrib(array("1","a","a","1"));//定义属性,数字型为"1",字符型为"a"

  $scores = explode(',',$dates_excel['KH_SCORES']);

  //echo $scores;exit();

  $i=0;

  foreach ($scores as $v){

  $i++;

  $r = explode(':', $v);

  $userCode = $r[0];

  $user = $dao->getUserInfo($userCode);

  $dept=$dao->getCellName($userCode);

  $excel->excelWrite(array($i,$user['QT_NAME'],$dept,$r[1]));

  }

  $excel->excelEnd();

  }

  以下是excel类 outExcel.class.php

  <?php

  class SimpleExcel

  {

  var $rowsNum=0;

  var $attrib=array();

  var $in_charset = 'UTF-8';

  function SimpleExcel()

  {

  echo pack("ssssss",0x809,0x8,0x0,0x10,0x0,0x0);

  return;

  }

  function excelItem($string=array())

  {

  for ($i=0;$i<count($string);$i++)

  {

  $curStr = $string[$i];

  $curStr = $this->iconvToData($curStr);

  $L = strlen($curStr);

  echo pack("ssssss",0x204,8+$L,$this->rowsNum,$i,0x0,$L);

  echo $curStr;

  }

  $this->rowsNum++;

  return;

  }

  function colsAttrib($string=array())

  {

  $this->attrib=$string;

  return;

  }

  function excelWrite($string=array())

  {

  for ($i=0;$i<count($string);$i++)

  {

  $curStr = $string[$i];

  $curStr = $this->iconvToData($curStr);

  if ($this->attrib[$i]=="1")

  {

  echo pack("sssss",0x203,14,$this->rowsNum,$i,0x0);

  echo pack("d",$curStr);

  } else {

  $L = strlen($curStr);

  echo pack("ssssss",0x204,8+$L,$this->rowsNum,$i,0x0,$L);

  echo $curStr;

  }

  }

  $this->rowsNum++;

  }

  function excelEnd()

  {

  echo pack("ss",0x0A,0x00);

  return;

  }

  function iconvToData($data)

  {

  return iconv($this->in_charset,'gb2312',$data);

  }

  }

  ?>
分享到:
本文"导出考核统计php导出Excelde应用"由远航站长收集整理而来,仅供大家学习与参考使用。更多网站制作教程尽在远航站长站。
顶一下
(0)
0%
踩一下
(0)
0%
[点击 次] [返回上一页] [打印]
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
关于本站 - 联系我们 - 网站声明 - 友情连接- 网站地图 - 站点地图 - 返回顶部
Copyright © 2007-2013 www.yhzhan.com(远航站长). All Rights Reserved .
远航站长:为中小站长提供最佳的学习与交流平台,提供网页制作与网站编程等各类网站制作教程.
官方QQ:445490277 网站群:26680406 网站备案号:豫ICP备07500620号-4