Commit 6a7e2e71 authored by claudiu.cristea's avatar claudiu.cristea Committed by claudiu.cristea

Issue #2949550 by claudiu.cristea, PieterDC: Compute cells with formulas

parent ac7b5ae5
......@@ -103,7 +103,7 @@ class SpreadsheetIterator implements SpreadsheetIteratorInterface {
return $this->getAbsoluteRowIndex();
}
elseif ($cell = $this->getWorksheet()->getCell("$col_letter{$this->getAbsoluteRowIndex()}", FALSE)) {
return $cell->getValue();
return $cell->getCalculatedValue();
}
// Fall back to NULL.
return NULL;
......
......@@ -4,7 +4,7 @@ namespace Drupal\Tests\migrate_spreadsheet\Unit;
use Drupal\migrate_spreadsheet\SpreadsheetIterator;
use Drupal\Tests\UnitTestCase;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
/**
* Tests the spreadsheet iterator.
......@@ -152,8 +152,9 @@ class SpreadsheetIteratorTest extends UnitTestCase {
$this->assertSame([
'row' => 4,
'column b' => 'cell b1',
'column d' => 'cell d1',
'column e' => 'cell e1',
'column d' => 7.0,
// We test here a computed cell (E4 == 'D4+3.23').
'column e' => 10.23,
], $this->iterator->current());
// Move the cursor.
......@@ -236,7 +237,7 @@ class SpreadsheetIteratorTest extends UnitTestCase {
// Test case:
// - origin: B3;
// - header_row: 2.
$this->worksheet = (new Worksheet())
$this->worksheet = (new Spreadsheet())->getActiveSheet()
// The header row starts on the 2nd line.
->setCellValue('B2', 'column b')
->setCellValue('C2', 'column c')
......@@ -255,8 +256,8 @@ class SpreadsheetIteratorTest extends UnitTestCase {
// Data row with index 1.
->setCellValue('B4', 'cell b1')
->setCellValue('C4', 'cell c1')
->setCellValue('D4', 'cell d1')
->setCellValue('E4', 'cell e1')
->setCellValue('D4', 7.0)
->setCellValue('E4', '=D4+3.23')
->setCellValue('F4', 'cell f1')
->setCellValue('G4', 'cell g1')
// Data row with index 2.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment