简体   繁体   English

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

[英]Generate Excel file with chart with data from mysql database using PHP

I want to generate an excel file with chart based on the data from MySQL database using PHP with PHPExcel Library. 我想使用PHP和PHPExcel Library生成带有图表的excel文件,该图表基于来自MySQL数据库的数据。 I searched a lot..but could not find a solution Values are exported to the excel file.but the chart doesnt show up. 我搜索了很多..但找不到解决方案值被导出到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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM