Skip to content

Instantly share code, notes, and snippets.

@theredstapler
Created November 28, 2016 13:12
Show Gist options
  • Save theredstapler/b9f75d5b9aa32ae73a1399796d7625a1 to your computer and use it in GitHub Desktop.
Save theredstapler/b9f75d5b9aa32ae73a1399796d7625a1 to your computer and use it in GitHub Desktop.
<?php
require_once 'vendor/autoload.php';
use PhpOffice\PhpWord\Shared\Converter;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$categories = array('A', 'B', 'C', 'D', 'E');
$series1 = array(5, 3, 4, 2, 7);
$series2 = array(15, 2, 9, 5, 9);
$chart = $section->addChart('line', $categories, $series1);
$chart->getStyle()->setWidth(Converter::inchToEmu(2.5))->setHeight(Converter::inchToEmu(2));
$chart->addSeries($categories,$series2);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="test.docx"');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('php://output');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment