Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

@no22@github

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

元の投稿

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

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
3
Help us understand the problem. What are the problem?