Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Phpexcel 公式错误_Phpexcel_Formulas - Fatal编程技术网

Phpexcel 公式错误

Phpexcel 公式错误,phpexcel,formulas,Phpexcel,Formulas,我想将公式设置为单元格,但我在路上遇到了错误。这里有一个代码: $objReader = PHPExcel_IOFactory::load($path.$filename); $objReader->setActiveSheetIndex(0); $objReader->getActiveSheet() ->setCellValue('C2','=VLOOKUP(A9;A3:B32;2)'); $ob

我想将公式设置为单元格,但我在路上遇到了错误。这里有一个代码:

  $objReader = PHPExcel_IOFactory::load($path.$filename);
    $objReader->setActiveSheetIndex(0);
    $objReader->getActiveSheet()
                        ->setCellValue('C2','=VLOOKUP(A9;A3:B32;2)');

    $objWriter = PHPExcel_IOFactory::createWriter($objReader, 'Excel5');
    $objWriter->save($path.'plik.xls'); 

公式是从普通表复制的,所以她是赖特。我收到这个消息:
feuil1!C2->公式错误:发生意外错误

,除非您启用了使用
的区域设置
作为参数分隔符,则必须使用英语(en_us)参数分隔符(即逗号

从手册中引用:

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
This is regardless of which language version of Microsoft Office Excel may have been used to create the Excel file.
因此:

编辑

如果要使用法语公式,则需要启用区域设置,并在法语和英语之间转换公式:

$objReader = PHPExcel_IOFactory::load($path.$filename);
$objReader->setActiveSheetIndex(0);

$locale = 'fr';
$validLocale = PHPExcel_Settings::setLocale($locale);
if (!$validLocale) {
echo 'Unable to set locale to '.$locale." - reverting to en_us<br />\n";

    $internalFormula = '=VLOOKUP(A9,A3:B32,2)';
} else {
    $formula = '=RECHERCHEV(A9;A3:B32;2)';
    $internalFormula = 
        PHPExcel_Calculation::getInstance()->translateFormulaToEnglish($formula);
}
$objReader->getActiveSheet()
    ->setCellValue('C2', $internalFormula);

$objWriter = PHPExcel_IOFactory::createWriter($objReader, 'Excel5');
$objWriter->save($path.'plik.xls'); 
$objReader=PHPExcel\u IOFactory::load($path.$filename);
$objReader->setActiveSheetIndex(0);
$locale='fr';
$validLocale=PHPExcel\u设置::setLocale($locale);
如果(!$validLocale){
echo“无法将区域设置设置为“.$locale”-正在还原为en_us
\n”; $internalFormula='=VLOOKUP(A9,A3:B32,2)'; }否则{ $formula='=RECHERCHEV(A9;A3:B32;2)'; $internalFormula= PHPExcel_计算::getInstance()->translateFormulaToEnglish($formula); } $objReader->getActiveSheet() ->setCellValue('C2',$internalFormula); $objWriter=PHPExcel_IOFactory::createWriter($objReader,'Excel5'); $objWriter->save($path.plik.xls');
$objReader = PHPExcel_IOFactory::load($path.$filename);
$objReader->setActiveSheetIndex(0);

$locale = 'fr';
$validLocale = PHPExcel_Settings::setLocale($locale);
if (!$validLocale) {
echo 'Unable to set locale to '.$locale." - reverting to en_us<br />\n";

    $internalFormula = '=VLOOKUP(A9,A3:B32,2)';
} else {
    $formula = '=RECHERCHEV(A9;A3:B32;2)';
    $internalFormula = 
        PHPExcel_Calculation::getInstance()->translateFormulaToEnglish($formula);
}
$objReader->getActiveSheet()
    ->setCellValue('C2', $internalFormula);

$objWriter = PHPExcel_IOFactory::createWriter($objReader, 'Excel5');
$objWriter->save($path.'plik.xls');