本文介绍了图形显示使用PHPExcel读写Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 http://phpexcel.codeplex.com 来读写Excel文件.当我阅读并写入新数据图表消失时,我在excel文件中有图表.这是第7个示例07reader.php,但将包含文件从"05featuredemon.php"更改为"33chartcreate-bar.php"因为我需要图
Hi I am using http://phpexcel.codeplex.com for read and write of excel file. I have graph in excel file when i read it and write new data graph disapear. This the example no 7 i.e07reader.php but change include file from "05featuredemon.php" to "33chartcreate-bar.php"because i need graph
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
/** Include PHPExcel_IOFactory */
require_once '../Classes/PHPExcel/IOFactory.php';
if (!file_exists("33chartcreate-bar.xlsx")) {
exit("Please run 33chartcreate-bar.php first." . EOL);
}
echo date('H:i:s') , " Load from Excel2007 file" , EOL;
$objPHPExcel = PHPExcel_IOFactory::load("05featuredemo.xlsx");
echo date('H:i:s') , " Write to Excel2007 format" , EOL;
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
// Echo memory peak usage
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
// Echo done
echo date('H:i:s') , " Done writing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;
请帮助我
推荐答案
您需要明确告知PHPExcel读写图表
You need to explicitly tell PHPExcel to read and to write charts
$objReader->setIncludeCharts(TRUE);
和
$objWriter->setIncludeCharts(TRUE);
如示例所示
编辑
显式喂汤类型示例
// Create a reader for an Excel2007 file
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
// Tell the reader to include charts when it loads a file
$objReader->setIncludeCharts(TRUE);
// Load the file
$objPHPExcel = $objReader->load("33chartcreate-bar.xlsx");
// Do some stuff to the file
// Create a writer for an Excel2007 file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
// Tell the writer to include any charts when it saves a file
$objWriter->setIncludeCharts(TRUE);
// Save the file
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
这篇关于图形显示使用PHPExcel读写Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!