Skip to content

Commit dd12f02

Browse files
committed
Better test of setFullCalcOnLoad
1 parent f2c6554 commit dd12f02

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

tests/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
_*
22
~*
3-
*copy.xls*

tests/test.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
use alexandrainst\XlsxFastEditor\XlsxFastEditor;
1111
use alexandrainst\XlsxFastEditor\XlsxFastEditorException;
1212

13-
copy(__DIR__ . '/test.xlsx', __DIR__ . '/copy.xlsx');
13+
copy(__DIR__ . '/test.xlsx', __DIR__ . '/_copy.xlsx');
1414

1515
try {
16-
$xlsxFastEditor = new XlsxFastEditor(__DIR__ . '/copy.xlsx');
16+
$xlsxFastEditor = new XlsxFastEditor(__DIR__ . '/_copy.xlsx');
1717

1818
$sheet1 = $xlsxFastEditor->getWorksheetNumber('Sheet1');
1919
assert($sheet1 === 1);
@@ -39,7 +39,7 @@
3939
assert($xlsxFastEditor->getFirstRow($sheet1)?->number() === 1);
4040
assert($xlsxFastEditor->getRow($sheet1, 1)?->getFirstCell()?->name() === 'A1');
4141
assert($xlsxFastEditor->getRow($sheet1, 2)?->number() === 2);
42-
assert($xlsxFastEditor->getRow($sheet1, 3)?->getLastCell()?->name() === 'D3');
42+
assert($xlsxFastEditor->getRow($sheet1, 3)?->getLastCell()?->name() === 'E3');
4343
assert($xlsxFastEditor->getRow($sheet1, 4)?->getCell('D4')?->name() === 'D4');
4444
assert($xlsxFastEditor->getLastRow($sheet1)?->number() === 4);
4545

@@ -52,7 +52,7 @@
5252
$nb++;
5353
}
5454
}
55-
assert($nb === 16);
55+
assert($nb === 20);
5656

5757
// Writing existing cells
5858
$xlsxFastEditor->writeFormula($sheet1, 'c2', '=2*3');
@@ -81,10 +81,12 @@
8181
// Regex
8282
assert($xlsxFastEditor->textReplace('/Hello/i', 'World') > 0);
8383

84+
$xlsxFastEditor->setFullCalcOnLoad($sheet1, true);
85+
8486
$xlsxFastEditor->save();
8587

8688
// Verify all the changes
87-
$xlsxFastEditor = new XlsxFastEditor(__DIR__ . '/copy.xlsx');
89+
$xlsxFastEditor = new XlsxFastEditor(__DIR__ . '/_copy.xlsx');
8890

8991
assert($xlsxFastEditor->readFormula($sheet1, 'c2') === '=2*3');
9092
assert($xlsxFastEditor->readString($sheet1, 'B4') === 'α');
@@ -96,8 +98,6 @@
9698
assert($xlsxFastEditor->readInt($sheet2, 'C3') === -7);
9799
assert($xlsxFastEditor->readFloat($sheet2, 'D3') === 273.15);
98100

99-
$xlsxFastEditor->setFullCalcOnLoad($sheet2, true);
100-
101101
assert($xlsxFastEditor->readFormula($sheet2, 'I2') === '=7*3');
102102
assert($xlsxFastEditor->readString($sheet2, 'F2') === 'γ');
103103
assert($xlsxFastEditor->readInt($sheet2, 'G3') === -7);
@@ -112,7 +112,8 @@
112112

113113
$xlsxFastEditor->close();
114114

115-
// Verify by hand that the resulting file opens without warning in Microsoft Excel
115+
// Verify by hand that the resulting file opens without warning in Microsoft Excel.
116+
// Verify by hand that the cell Sheet1!E4 has its formula recalculated (to -999) when opening in Excel.
116117
// unlink(__DIR__ . '/copy.xlsx');
117118
} catch (XlsxFastEditorException $xlsxe) {
118119
die($xlsxe);

tests/test.xlsx

225 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)