无法读取和写入XLSX文件的PHP [英] can't read and write xlsx file php

查看:161
本文介绍了无法读取和写入XLSX文件的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,我想附加此文件并将其发送,并且值是数值文件,我在excel文件中使用它们绘制图表 它根本不起作用, 我的老板生我的气,帮助

this is my code i want to attach this file and send it and the values are numerical variables that in excel file i use them to drow a chart it dosen't work at all , my boss is mad at me , Help

让我解释更多.我必须附加一个excel文件{其中包含4个数字,它们是测试结果并绘制图表}我已经完成了测试,已经获得了结果,已经完成了带有附件的发送,但是我无法制作该文件.

let me explain more . i have to attach an excel file {which contains 4 numbers that are a test result and draw a chart } I've done the test i have the result, i have done sending with attachment but i can't make the file .

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

推荐答案

告诉PHPExcel您想要在读写时包括图表

Tell PHPExcel that you want to include charts when reading and writing

假设图表是在模板中定义的

Assuming that the chart is defined in your template

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

如果未在模板中定义图表,则需要在代码中创建

If the chart isn't defined in your template, then you need to create it in your code

这篇关于无法读取和写入XLSX文件的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆