Model_excelxh.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. public function get_fz5($info_list,$titlename,$filename,$tail,$kong)//带空项
  166. {
  167. //这样 echo 的内容就会直接往外发,不会再在内存里堆成大球
  168. while (ob_get_level()) {
  169. ob_end_clean();
  170. }
  171. header("Content-Type: application/vnd.ms-excel; name='excel'");
  172. header("Content-type: application/octet-stream");
  173. header("Content-Disposition: attachment; filename=" . $filename);
  174. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  175. header("Pragma: no-cache");
  176. header("Expires: 0");
  177. echo '<html xmlns:x="urn:schemas-microsoft-com:office:excel">';
  178. echo '<head>';
  179. echo '<!--[if gte mso 9]><xml>';
  180. echo '<x:ExcelWorkbook>';
  181. echo '<x:ExcelWorksheets>';
  182. echo '<x:ExcelWorksheet>';
  183. echo '<x:Name>EXCEL</x:Name>';
  184. echo '<x:WorksheetOptions>';
  185. echo '<x:Print>';
  186. echo '<x:ValidPrinterInfo />';
  187. echo '</x:Print>';
  188. echo '</x:WorksheetOptions>';
  189. echo '</x:ExcelWorksheet>';
  190. echo '</x:ExcelWorksheets>';
  191. echo '</x:ExcelWorkbook>';
  192. echo '</xml>';
  193. echo '<![endif]-->';
  194. echo '</head><body>';
  195. echo $titlename;
  196. echo "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  197. foreach ($info_list as $key=>$value)
  198. {
  199. $str = "<tr>";$i=0;
  200. foreach ($kong as $k=>$a)
  201. {
  202. array_splice($value,$k,0,'');
  203. }
  204. foreach ($value as $ke=>$va)
  205. {
  206. $tj = '';
  207. //文本:vnd.ms-excel.numberformat:@
  208. //日期:vnd.ms-excel.numberformat:yyyy/mm/dd
  209. //数字:vnd.ms-excel.numberformat:#,##0.00
  210. //货币:vnd.ms-excel.numberformat:¥#,##0.00
  211. //百分比:vnd.ms-excel.numberformat: #0.00%
  212. if($ke == 'shipremarks')
  213. {
  214. $va = str_replace(array('<','>'),array('&lt;','&gt;'),$va);
  215. }
  216. if($ke == 'shouldmoney' || $ke == 'freight' || $ke == 'expressmoney' || $ke == 'budget' || $ke == 'cost' || $ke == 'refundy' || $ke == 'refundj')
  217. {
  218. $str .= "<td align='left'>".$va."</td>";//使用文本格式
  219. }
  220. else if($ke == 'ts')
  221. {
  222. $str .= "<td align='left' style='vnd.ms-excel.numberformat:0'>".$va."</td>";
  223. }
  224. else if($ke == 'zsbjz' || $ke == 'dtsbjz' || $ke == 'insurance')
  225. {
  226. $str .= "<td align='left' style='vnd.ms-excel.numberformat:#,##0.00'>".$va."</td>";
  227. }
  228. else if($ke == 'zjs' || $ke == 'ts')
  229. {
  230. $str .= "<td align='left' style='vnd.ms-excel.numberformat:#,##'>".$va."</td>";
  231. }
  232. else if($ke == 'zzl' || $ke == 'jweight' || $ke == 'weight')
  233. {
  234. if($ke == 'weight')
  235. {
  236. $va = trim($va,'kg');
  237. }
  238. $str .= "<td align='left' style='vnd.ms-excel.numberformat:#,##0.00'>".$va."</td>";
  239. }
  240. else if($ke != 'hl' && $ke != 'currencytitle' || $ke == 'orderinfo')
  241. {
  242. $str .= "<td align='left' style='vnd.ms-excel.numberformat:@'>".trim($va,' ')."\t"."</td>";
  243. }
  244. $i++;
  245. }
  246. $str .= "</tr>\n";
  247. echo $str;
  248. }
  249. echo $tail;
  250. echo "</table></body></html>";
  251. exit();
  252. //return $str;
  253. }
  254. public function get_fz6($info_list,$titlename,$filename)
  255. {
  256. //这样 echo 的内容就会直接往外发,不会再在内存里堆成大球
  257. while (ob_get_level()) {
  258. ob_end_clean();
  259. }
  260. header("Content-Type: application/vnd.ms-excel; name='excel'");
  261. header("Content-type: application/octet-stream");
  262. header("Content-Disposition: attachment; filename=" . $filename);
  263. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  264. header("Pragma: no-cache");
  265. header("Expires: 0");
  266. echo '<html xmlns:x="urn:schemas-microsoft-com:office:excel">';
  267. echo '<head>';
  268. echo '<!--[if gte mso 9]><xml>';
  269. echo '<x:ExcelWorkbook>';
  270. echo '<x:ExcelWorksheets>';
  271. echo '<x:ExcelWorksheet>';
  272. echo '<x:Name>EXCEL</x:Name>';
  273. echo '<x:WorksheetOptions>';
  274. echo '<x:Print>';
  275. echo '<x:ValidPrinterInfo />';
  276. echo '</x:Print>';
  277. echo '</x:WorksheetOptions>';
  278. echo '</x:ExcelWorksheet>';
  279. echo '</x:ExcelWorksheets>';
  280. echo '</x:ExcelWorkbook>';
  281. echo '</xml>';
  282. echo '<![endif]-->';
  283. echo '</head><body>';
  284. echo $titlename;
  285. echo "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'><tr>";
  286. foreach ($info_list as $key=>$value)
  287. {
  288. echo "<td><table border=0>";
  289. foreach ($value as $ke=>$va)
  290. {
  291. if($ke == 'shipremarks')
  292. {
  293. $va = str_replace(array('<','>'),array('&lt;','&gt;'),$va);
  294. }
  295. echo "<tr><td>".$va[0]."</td><td style='vnd.ms-excel.numberformat:@'>".$va[1]."</td></tr>";
  296. }
  297. echo "</table></td>\n";
  298. }
  299. echo "</tr></table></body></html>";
  300. exit();
  301. //return $str;
  302. }
  303. public function get_fz7($info_list,$titlename,$filename)
  304. {
  305. //这样 echo 的内容就会直接往外发,不会再在内存里堆成大球
  306. while (ob_get_level()) {
  307. ob_end_clean();
  308. }
  309. header("Content-Type: application/vnd.ms-excel; name='excel'");
  310. header("Content-type: application/octet-stream");
  311. header("Content-Disposition: attachment; filename=" . $filename);
  312. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  313. header("Pragma: no-cache");
  314. header("Expires: 0");
  315. echo '<html xmlns:x="urn:schemas-microsoft-com:office:excel">';
  316. echo '<head>';
  317. echo '<!--[if gte mso 9]><xml>';
  318. echo '<x:ExcelWorkbook>';
  319. echo '<x:ExcelWorksheets>';
  320. echo '<x:ExcelWorksheet>';
  321. echo '<x:Name>EXCEL</x:Name>';
  322. echo '<x:WorksheetOptions>';
  323. echo '<x:Print>';
  324. echo '<x:ValidPrinterInfo />';
  325. echo '</x:Print>';
  326. echo '</x:WorksheetOptions>';
  327. echo '</x:ExcelWorksheet>';
  328. echo '</x:ExcelWorksheets>';
  329. echo '</x:ExcelWorkbook>';
  330. echo '</xml>';
  331. echo '<![endif]-->';
  332. echo '</head><body>';
  333. echo $titlename;
  334. echo "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'><tr>";
  335. foreach ($info_list as $key=>$value)
  336. {
  337. echo "<td><table border=0>";
  338. foreach ($value as $ke=>$va)
  339. {
  340. if($ke == 'shipremarks')
  341. {
  342. $va = str_replace(array('<','>'),array('&lt;','&gt;'),$va);
  343. }
  344. echo "<tr><td>".$va[0]."</td><td style='vnd.ms-excel.numberformat:@'>".$va[1]."</td><td >".$va[2]."</td></tr>";
  345. }
  346. echo "</table></td>\n";
  347. }
  348. echo "</tr></table></body></html>";
  349. exit();
  350. //return $str;
  351. }
  352. }