【问题标题】:Add chart on phpoffice/phpword在 phpoffice/phpword 上添加图表
【发布时间】:2014-07-19 10:24:16
【问题描述】:

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

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

【问题讨论】:

    标签: php charts phpexcel phpword


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      实际上不可能在 PHPWord 文档中添加图表。但该功能正在开发中(请关注此票#123)。

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

      【讨论】:

      【解决方案3】:

      是的,可以在 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));
      

      【讨论】:

        【解决方案4】:

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

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

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

        【讨论】:

          【解决方案5】:

          您可以添加图表,但它有点受限,并且到目前为止创建的内容中有一些硬编码。

          您可以执行的操作示例: 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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2014-07-23
            • 2019-03-20
            • 1970-01-01
            • 2018-05-27
            • 2017-03-08
            • 2018-04-28
            • 1970-01-01
            • 2019-08-30
            相关资源
            最近更新 更多