您是否考虑将其导出为 CSV?
Excel 可以导入 CSV 并制作数据表格(ofc 没有边框和其他装饰)。
我制作了一个用于构建电子表格的 PHP 类,也许它可以帮助你:
<?php
class Spreadsheet {
private $grid = array();
public function setCell(/*int*/ $x, /*int*/ $y, /*mixed*/ $value) {
for($yy=0; $yy<=$y; $yy++) {
if(!isset($this->grid[$yy])) {
$this->grid[$yy] = array();
}
}
for($xx=0; $xx<=$x; $xx++) {
if(!isset($this->grid[$y][$xx])) {
$this->grid[$y][$xx] = null;
}
}
$this->grid[$y][$x] = $value;
}
// final command executed, including "exit".
public function sendAsCsv(/*string*/ $filename) {
header('Content-type: text/csv; charset=utf-8');
header('Content-Language: en');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header("Pragma: no-cache");
header("Expires: 0");
ob_end_clean();
$outputBuffer = fopen("php://output", 'w');
$this->appendToFile($outputBuffer);
fclose($outputBuffer);
exit;
}
public function appendToFile(/*resource*/ $fileHandle) {
foreach($this->grid as $val) {
fputcsv($fileHandle, $val);
}
}
}