Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

元の投稿

https://qiita.com/makasn/items/98b4995266661ec1659f

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

PhpSpreadsheetにおける対応

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

https://github.com/PHPOffice/PhpSpreadsheet/issues/456

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という属性を追加しているところが該当箇所。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした