我成功地将数据从API下载到excel,但在chrome中没有下载确认。这只是把它保存在供应商问题中。我想让显示在下载铬
public function download()
{
$host ="https://jsonplaceholder.typicode.com/posts";
$process = curl_init($host);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
curl_close($process);
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Id');
$sheet->setCellValue('B1', 'Name');
$sheet->setCellValue('C1', 'Skills');
$sheet->setCellValue('D1', 'Address');
$rows = 2;
$results=json_decode($return);
foreach ($results as $val){
$sheet->setCellValue('A' . $rows, $val->id);
$sheet->setCellValue('B' . $rows, $val->userId);
$sheet->setCellValue('C' . $rows, $val->title);
$sheet->setCellValue('D' . $rows, $val->body);
$rows++;
}
$writer=new Xlsx($spreadsheet);
$writer->save('json.xlsx');
}
这不是由PHP代码完成的,您需要的是浏览器功能选中此链接使Chrome显示下载如何使Chrome下载显示