Model_excelxh.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * 采用循环输入的模式
  4. */
  5. class Model_excelxh extends Lin_Model {
  6. function __construct(){
  7. parent::__construct();
  8. }
  9. public function get_fz2($info_list, $titlename, $filename, $tail){
  10. //这样 echo 的内容就会直接往外发,不会再在内存里堆成大球
  11. while (ob_get_level()) {
  12. ob_end_clean();
  13. }
  14. header("Content-Type: application/vnd.ms-excel; name='excel'");
  15. header("Content-type: application/octet-stream");
  16. header("Content-Disposition: attachment; filename=" . $filename);
  17. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  18. header("Pragma: no-cache");
  19. header("Expires: 0");
  20. echo '<html xmlns:x="urn:schemas-microsoft-com:office:excel">';
  21. echo '<head>';
  22. echo '<!--[if gte mso 9]><xml>';
  23. echo '<x:ExcelWorkbook>';
  24. echo '<x:ExcelWorksheets>';
  25. echo '<x:ExcelWorksheet>';
  26. echo '<x:Name>EXCEL</x:Name>';
  27. echo '<x:WorksheetOptions>';
  28. echo '<x:Print>';
  29. echo '<x:ValidPrinterInfo />';
  30. echo '</x:Print>';
  31. echo '</x:WorksheetOptions>';
  32. echo '</x:ExcelWorksheet>';
  33. echo '</x:ExcelWorksheets>';
  34. echo '</x:ExcelWorkbook>';
  35. echo '</xml>';
  36. echo '<![endif]-->';
  37. echo '</head><body>';
  38. echo $titlename;
  39. echo "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  40. foreach ($info_list as $key=>$value)
  41. {
  42. $str = "<tr>";
  43. foreach ($value as $ke=>$va)
  44. {
  45. $tj = '';
  46. //文本:vnd.ms-excel.numberformat:@
  47. //日期:vnd.ms-excel.numberformat:yyyy/mm/dd
  48. //数字:vnd.ms-excel.numberformat:#,##0.00
  49. //货币:vnd.ms-excel.numberformat:¥#,##0.00
  50. //百分比:vnd.ms-excel.numberformat: #0.00%
  51. if($ke == 'shipremarks')
  52. {
  53. $va = str_replace(array('<','>'),array('&lt;','&gt;'),$va);
  54. }
  55. if($ke == 'shouldmoney' || $ke == 'freight' || $ke == 'expressmoney' || $ke == 'budget' || $ke == 'cost' || $ke == 'refundy' || $ke == 'refundj')
  56. {
  57. $str .= "<td align='left'>".$va."</td>";//使用文本格式
  58. }
  59. else if($ke == 'ts' || $ke == 'zsbjz')
  60. {
  61. $str .= "<td align='left' style='vnd.ms-excel.numberformat:0'>".$va."</td>";
  62. }
  63. else if($ke == 'zzl')
  64. {
  65. $str .= "<td align='left' style='vnd.ms-excel.numberformat:#,##0.00'>".$va."</td>";
  66. }
  67. else if($ke != 'fpdata' && $ke != 'hl' && $ke != 'currencytitle' || $ke == 'orderinfo')
  68. {
  69. $str .= "<td align='left' x:str style='mso-number-format:".' "\@'.'" '.";vnd.ms-excel.numberformat:0'>".trim($va,' ')."\t"."</td>"; //.$tj.$va.
  70. }
  71. }
  72. $str .= "</tr>\n";
  73. echo $str;
  74. }
  75. echo $tail."</table></body></html>";
  76. exit();
  77. }
  78. }