PHPexcel公式IFERROR [英] PHPexcel formula IFERROR

查看:305
本文介绍了PHPexcel公式IFERROR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP excel 1.8.0.我到处搜索过,但不明白为什么会发生以下错误并且我的excel文件已损坏.

I'm using PHP excel 1.8.0. I have searched everywhere but I don't understand why following error occures and my excel file is corrupted.

Uncaught exception 'PHPExcel_Calculation_Exception' with message 'Worksheet!K2 -> Formula Error: An unexpected error occured'

我必须使用ISO 8859-2编码

I have to use ISO 8859-2 encoding

$formula = iconv('ISO-8859-2', 'UTF-8//IGNORE//TRANSLIT', '=IFERROR(IF(OR(C'.$row.'="string1";C'.$row.'="strin2");D'.$row.';" ");" ")');
$objPHPExcel->getActiveSheet()->setCellValue($where, $formula);

我尝试设置不带=的公式.之后,当我打开excel文件时,所有公式均正确设置,没有=标记.然后,如果我将其手动添加到公式中,它将起作用.但是使用您可以看到的代码,公式就坏了. 我也尝试在使用iconv之后添加=,但没有任何更改,文件仍然损坏.如果有人可以帮助我解决这个问题,我将感到非常高兴.

I tried setting formula without =. After that when I open my excel file all formulas are set properly without = mark. Then if I add it manually to the formula, it works. But with code like you can see it, formulas are broken. I have Also tried adding = after I used iconv, but nothing has changed file was still broken. I would be glad if someone could help me with this problem.

推荐答案

来自 将公式写入单元格

在Excel文件中,公式始终按照在Microsoft Office Excel英文版中出现的方式存储,并且PHPExcel在内部以这种格式处理所有公式.这意味着以下规则成立:

Inside the Excel file, formulas are always stored as they would appear in an English version of Microsoft Office Excel, and PHPExcel handles all formulae internally in this format. This means that the following rules hold:

  • 小数点分隔符为." (句号)
  • 函数参数分隔符为','(逗号)
  • 矩阵行分隔符为;" (分号)
  • 必须使用英文功能名称
    • Decimal separator is '.' (period)
    • Function argument separator is ',' (comma)
    • Matrix row separator is ';' (semicolon)
    • English function names must be used
    • 这与创建Excel文件所使用的Microsoft Office Excel语言版本无关.

      This is regardless of which language version of Microsoft Office Excel may have been used to create the Excel file.

      您使用分号(;)作为函数参数分隔符

      You're using a semi-colon (;) as a function argument separator

      这篇关于PHPexcel公式IFERROR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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