使用PHP从mysql数据库生成带图表的Excel文件

使用PHP从mysql数据库生成带图表的Excel文件,php,excel,phpexcel,excel-charts,Php,Excel,Phpexcel,Excel Charts,我想使用PHP和PHPExcel库,基于MySQL数据库中的数据生成一个带有图表的excel文件。 我找了很多,但找不到解决办法 值将导出到excel文件。但图表不会显示 require_once 'includes/PHPExcel-1.8/Classes/PHPExcel.php'; //Data Series Labels $dsl=array( new PHPExcel_Chart_DataSeriesValues('String', 'Data!$C$

我想使用PHP和PHPExcel库,基于MySQL数据库中的数据生成一个带有图表的excel文件。 我找了很多,但找不到解决办法 值将导出到excel文件。但图表不会显示

require_once 'includes/PHPExcel-1.8/Classes/PHPExcel.php';

//Data Series Labels
$dsl=array(
                new PHPExcel_Chart_DataSeriesValues('String', 'Data!$C$1', NULL, 1),
                new PHPExcel_Chart_DataSeriesValues('String', 'Data!$D$1', NULL, 1),

            );
//X Axis Value Label
$xal=array(
                new PHPExcel_Chart_DataSeriesValues('String', 'Data!$C$2:$C$91', NULL, 90),
            );
//Data Series Values
$dsv=array(
                new PHPExcel_Chart_DataSeriesValues('Number', 'Data!$C$2:$C$91', NULL, 90),
                new PHPExcel_Chart_DataSeriesValues('Number', 'Data!$D$2:$D$91', NULL, 90),
            );
//set up Data Series
$ds=new PHPExcel_Chart_DataSeries(
                    PHPExcel_Chart_DataSeries::TYPE_LINECHART,
                    PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
                    range(0, count($dsv)-1),
                    $dsl,
                    $xal,
                    $dsv
                    );
//create the Plot Area and Legend
$pa=new PHPExcel_Chart_PlotArea(NULL, array($ds));
$legend=new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
//create chart
$chart= new PHPExcel_Chart(
                    'chart1',
                    $title,
                    $legend,
                    $pa,
                    true,
                    0,
                    NULL, 
                    NULL
                    );

$chart->setTopLeftPosition('K1');
$chart->setBottomRightPosition('M5');
$ews->addChart($chart);
//title of chart
$title=new PHPExcel_Chart_Title('Any literal string');

$writer = PHPExcel_IOFactory::createWriter($ea, 'Excel5');

$writer->setIncludeCharts(true);

您可以从中找到解决方案。

您可以从中找到解决方案。

不鼓励使用链接。我认为affaz将从此链接中获得正确的解决方案。因为将该链接的全部代码放在这里是不可行的。请查看我编辑的帖子。我可以使用您提供的链接将数据导出到excel,但图表没有显示。我已附加了上面的代码。感谢链接仅限于答案。我想affaz将从该链接获得正确的解决方案。因为将该链接的全部代码放在这里是不可行的。请查看我编辑的帖子。我可以使用您提供的链接将数据导出到excel,但图表没有显示。我已附上上面的代码。谢谢