lvhao 14 часов назад
Родитель
Сommit
aa50bd8c17
2 измененных файлов с 83 добавлено и 1 удалено
  1. 2 1
      core/CoreApp/controllers/Boss.php
  2. 81 0
      core/CoreApp/models/Model_excelxh.php

+ 2 - 1
core/CoreApp/controllers/Boss.php

@@ -61,6 +61,7 @@ class Boss extends Start_Controller
 		$this->load->_model("Model_check","check");
 		$this->load->_model("Model_logic_express","logic_express");
 		$this->load->_model("Model_ck","ck");
+		$this->load->_model("Model_excelxh","excelxh");
 
 	}
 	//定义方法的调用规则 获取URI第二段值
@@ -1323,7 +1324,7 @@ class Boss extends Start_Controller
             </table>";
 			$filename = $title . ".xls";
 			$tail = "\n";
-			$this->excel->get_fz2($sp, $titlename, $filename, $tail);
+			$this->excelxh->get_fz2($sp, $titlename, $filename, $tail);
 		}
 	}
 

+ 81 - 0
core/CoreApp/models/Model_excelxh.php

@@ -0,0 +1,81 @@
+<?php
+/**
+ * 采用循环输入的模式
+ */
+class Model_excelxh extends Lin_Model {
+	function __construct(){
+			parent::__construct();
+	}
+	public function get_fz2($info_list, $titlename, $filename, $tail){
+		//这样 echo 的内容就会直接往外发,不会再在内存里堆成大球
+		while (ob_get_level()) {
+			ob_end_clean();
+		}
+		header("Content-Type: application/vnd.ms-excel; name='excel'");
+		header("Content-type: application/octet-stream");
+		header("Content-Disposition: attachment; filename=" . $filename);
+		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+		header("Pragma: no-cache");
+		header("Expires: 0");
+
+		echo '<html xmlns:x="urn:schemas-microsoft-com:office:excel">';
+		echo '<head>';
+		echo '<!--[if gte mso 9]><xml>';
+		echo '<x:ExcelWorkbook>';
+		echo '<x:ExcelWorksheets>';
+		echo '<x:ExcelWorksheet>';
+		echo '<x:Name>EXCEL</x:Name>';
+		echo '<x:WorksheetOptions>';
+		echo '<x:Print>';
+		echo '<x:ValidPrinterInfo />';
+		echo '</x:Print>';
+		echo '</x:WorksheetOptions>';
+		echo '</x:ExcelWorksheet>';
+		echo '</x:ExcelWorksheets>';
+		echo '</x:ExcelWorkbook>';
+		echo '</xml>';
+		echo '<![endif]-->';
+		echo '</head><body>';
+		
+		echo $titlename; 
+		echo  "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>"; 
+		foreach ($info_list as $key=>$value) 
+		{ 
+		    $str = "<tr>";
+		    foreach ($value as $ke=>$va) 
+			{
+				$tj = '';
+				//文本:vnd.ms-excel.numberformat:@
+				//日期:vnd.ms-excel.numberformat:yyyy/mm/dd
+				//数字:vnd.ms-excel.numberformat:#,##0.00
+				//货币:vnd.ms-excel.numberformat:¥#,##0.00
+				//百分比:vnd.ms-excel.numberformat: #0.00%
+				if($ke == 'shipremarks')
+				{
+					$va = str_replace(array('<','>'),array('&lt;','&gt;'),$va);
+				}
+				if($ke == 'shouldmoney' || $ke == 'freight' || $ke == 'expressmoney' || $ke == 'budget' || $ke == 'cost' || $ke == 'refundy' || $ke == 'refundj')
+				{
+					$str .= "<td align='left'>".$va."</td>";//使用文本格式
+				}
+				else if($ke == 'ts' || $ke == 'zsbjz')
+				{
+					$str .= "<td align='left' style='vnd.ms-excel.numberformat:0'>".$va."</td>";
+				}
+				else if($ke == 'zzl')
+				{
+					$str .= "<td align='left' style='vnd.ms-excel.numberformat:#,##0.00'>".$va."</td>";
+				}
+				else if($ke != 'fpdata' && $ke != 'hl' && $ke != 'currencytitle' || $ke == 'orderinfo')
+				{
+						 $str .= "<td align='left' x:str style='mso-number-format:".' "\@'.'" '.";vnd.ms-excel.numberformat:0'>".trim($va,' ')."\t"."</td>"; //.$tj.$va.
+				}
+		    }
+			$str .= "</tr>\n";
+			echo $str;
+		}
+		echo  $tail."</table></body></html>"; 
+		
+		exit(); 
+	}
+}