【发布时间】:2020-11-04 01:33:12
【问题描述】:
我在下面有这段代码。我正在使用一个名为 b1b5.xls 的现有 excel,并且我正在输入一些值,如您所见。问题是我不知道如何关联一个按钮,当我单击它时,下载 b1b5.xls我的价值观..
<html>
<head>
</head>
<body>
<center>
<button onclick=" somefunction ?? ">Download!</button>
</center>
</body>
</html>
<?php
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\IOFactory;
$spreadsheet = IOFactory::load('b1b5.xls');
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('C7', 'Myvalue');
$sheet->setCellValue('C8', 'Myvalue2');
foreach (range('A', 'E') as $col) {
$sheet->getColumnDimension($col)->setAutoSize(true);
}
$filename = 'trapezas_ellados.xlsx';
// Redirect output to a client's web browser (Xlsx)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $filename . '"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');
?>
【问题讨论】:
-
我看过这个..没有
-
请详细说明。链接的问题究竟如何不能解决您的问题?您不希望该按钮导致文件被下载吗?因为这正是链接帖子中的代码所做的。
标签: javascript php html