Conditional formatting error if document opened in Microsoft Office

Asked

Viewed 510 times

3

When applying conditional formatting to a spreadsheet xlsx generated with the Phpexcel, the same works smoothly when the document is opened in Libreoffice:

$objConditional = new PHPExcel_Style_Conditional();

$objConditional->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
               ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_EQUAL)
               ->addCondition('='.$index_min_cell);

$objConditional->getStyle()->getFont()->getColor()->setRGB('FFFFFF');
$objConditional->getStyle()->getFont()->setSize(8);
$objConditional->getStyle()->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getEndColor()->setRGB('5c8526');
$objConditional->getStyle()->getNumberFormat()->setFormatCode("[$$-409]#,##0.00;-[$$-409]#,##0.00");


$explode=explode(',', $condition_min_med);

for ($m=0; $m<count($explode); $m++) {
    $sheet_00->getStyle($explode[$m])->setConditionalStyles(array($objConditional));
} 

But when the document is opened using Microsoft Office, it shows the following error information-rich:

Feature Removed: Conditional formatting of part /Xl/worksheets/sheet1.xml

With Link to an XML with the following information:

<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  <logFileName>error033680_04.xml</logFileName>
  <summary>Foram detectados erros no ficheiro 'C:\Users\JohnDoe\AppData\Local\Temp\super_bubu.xlsx'</summary>
  <removedFeatures summary="Segue-se uma lista de funcionalidades removidas:">
    <removedFeature>Funcionalidade Removida: Formatação condicional da parte /xl/worksheets/sheet1.xml</removedFeature>
  </removedFeatures>
</recoveryLog>

Question

Since the error information only indicates that the functionality has been removed, and taking into account that the document when opened in Libreoffice works smoothly making use of the conditional formatting applied:

What is the reason for any Microsoft Office Excel 2010 ignores the conditional formatting that is being applied ?


Note:
This is part of a very large file that tries to generate the entire spreadsheet, but this particular part, if removed, causes Excel to no longer present the error... Of course the conditional formatting is not there!

  • In which excel version was the test done? the spreadsheet is in the format of excel5 or 2007?

  • @lost The file being generated is a XLSX and is being tested in Excel 2010.

1 answer

3


Apparently, for Microsoft Office Excel, when defining the type of operator, we cannot indicate the same operator in the condition:

Where is:

$objConditional->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
               ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_EQUAL)
               ->addCondition('='.$index_min_cell);

Change to:

$objConditional->setConditionType(PHPExcel_Style_Conditional::CONDITION_CELLIS)
               ->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_EQUAL)
               ->addCondition($index_min_cell);

That is, as we have already defined through the setOperatorType() the intended operator:

->setOperatorType(PHPExcel_Style_Conditional::OPERATOR_EQUAL)

We should not apply the same in condition through the addCondition():

->addCondition('='.$index_min_cell);

only the desired condition:

->addCondition($index_min_cell);

From what I understand, the Libreoffice to find the type of operator OPERATOR_EQUAL and the condition preceded by the operator =, leave only one = in the construction of the condition.

Microsoft Office Excel, I suspect it tries to do the type ==condição, and by not interpreting this, it bursts all and ignores the conditional formatting altogether.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.