• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php生成excel

php 搞代码 4年前 (2022-01-23) 16次浏览 已收录 0个评论

生成excel有很多方法 这里记录一个相对最简单 在php 5.3.8里能使用的

 1 function xlsBOF() { 2  echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0); 3  return; 4 } 5 function xlsEOF() { 6  echo pack("ss", 0x0A, 0x00); 7  return; 8 } 9 function format( $STR ){10  $STR = str_replace( "\"", "", $STR );11  if ( strpos( $STR, "," ) ){12   $STR = "\"".$STR."\"";13  }14  $STR = iconv( "utf-8", "gb2312", $STR );15  return $STR;16 }17 function xlsWriteNumber($Row, $Col, $Value) {18  echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);19  echo pack("d", $Value);20  return;21 }22 function xlsWriteLabel($Row, $Col, $Value ) {23  $L = strlen($Value);24  echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);25  echo $Value;26  return;27 }28 function write_excel_line($hang,$lie,$val){29  if(is_n<a style="color:transparent">、本文来源gao($daima.com搞@代@#码$网</a><big>搞gaodaima代码</big>umeric($val)){30   xlsWriteNumber($hang,$lie,$val);31  }else{32   xlsWriteLabel($hang,$lie,$val);33  }34 }35 $mktime = mktime();36 header('Content-Type: text/html; charset=utf-8');37 header("Pragma: public");38 header("Expires: 0");39 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");40 header("Content-Type: application/force-download");41 header("Content-Type: application/octet-stream");42 header("Content-Type: application/download");43 header("Content-Disposition: attachment;filename=$mktime.xls ");44 header("Content-Transfer-Encoding: binary ");45 // XLS Data Cell46 xlsBOF();47 xlsWriteLabel(0, 0, format('单元格A1'));48 xlsWriteLabel(0, 1, format('单元格B1'));49 xlsWriteLabel(0, 2, format('单元格C1'));50 write_excel_line(1, 0, 'A2');51 write_excel_line(1, 1, 'B2');52 write_excel_line(1, 2, 'C2');53 write_excel_line(2, 0, 'A3');54 write_excel_line(2, 1, 'B3');55 write_excel_line(2, 2, 'C3');56 write_excel_line(3 , 0, '40');57 write_excel_line(3 , 1, '41');58 write_excel_line(3 , 2, '42');59 xlsEOF();

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php生成excel
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址