问题在于,电子琴以科学记数法显示:
include_once 'PHPExcel.php';
$sheet = new PHPExcel();
$servername =
$username =
$password =
$dbname =
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT firstname, lastname, phonenumber FROM people where answer='true'";
$result = $conn->query($sql);
$x=0;
if ($result->num_rows > 0) {
// output data of each row
$activeSheet=$sheet->getActiveSheet();
while($row = $result->fetch_assoc()) {
$activeSheet->setCellValue('A'. $x,$row["firstname"]);
$activeSheet->setCellValue('B'. $x,$row["lastname"]);
$activeSheet->setCellValue('C'. $x,$row["phonenumber"]);
$activeSheet->setCellValue('D'. $x,"True");
$x++;
}
}
$conn->close();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="report.xlsx"');
header('Cache-Control: max-age=0');
$objWriter=PHPExcel_IOFactory::createWriter($sheet,'Excel2007');
$objWriter->save('php://output');
exit;
答案 0 :(得分:1)
您应该将电话号码存储在文本字段中;不是数字字段;这会导致各种各样的问题。你看到其中一个;数字太大而无法显示为数字,并且可能已在您的mysql数据库中损坏。这意味着您将永远无法检索电话号码。
再次;更新您的数据库并使 phonenumber 成为VARCHAR
而不是INT