我正在尝试创建一个简单的设置来加载模板,插入一些数据并保存为新文件.然而,我需要一些条件格式化的一些单元格,当我得到新创建的文件条件格式化缺失.它不会被某些其他格式化覆盖,条件格式菜单中缺少规则.我使用
PHP 5.2,PHPExcel 1.7.8和Excel 2010.
<?PHP class template { static $objPHPExcel; function __construct() { define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />'); require_once '../Classes/PHPExcel/IOFactory.PHP'; if (!file_exists("template.xlsx")) { exit("template missing." . EOL); } echo date('H:i:s')," Load from Excel2007 file",EOL; $objReader = PHPExcel_IOFactory::createReader('Excel2007'); $objReader->setReadDataOnly(false); self::$objPHPExcel = $objReader->load("template.xlsx"); } function insertdata($dataArray){ /* unused */ } function save($name){ define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />'); require_once '../Classes/PHPExcel/IOFactory.PHP'; echo date('H:i:s')," Write to Excel2007 format",EOL; $objWriter = PHPExcel_IOFactory::createWriter(self::$objPHPExcel,'Excel2007'); $objWriter->save($name); echo date('H:i:s')," File written to: ".$name,EOL; } $temp=new template(); $temp->save("savethis.xlsx");
我试图保留一个分级2颜色比例(基于单元格的格式,最小值是Number = 1,Maximum is type Number = 10).所涉及的单元格具有引用另一个工作表的所有公式(所有数据都已正确保存).
我发现,从原始文件中获取“自动过滤器”,“数据验证”和“条件格式”的XLS / XLSX文件,我发现无法阅读,修改和保存,我发现的最终解决方案是使模板使用PHPExcel库.
原文链接:https://www.f2er.com/php/132180.html可悲的是,正如另一个答案(https://stackoverflow.com/a/13172890/218418)所述:
PHPExcel is not a library for “editing” workbook files: you’re not using PHPExcel to change a file,you’re changing a PHPExcel object that can be loaded from a file,and can subsequently be written to a file.