这是我的出口代码。只想用零引导,因为这是我每个学生的唯一代码,但是在我导出到excel之后,零已经消失了。我想做什么。
function db_connect(){
include('dbcon.php');
if ($dbcon->connect_error) {
die("Connection failed: " . $dbcon->connect_error);
}
return $dbcon;
}
$filename ="Users.xls";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment;filename='.$filename);
$sql = "SELECT * FROM member";
$dbcon = db_connect();
if($dbcon){
$result = $dbcon->query($sql);
echo "User ID\tFNAME\tLNAME\tTYPE\tCOURSE\tYEAR LEVEL\tCODE\n"; // prints header line with field names
if ($result->num_rows > 0) {// output data of each row
while($row = $result->fetch_assoc()) {
echo $row['stud_num']."\t".$row['firstname']."\t".$row['lastname']."\t". $row['type']."\t".$row['course']."\t".$row['year_level']."\t".$row['code']."\n";// prints each record with five fields in a row
}
}
}
答案 0 :(得分:0)
Excel将输入一个全数字字段作为int并放下左边的0。要欺骗Excels导入器将其视为文本字段,您需要将其格式化为简单的论坛。在回声线中,更改
."\t".$row['code']."\n"
到
."\t\"=\"\"".$row['code']."\"\"\"\n"
直接剪切n贴,然后看看是否能为您提供所需的效果。