1

I'm trying to select data from the database and write them to Excel file using PHPExcel_IOFactory. The script ends with the following error

PHP Fatal error: Uncaught exception 'PHPExcel_Calculation_Exception' with message 'Worksheet!AC2064 -> Formula Error: Unexpected operator '>'' in F:\SVN\Migration\CommonLib\CodePlex\PHPExcel\Cell.php:298

I tried to escape all cells one by one and also replace this character with blank space which resulted in unknown exception

$lineNumber  = 2;
while($row = odbc_fetch_array($result)){

  try{

    //print_r($row);
    $row = EscapeArray($row);
    $document->getActiveSheet()->fromArray($row, null, "A" . $lineNumber);
    $lineNumber++;

  } catch(Exception $e){

  echo "Caught exception: " . $e->getMessage() . "\n";

  }
}   
$writter = PHPExcel_IOFactory::createWriter($document, 'Excel2007');
$writter->save($tempFilePath);

function EscapeArray($array){

  $output = array();
  foreach($array as $key => $value){

    $output[$key] = addslashes($value);

  }
  return $output;
}

I would like to figure out why does the '<' character causing the error and how to fix it. Many thanks in advance.

Rahul
  • 18,271
  • 7
  • 41
  • 60
Jakub Sluka
  • 123
  • 1
  • 14
  • 2
    Please review this link: https://stackoverflow.com/questions/33439187/prevent-phpexcel-to-calculate-values-when-writing-to-file?rq=1 – Dhara Bhatti Jun 04 '19 at 12:39
  • 5
    Possible duplicate of [Prevent PHPExcel to calculate values when writing to file](https://stackoverflow.com/questions/33439187/prevent-phpexcel-to-calculate-values-when-writing-to-file) – Dave Jun 04 '19 at 12:45
  • Hello, found answer in related question. – Jakub Sluka Jun 04 '19 at 13:51

1 Answers1

-1

The formula error suggests that there is = before your < operator in a cell that you are trying to put into. So there is "=<" in the text from your DB. Whenever a cell starts with "=" , it treats it as a formula which will be an invalid formula in this case.

Rama Bhat
  • 1
  • 1
  • 1
    While this answer explains the reason of the error it does not help in solving the problem. As noted in comments to answer the solution was found in possible duplicate. Update your answer so that it includes possible solution. – Eduard Sukharev Jul 23 '21 at 12:16