-3

这是我的代码,我想附上这个文件并发送它,这些值是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'); 
4

1 回答 1

0

告诉 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');

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

于 2012-09-26T09:09:59.927 回答