Skip to content

Commit 27fadb3

Browse files
committed
Add function getFullCalcOnLoad
1 parent e94c280 commit 27fadb3

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ try {
5050
$nbWorksheets = $xlsxFastEditor->getWorksheetCount();
5151
$worksheetName = $xlsxFastEditor->getWorksheetName(1);
5252
$worksheetId1 = $xlsxFastEditor->getWorksheetNumber('Sheet1');
53+
5354
// If you want to force Excel to recalculate formulas on next load:
5455
$xlsxFastEditor->setFullCalcOnLoad($worksheetId1, true);
56+
$fullCalcOnLoad = $xlsxFastEditor->getFullCalcOnLoad($worksheetId1);
5557

5658
// Direct read/write access
5759
$fx = $xlsxFastEditor->readFormula($worksheetId1, 'A1');

src/XlsxFastEditor.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,29 @@ public function setFullCalcOnLoad(int $sheetNumber, bool $value): void
358358
}
359359
}
360360

361+
/**
362+
* Get the *Full calculation on load* policy for the specified worksheet.
363+
* @param int $sheetNumber Worksheet number (base 1)
364+
* @throws XlsxFastEditorFileFormatException
365+
* @throws XlsxFastEditorXmlException
366+
*/
367+
public function getFullCalcOnLoad(int $sheetNumber): ?bool
368+
{
369+
$dom = $this->getDomFromPath(self::getWorksheetPath($sheetNumber));
370+
$sheetCalcPrs = $dom->getElementsByTagName('sheetCalcPr');
371+
if ($sheetCalcPrs->length > 0) {
372+
$sheetCalcPr = $sheetCalcPrs[0];
373+
if ($sheetCalcPr instanceof \DOMElement) {
374+
$fullCalcOnLoad = $sheetCalcPr->getAttribute('fullCalcOnLoad');
375+
if ($fullCalcOnLoad !== '') {
376+
$fullCalcOnLoad = strtolower(trim($fullCalcOnLoad));
377+
return in_array($fullCalcOnLoad, ['true', '1'], true);
378+
}
379+
}
380+
}
381+
return null;
382+
}
383+
361384
/**
362385
* Get the row of the given number in the given worksheet.
363386
* @param int $sheetNumber Worksheet number (base 1)

tests/test.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@
134134
// Regex
135135
assert($xlsxFastEditor->textReplace('/Hello/i', 'World') > 0);
136136

137+
assert($xlsxFastEditor->getFullCalcOnLoad($sheet1) == null);
137138
$xlsxFastEditor->setFullCalcOnLoad($sheet1, true);
139+
assert($xlsxFastEditor->getFullCalcOnLoad($sheet1) === true);
138140

139141
$xlsxFastEditor->save();
140142

0 commit comments

Comments
 (0)