文件格式或文件扩展名在 Linux CentOS 中使用 Spout PHP 无效



我在使用喷口库导出 xlsx 格式时遇到问题。我不知道我的代码中的问题在哪里。我对喷口图书馆了解不多。我已经尝试了很多次,但是当我尝试在实时服务器(CentOs(中打开导出的excel文件时,一次又一次地出现相同的错误。请指导我问题出在哪里。

#!/usr/bin/php -q
<?PHP
require_once 'spout-3.1.0/src/Spout/Autoloader/autoload.php';

use BoxSpoutWriterCommonCreatorWriterEntityFactory;
use BoxSpoutWriterCommonCreatorStyleStyleBuilder;
use BoxSpoutCommonEntityStyleCellAlignment;
use BoxSpoutCommonEntityStyleColor;

$columnHeaders = array("Category",
"Brand",
"Model",
"Sub Category",
"Description",
"Price",
"Online Retailer",
"Date");

$writer = WriterEntityFactory::createXLSXWriter();
$writer->openToFile('test.xlsx');
/** Create a style with the StyleBuilder */
$style = (new StyleBuilder())
->setFontBold()
->setFontSize(10)
->setFontColor(Color::BLUE)
->setShouldWrapText()
->setCellAlignment(CellAlignment::LEFT)
->setBackgroundColor(Color::YELLOW)
->build();
/** Create a row with cells and apply the style to all cells */
$row = WriterEntityFactory::createRowFromArray($columnHeaders, $style);
/** Add the row to the writer */
$writer->addRow($row);
$writer->close();


?>

但是相同的代码在我的 xampp 本地环境(我的 PC(中完美地创建了 excel 文件

使用$writer->openToBrowser('test.xlsx');

最新更新