<?php require_once "config.php"; ?>
<?php require_once "class/class.mysql.php"; ?>
<?php
$vars = array_merge ( $_GET, $_POST );
if (array_key_exists ( "level1", $vars )) {
$level1 = $vars ["level1"];
} else {
$level1 = "";
}
if (array_key_exists ( "level2", $vars )) {
$level2 = $vars ["level2"];
} else {
$level2 = "";
}
if (array_key_exists ( "level3", $vars )) {
$level3 = $vars ["level3"];
} else {
$level3 = "";
}
if (array_key_exists ( "level4", $vars )) {
$level4 = $vars ["level4"];
} else {
$level4 = "";
}
$tmp = split ( ",", $level4 );
$tmp2 = array ();
foreach ( $tmp as &$x ) {
array_push ( $tmp2, "level4='$x'" );
}
$level4cond = join ( " or ", $tmp2 );
$level3 = "-," . $level3;
$tmp = split ( ",", $level3 );
$tmp2 = array ();
foreach ( $tmp as &$x ) {
array_push ( $tmp2, "level3 LIKE '%$x%'" );
}
$level3cond = join ( " or ", $tmp2 );
$db = new mysql ();
$sql = "SELECT * FROM chemicals where level1='MAT' and level2='CER' and level3 LIKE '%-%' and level4='ADD001' ORDER BY name ASC,score DESC ";
$db->query ( $sql );
$total = $db->count ();
//echo $total;
$totalscore = 0;
$totalchemicals = 0;function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
// 文件头
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=456.xls ");
header("Content-Transfer-Encoding: binary ");
// 向表中添加数据
xlsBOF();
xlsWriteLabel(0,0,"No");
xlsWriteLabel(0,1,"Chemical");
xlsWriteLabel(0,2,"Classification");
xlsWriteLabel(0,3,"CAS NO.");
xlsWriteLabel(0,4,"EC No.");
xlsWriteLabel(0,5,"Function");
$xlsRow = 1;
while($array = mysql_fetch_array($query)) {
$score = $row['score'];
if($score > 20) { $color = "red"; }
else if($score > 10 and $score <= 20) { $color = "green"; }
else if($score <= 10) {$color = "white"; }
++$i;
xlsWriteNumber($xlsRow,0,"$i");
xlsWriteNumber($xlsRow,1,"\t\t<NAME><![CDATA[" . $row['name'] . "]]></NAME>\n");
xlsWriteLabel($xlsRow,2,"\t\t<CLASSIFICATION><![CDATA[" . $row['classification'] . "]]></CLASSIFICATION>\n");
xlsWriteLabel($xlsRow,3,"\t\t<CASNO><![CDATA[" . $row['casno'] . "]]></CASNO>\n");
xlsWriteLabel($xlsRow,4,"\t\t<ECNO><![CDATA[" . $row['ecno'] . "]]></ECNO>\n");
xlsWriteLabel($xlsRow,5,"\t\t<FUNCTION><![CDATA[" . $row['function'] . "]]></FUNCTION>\n");
$xlsRow++;
}
xlsEOF();
exit();
?>
<?php require_once "class/class.mysql.php"; ?>
<?php
$vars = array_merge ( $_GET, $_POST );
if (array_key_exists ( "level1", $vars )) {
$level1 = $vars ["level1"];
} else {
$level1 = "";
}
if (array_key_exists ( "level2", $vars )) {
$level2 = $vars ["level2"];
} else {
$level2 = "";
}
if (array_key_exists ( "level3", $vars )) {
$level3 = $vars ["level3"];
} else {
$level3 = "";
}
if (array_key_exists ( "level4", $vars )) {
$level4 = $vars ["level4"];
} else {
$level4 = "";
}
$tmp = split ( ",", $level4 );
$tmp2 = array ();
foreach ( $tmp as &$x ) {
array_push ( $tmp2, "level4='$x'" );
}
$level4cond = join ( " or ", $tmp2 );
$level3 = "-," . $level3;
$tmp = split ( ",", $level3 );
$tmp2 = array ();
foreach ( $tmp as &$x ) {
array_push ( $tmp2, "level3 LIKE '%$x%'" );
}
$level3cond = join ( " or ", $tmp2 );
$db = new mysql ();
$sql = "SELECT * FROM chemicals where level1='MAT' and level2='CER' and level3 LIKE '%-%' and level4='ADD001' ORDER BY name ASC,score DESC ";
$db->query ( $sql );
$total = $db->count ();
//echo $total;
$totalscore = 0;
$totalchemicals = 0;function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
// 文件头
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=456.xls ");
header("Content-Transfer-Encoding: binary ");
// 向表中添加数据
xlsBOF();
xlsWriteLabel(0,0,"No");
xlsWriteLabel(0,1,"Chemical");
xlsWriteLabel(0,2,"Classification");
xlsWriteLabel(0,3,"CAS NO.");
xlsWriteLabel(0,4,"EC No.");
xlsWriteLabel(0,5,"Function");
$xlsRow = 1;
while($array = mysql_fetch_array($query)) {
$score = $row['score'];
if($score > 20) { $color = "red"; }
else if($score > 10 and $score <= 20) { $color = "green"; }
else if($score <= 10) {$color = "white"; }
++$i;
xlsWriteNumber($xlsRow,0,"$i");
xlsWriteNumber($xlsRow,1,"\t\t<NAME><![CDATA[" . $row['name'] . "]]></NAME>\n");
xlsWriteLabel($xlsRow,2,"\t\t<CLASSIFICATION><![CDATA[" . $row['classification'] . "]]></CLASSIFICATION>\n");
xlsWriteLabel($xlsRow,3,"\t\t<CASNO><![CDATA[" . $row['casno'] . "]]></CASNO>\n");
xlsWriteLabel($xlsRow,4,"\t\t<ECNO><![CDATA[" . $row['ecno'] . "]]></ECNO>\n");
xlsWriteLabel($xlsRow,5,"\t\t<FUNCTION><![CDATA[" . $row['function'] . "]]></FUNCTION>\n");
$xlsRow++;
}
xlsEOF();
exit();
?>
--------
With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is
hard to be sure where they are going to land, and it could be dangerous sitting under them as they
fly overhead.
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=456.xls ");
header("Content-Transfer-Encoding: binary ");这段内容放到xlsEOF();后面呢?导出有内容么?