Created
August 6, 2016 14:05
-
-
Save madflow/d134d476f396a7f0753f2bee327008b9 to your computer and use it in GitHub Desktop.
Test BG colors in spout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__ . '/vendor/autoload.php'; | |
use Box\Spout\Writer\Style\StyleBuilder; | |
use Box\Spout\Writer\WriterFactory; | |
use Box\Spout\Common\Type; | |
use Box\Spout\Writer\Style\Color; | |
use Box\Spout\Reader\Wrapper\XMLReader; | |
$file = __DIR__ . '/bg.xlsx'; | |
$writer = WriterFactory::create(Type::XLSX); | |
$writer->openToFile($file); | |
$styleRed = (new StyleBuilder())->setBackgroundColor(Color::RED)->build(); | |
$styleGreen = (new StyleBuilder())->setBackgroundColor(Color::GREEN)->build(); | |
$styleFont = (new StyleBuilder())->setFontBold()->setFontSize(16)->build(); | |
$writer->addRow(['PLAIN']); | |
$writer->addRowWithStyle(['RED'], $styleRed); | |
$writer->addRowWithStyle(['GREEN'], $styleGreen); | |
$writer->addRow(['PLAIN']); | |
$writer->addRowWithStyle(['Font Styled'], $styleFont); | |
$writer->addRow(['PLAIN']); | |
$writer->addRow(['PLAIN']); | |
$writer->addRow(['PLAIN']); | |
$writer->addRow(['PLAIN']); | |
$writer->addRowWithStyle(['RED'], $styleRed); | |
$writer->addRowWithStyle(['GREEN'], $styleGreen); | |
$writer->addRowWithStyle(['RED'], $styleRed); | |
$writer->close(); | |
$xmlReader = new XMLReader(); | |
$path = $xmlReader->getRealPathURIForFileInZip($file, 'xl/styles.xml'); | |
$xml = DOMDocument::load($path); | |
$xml->preserveWhiteSpace = false; | |
$xml->formatOutput = true; | |
echo $xml->saveXML(); | |
$xmlReader->close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment