3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

3
3
3

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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?