不能读写xlsx档案PHP(can't read and write xlsx file p

2019-09-23 00:40发布

这是我的代码要附加该文件,并把它和值是在Excel文件我用它们来卓尔图表忽略了最低工作在所有数值变量,我的老板对我发火,帮助

让我解释更多。 我必须附加一个excel文件{其中包含4个数字,是一个测试结果,绘制图表}我已经做了测试,我有结果,我已经做了与附件发送,但我不能让该文件。

require_once '../Classes/PHPExcel.php';

$fileType = 'Excel2007';
$fileName = 'Result.xlsx';

// Read the file
$objReader = PHPExcel_IOFactory::createReader($fileType);
$objPHPExcel = $objReader->load($fileName);

// Change the file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $fileType);

$objSheet = $objPHPExcel->setActiveSheetIndex(0);

 objSheet->getCell('A2')->setValue($SumY );
  objSheet->getCell('B2')->setValue($SumR );
 objSheet->getCell('C2')->setValue($SumB );
  objSheet->getCell('D2')->setValue($SumG );



// Write the file
$objWriter->save('Result.xlsx'); 

Answer 1:

告诉PHPExcel要阅读和写作时,包括图表

假设图表在你的模板定义

require_once '../Classes/PHPExcel.php'; 

$fileType = 'Excel2007'; 
$fileName = 'Result.xlsx'; 

// Read the file (including chart template)
$objReader = PHPExcel_IOFactory::createReader($fileType); 
$objReader->setIncludeCharts(TRUE);
$objPHPExcel = $objReader->load($fileName); 

// Change the file 
$objSheet = $objPHPExcel->setActiveSheetIndex(0); 

$objSheet->getCell('A2')->setValue($SumY ); 
$objSheet->getCell('B2')->setValue($SumR ); 
$objSheet->getCell('C2')->setValue($SumB ); 
$objSheet->getCell('D2')->setValue($SumG ); 

// Write the file (including chart)
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $fileType); 
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('Result.xlsx');

如果图表没有在模板中定义,那么你需要在你的代码来创建它



文章来源: can't read and write xlsx file php
标签: php phpexcel