LoginSignup
2
3

More than 5 years have passed since last update.

RE:PHPExcelで出力したExcelの数式で再計算が実行できなくなった時の対処法

Last updated at Posted at 2018-04-13

元の投稿

しかし、$preCalculateFormulasをtrueにする対処は利用している関数によってはうまく動作しないようだ。

PhpSpreadsheetにおける対応

後継ライブラリのPhpSpreadsheetのissuesで以下を発見。

PHPExcelでの対応

/PHPExcel/Writer/Excel2007/Workbook.php の中の _writeCalcPr メソッドに一行追加し、以下のようにする。

Worksbook.php
    private function _writeCalcPr(PHPExcel_Shared_XMLWriter $objWriter = null, $recalcRequired = TRUE)
    {
        $objWriter->startElement('calcPr');

        //  Set the calcid to a higher value than Excel itself will use, otherwise Excel will always recalc
        //  If MS Excel does do a recalc, then users opening a file in MS Excel will be prompted to save on exit
        //     because the file has changed
        $objWriter->writeAttribute('calcId',            '999999');
        $objWriter->writeAttribute('calcMode',          'auto');
        //  fullCalcOnLoad isn't needed if we've recalculating for the save
        $objWriter->writeAttribute('calcCompleted',     ($recalcRequired) ? 1 : 0);
        $objWriter->writeAttribute('fullCalcOnLoad',    ($recalcRequired) ? 0 : 1);
        $objWriter->writeAttribute('forceFullCalc',     ($recalcRequired) ? 0 : 1);

        $objWriter->endElement();
    }

forceFullCalcという属性を追加しているところが該当箇所。

2
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3