Model_excelxh.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * 采用循环输入的模式
  4. */
  5. class Model_excelxh extends Lin_Model {
  6. function __construct(){
  7. parent::__construct();
  8. }
  9. public function get_fz($info_list,$titlename,$filename,$tail,$ts=0)
  10. {
  11. //这样 echo 的内容就会直接往外发,不会再在内存里堆成大球
  12. while (ob_get_level()) {
  13. ob_end_clean();
  14. }
  15. header("Content-Type: application/vnd.ms-excel; name='excel'");
  16. header("Content-type: application/octet-stream");
  17. header("Content-Disposition: attachment; filename=" . $filename);
  18. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  19. header("Pragma: no-cache");
  20. header("Expires: 0");
  21. echo "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  22. <head>
  23. <!--[if gte mso 9]><xml>
  24. <x:ExcelWorkbook>
  25. <x:ExcelWorksheets>
  26. <x:ExcelWorksheet>
  27. <x:Name>EXCEL</x:Name>
  28. <x:WorksheetOptions>
  29. <x:Print>
  30. <x:ValidPrinterInfo />
  31. </x:Print>
  32. </x:WorksheetOptions>
  33. </x:ExcelWorksheet>
  34. </x:ExcelWorksheets>
  35. </x:ExcelWorkbook>
  36. </xml>
  37. <![endif]-->
  38. </head><body>";
  39. echo $titlename;
  40. echo "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  41. foreach ($info_list as $key=>$value)
  42. {
  43. $str = "";
  44. if($value['fpdata'] == '')
  45. {
  46. continue;
  47. }
  48. $str .= "<tr>";
  49. foreach ($value as $ke=>$va)
  50. {
  51. if($ke == 'shipremarks')
  52. {
  53. $va = str_replace(array('<','>'),array('&lt;','&gt;'),$va);
  54. }
  55. if($ke == 'orderinfo' || $ke == 'waybill')
  56. {
  57. $str .= "<td align='left' style='vnd.ms-excel.numberformat:@'>".$va."</td>";
  58. }
  59. else if($ke != 'fpdata' && $ke != 'hl' && $ke != 'currencytitle')
  60. {
  61. $str .= "<td align='left'>".$va."</td>";
  62. }
  63. }
  64. $str .= "<td><table border=1>";
  65. $a = 0;
  66. foreach ($value['fpdata'] as $k=>$v)
  67. {
  68. $vd = '';
  69. foreach ($v as $vv)
  70. {
  71. $vd .= "<td>".$vv."</td>";
  72. }
  73. $str .= "<tr>".$vd."</tr>";
  74. $endv = is_numeric(end($v))?end($v):0;
  75. $a = $a + $endv;
  76. }
  77. $str .= "</table></td>";
  78. if($ts != 1)
  79. {
  80. $str .= "<td>".$a."</td>";
  81. }
  82. $str .= "</tr>\n";
  83. echo $str;
  84. }
  85. echo $tail;
  86. echo "</table></body></html>";
  87. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  88. header( "Content-type: application/octet-stream" );
  89. header( "Content-Disposition: attachment; filename=".$filename );
  90. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  91. header( "Pragma: no-cache" );
  92. header( "Expires: 0" );
  93. exit();
  94. //return $str;
  95. }
  96. public function get_fz2($info_list, $titlename, $filename, $tail){
  97. //这样 echo 的内容就会直接往外发,不会再在内存里堆成大球
  98. while (ob_get_level()) {
  99. ob_end_clean();
  100. }
  101. header("Content-Type: application/vnd.ms-excel; name='excel'");
  102. header("Content-type: application/octet-stream");
  103. header("Content-Disposition: attachment; filename=" . $filename);
  104. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  105. header("Pragma: no-cache");
  106. header("Expires: 0");
  107. echo '<html xmlns:x="urn:schemas-microsoft-com:office:excel">';
  108. echo '<head>';
  109. echo '<!--[if gte mso 9]><xml>';
  110. echo '<x:ExcelWorkbook>';
  111. echo '<x:ExcelWorksheets>';
  112. echo '<x:ExcelWorksheet>';
  113. echo '<x:Name>EXCEL</x:Name>';
  114. echo '<x:WorksheetOptions>';
  115. echo '<x:Print>';
  116. echo '<x:ValidPrinterInfo />';
  117. echo '</x:Print>';
  118. echo '</x:WorksheetOptions>';
  119. echo '</x:ExcelWorksheet>';
  120. echo '</x:ExcelWorksheets>';
  121. echo '</x:ExcelWorkbook>';
  122. echo '</xml>';
  123. echo '<![endif]-->';
  124. echo '</head><body>';
  125. echo $titlename;
  126. echo "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  127. foreach ($info_list as $key=>$value)
  128. {
  129. $str = "<tr>";
  130. foreach ($value as $ke=>$va)
  131. {
  132. $tj = '';
  133. //文本:vnd.ms-excel.numberformat:@
  134. //日期:vnd.ms-excel.numberformat:yyyy/mm/dd
  135. //数字:vnd.ms-excel.numberformat:#,##0.00
  136. //货币:vnd.ms-excel.numberformat:¥#,##0.00
  137. //百分比:vnd.ms-excel.numberformat: #0.00%
  138. if($ke == 'shipremarks')
  139. {
  140. $va = str_replace(array('<','>'),array('&lt;','&gt;'),$va);
  141. }
  142. if($ke == 'shouldmoney' || $ke == 'freight' || $ke == 'expressmoney' || $ke == 'budget' || $ke == 'cost' || $ke == 'refundy' || $ke == 'refundj')
  143. {
  144. $str .= "<td align='left'>".$va."</td>";//使用文本格式
  145. }
  146. else if($ke == 'ts' || $ke == 'zsbjz')
  147. {
  148. $str .= "<td align='left' style='vnd.ms-excel.numberformat:0'>".$va."</td>";
  149. }
  150. else if($ke == 'zzl')
  151. {
  152. $str .= "<td align='left' style='vnd.ms-excel.numberformat:#,##0.00'>".$va."</td>";
  153. }
  154. else if($ke != 'fpdata' && $ke != 'hl' && $ke != 'currencytitle' || $ke == 'orderinfo')
  155. {
  156. $str .= "<td align='left' x:str style='mso-number-format:".' "\@'.'" '.";vnd.ms-excel.numberformat:0'>".trim($va,' ')."\t"."</td>"; //.$tj.$va.
  157. }
  158. }
  159. $str .= "</tr>\n";
  160. echo $str;
  161. }
  162. echo $tail."</table></body></html>";
  163. exit();
  164. }
  165. }