/*它可以工作,但是當我打開Excel工作表時,它不工作,所以我刪除了else語句中的echo以及其他所有工作,所以它工作但沒有將數據打印到工作表*/PHP MySQL到PHPExcel沒有顯示數據
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' LIMIT ".$start.",10 ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
$activeSheet=$sheet->getActiveSheet();
while($row = $result->fetch_assoc()) {
$activeSheet->setCellValue('A1',' $row["firstname"]');
$activeSheet->setCellValue('B1','$row["lastname"]');
$activeSheet->setCellValue('C1','$row["phonenumber"]');
}
} else {
echo "0 results";
}
$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;
它顯示什麼嗎?你得到的錯誤是什麼,你期望什麼? –
它顯示excel錯誤,當我打開它的類型錯誤...但是當我刪除else語句它的工作原理而不打印數據到工作表 –
不要把你的密碼在公共論壇! –