这是phpword的示例代码,用于制作微软单词中的图表
<?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);
$chart = $section->addChart('column', $categories, $series1);
$chart->getStyle()->setWidth(Converter::inchToEmu(2.5))->setHeight(Converter::inchToEmu(2));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="test.docx"');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('php://output');
?>
当代码运行并保存到Microsoft Word时,数据由图表中未显示的变量声明。