0

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

#!/usr/bin/php -q
<?PHP
    require_once 'spout-3.1.0/src/Spout/Autoloader/autoload.php';
    
    use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
    use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
    use Box\Spout\Common\Entity\Style\CellAlignment;
    use Box\Spout\Common\Entity\Style\Color;
    
    $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 本地环境(我的电脑)中完美地创建了 excel 文件

4

1 回答 1

-1

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

于 2020-10-28T06:13:06.330 回答