Ver Fonte

提交excel的fz的方法

lvhao há 5 horas atrás
pai
commit
fc3237d2d9
1 ficheiros alterados com 89 adições e 0 exclusões
  1. 89 0
      core/CoreApp/models/Model_excelxh.php

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

@@ -6,6 +6,95 @@ class Model_excelxh extends Lin_Model {
 	function __construct(){
 			parent::__construct();
 	}
+	public function get_fz($info_list,$titlename,$filename,$tail,$ts=0)
+	{
+		//这样 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\">
+        <head>
+        <!--[if gte mso 9]><xml>
+        <x:ExcelWorkbook>
+        <x:ExcelWorksheets>
+        <x:ExcelWorksheet>
+        <x:Name>EXCEL</x:Name>
+        <x:WorksheetOptions>
+        <x:Print>
+        <x:ValidPrinterInfo />
+        </x:Print>
+        </x:WorksheetOptions>
+        </x:ExcelWorksheet>
+        </x:ExcelWorksheets>
+        </x:ExcelWorkbook>
+        </xml>
+        <![endif]-->
+        </head><body>";
+		echo $titlename; 
+		echo "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>"; 
+		foreach ($info_list as $key=>$value) 
+		{ 
+			$str = "";
+		    if($value['fpdata'] == '')
+				{
+					continue;
+				}
+		    $str .= "<tr>";
+		    foreach ($value as $ke=>$va) 
+			{
+				if($ke == 'shipremarks')
+				{
+					$va = str_replace(array('<','>'),array('&lt;','&gt;'),$va);
+				}
+				if($ke == 'orderinfo' || $ke == 'waybill')
+				{
+					$str .= "<td align='left' style='vnd.ms-excel.numberformat:@'>".$va."</td>";
+				}
+				else if($ke != 'fpdata' && $ke != 'hl' && $ke != 'currencytitle')
+				{
+		            $str .= "<td align='left'>".$va."</td>"; 
+				}
+		    }
+			$str .= "<td><table border=1>";
+			$a = 0;
+			foreach ($value['fpdata'] as $k=>$v)
+		    {
+				$vd = '';
+				foreach ($v as $vv) 
+		        {
+					$vd .= "<td>".$vv."</td>";
+				}
+				$str .= "<tr>".$vd."</tr>";
+				$endv = is_numeric(end($v))?end($v):0;
+				$a = $a + $endv;		
+			}
+			$str .= "</table></td>"; 
+			if($ts != 1)
+			{
+			    $str .= "<td>".$a."</td>";
+			}
+		    $str .= "</tr>\n"; 
+			echo $str;
+		}
+		echo $tail;
+		echo  "</table></body></html>"; 
+		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" ); 
+		exit(); 
+		//return $str;
+	}
+
+
 	public function get_fz2($info_list, $titlename, $filename, $tail){
 		//这样 echo 的内容就会直接往外发,不会再在内存里堆成大球
 		while (ob_get_level()) {