I am facing problem in export xlsx format using spout library. I don't know where is the issue in my code. I don't know much about spout library. I have tried many times but the same error occurs again and again when I tried opening the exported excel file in live server (CentOs) . Please guide me where is the issue.
#!/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();
?>
But the same code is perfectly creating the excel file in my xampp local environment (My PC)
use
$writer->openToBrowser('test.xlsx');