在phpoffice / phpword上添加图表

时间:2014-05-29 19:25:01

标签: php charts phpexcel phpword

我知道如何在PHPExcel上添加图表,但我还需要在docx文件中插入图表。是否可以使用phpoffice / phpword操作图表?

如果不可能,你知道这个工作的好图书馆吗?

5 个答案:

答案 0 :(得分:2)

实际上不可能在PHPWord文档中添加图表。但该功能在管道中(遵循此票证#123)。

但是你可以使用PHPExcel使用的一些库(实际上和将来)PHP Charting Libraries。实际上,PHPExcel just use JpGraph用于渲染一些图形。

答案 1 :(得分:1)

我不知道该库,但您可以在php中生成图像(例如使用PHP GD或imagemagick)并将生成的图像插入到docx文件中。

答案 2 :(得分:1)

是的,可以在phpoffice中添加图表。问题是文档还没有完成。

$chart = $section->addChart([$chartType], [$categories], [$series]);
$chart->getStyle() //For styling the chart

$chartTypes = 'pie' / 'doughnut' / 'bar' / 'column'/ 'line'/ 'area' / 'scatter' / 'radar';

//Example
$chart = $section->addChart('pie', array('A', 'B', 'C', 'D', 'E'), array(1, 3, 2, 5, 4));

答案 3 :(得分:1)

官方github的一些例子,希望这可以回答你的问题:)

PHPWord: https://github.com/PHPOffice/PHPWord/blob/master/samples/Sample_32_Chart.php

PHPExcel: https://github.com/PHPOffice/PHPExcel/tree/master/Examples

答案 4 :(得分:0)

你可以添加一个图表,但它有点受限,到目前为止已经创建了一些硬编码。

你可以做什么的例子: http://elumina.co/libs/PHPWord-master/samples/Sample_32_Chart.php

源代码:https://github.com/PHPOffice/PHPWord/blob/master/samples/Sample_32_Chart.php

需要对类进行一些修改才能使某些图形选项起作用,因为这些选项是硬编码的 https://github.com/PHPOffice/PHPWord/issues/957

无法编辑数据 https://github.com/PHPOffice/PHPWord/issues/956