问题描述
我正在用phpexcel生成一个Excel工作表,当使用条件格式(条件是搜索文本或部分内容)时,在尝试打开生成的工作表时收到验证错误.与数字完美搭配,与文字完美搭配.
I am generating an excel sheet with phpexcel, when using conditional formatting with the condition being (search for a text or part of it), i get a validation error when trying to open the generated sheet. Works perfectly with numbers, Less so WITH TEXTS.
这是我的代码:
//conditional formatting
$objConditional1 = new PHPExcel_Style_Conditional();
$objConditional1->setConditionType(PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT)
->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_CONTAINSTEXT)
->addCondition('X');
$objConditional1->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_YELLOW);
$objConditional3 = new PHPExcel_Style_Conditional();
$objConditional3->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_GREATERTHANOREQUAL)
->addCondition('0');
$objConditional3->getStyle()->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_GREEN);
$conditionalStyles = $objPHPExcel->getActiveSheet()->getStyle('B2')->getConditionalStyles();
array_push($conditionalStyles, $objConditional3);
array_push($conditionalStyles, $objConditional1);
$objPHPExcel->getActiveSheet()->getStyle('B2')->setConditionalStyles($conditionalStyles);
有人知道如何解决这个问题吗?我做错什么了吗?谢谢.
Does any one know how to work around this ? am i doing anything wrong ?Thanks.
推荐答案
据我所知,尽管我没有针对您的情况进行具体测试,但是当您尝试基于CONTAINSTEXT应用条件格式时,你不应该打电话
As far as i know, though i have not tested with your case specifically, when you try to apply conditional formatting based on CONTAINSTEXT,you shouldn't call
'->addCondition('X')'
(代码中的第5行),而是调用方法:
(line 5 in your code), but instead call the method:
->setText('X')
在您的PHPExcel_Style_Conditional对象上.这就是我在PHPExcel工作表中指定要比较的文本的方式.
On your PHPExcel_Style_Conditional objects. This is how I specify the text to compare to in my PHPExcel sheets.
这篇关于条件格式后,Excel工作表已损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!