Google chart + phpexcel ?

Apr 25, 2009 at 2:10 AM
someone have a tutorial to include google chart into spreadsheet
thx :)
Coordinator
Apr 25, 2009 at 9:43 AM
It should be possible to download a generated chart using file_get_contents(), for example. This can then be included as an image on the spreadsheet.
Apr 26, 2009 at 1:59 AM
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . './Classes/');
require_once 'PHPExcel.php';
include 'PHPExcel/IOFactory.php';

//basic function to download chart
function charting($title,$val1,$val2,$color){
$url = file_get_contents("http://chart.apis.google.com/chart?chs=340x200&cht=p3&chl=$title&chd=t:$val1,$val2&chtt=Example+Chart&chco=$color");
$img = fopen("chart.png", 'w');
fwrite($img, $url);
fclose($img);
}

//create excel file
$objPHPExcel = new PHPExcel();
charting("PHP|Java",50,50,"00ff00,0000ff");
$objPHPExcel->setActiveSheetIndex(0);
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Example Chart');
$objDrawing->setDescription('Example Chart');
$objDrawing->setPath('chart.png');
$objDrawing->setCoordinates('H6');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

//Write xlsx
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));

?>

wORK ok. thx for the info :)