【问题标题】:File Format or File Extension is not valid using Spout PHP In Linux CentOS在 Linux CentOS 中使用 Spout PHP 文件格式或文件扩展名无效
【发布时间】:2019-12-19 06:09:36
【问题描述】:

我在使用 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 文件

【问题讨论】:

  • 您没有指定错误是什么。没有这个很难提供帮助。

标签: php spout phpxlsxwriter


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 2015-12-14
    • 2022-06-30
    • 1970-01-01
    • 2020-07-11
    • 2012-12-24
    相关资源
    最近更新 更多