当我尝试导出时,除NID字段外,所有其他字段都可以。这个数字的长度是17+,所以我怎么显示这个字段(nid)中的所有数字?我有
$filename = "hello.csv";
$query = "SELECT * FROM test_users";
$result_users = $this->conn->prepare($query);
$result_users->execute();
// Create array
$list = array ();
// Append results to array
array_push($list, array("## START OF May TABLE ##"));
while ($row = $result_users->fetch(PDO::FETCH_ASSOC)) {
array_push($list, array_values($row));
}
array_push($list, array("## END OF May TABLE ##"));
// Output array into CSV file
$fp = fopen('php://output', 'w');
fputcsv($fp, ['Serial NO','English Name','Bangla Name','address','bn_address','user_no','nid','previous_cm','meter_no','type_of_user']);
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header("Content-Transfer-Encoding: binary");
foreach ($list as $ferow) {
fputcsv($fp, $ferow);
}
我遇到了相同的问题,并且已经按照以下方法解决了。
我在每个数组值中插入了单引号。这样,当您使用Excel打开CSV文件时,科学记号E + 15
将不再显示。
// this function add a single quote for each member of array
function insertquote($value) {
return "'$value'";
}
# here i send each value of array
# to a insertquote function, and returns an array with new values,
# with the single quote.
foreach ($list as $ferow) {
fputcsv($fp, array_map(insertquote, $ferrow), ';');
}